Irina
Irina

Reputation: 1598

Getting "cant_update_message" error when updating messages posted by Bot

I am trying to update messages posted by my bot. However, I am getting a 'cant_update_message' error when trying to call chat.update. This is what my call looks like:

oauth_token = os.environ.get("OAUTH_TOKEN")
sc=SlackClient(oauth_token)
sc.api_call("chat.update", channel=channel_id, text=text, ts=ts)

I have also tried the Bot OAuth Token instead of the OAuth token, as well as all combinations of as_user (True, False, the bot's user ID...) without success.

Also, please notice that the channel and timestamp have been tested and are correct; I am able to update the messages by using the OAuth token when the message has been posted by me and I am the one invoking it through a slash command.

I am new to Slack API development. Can you let me know what I need to do to get it working?

Also, is it possible to customize other settings (like username and icon_url) when posting a message via chat.update? This is an important feature, as my bot sometimes posts using different display names and icons.

Upvotes: 5

Views: 3286

Answers (1)

Erik Kalkoken
Erik Kalkoken

Reputation: 32777

You say that you message are posted by webhook and I am not so sure those can be updated by API method.

To ensure you can update messages posted by your app you want to use one of two approaches:

  • Respond to the slash command instead of posting via webhook. You can control the behavior of slash command replies and e.g. overwrite the previous one to update it.
  • Use chat.postMessage API method instead of webhook to post your message.

I would recommend the first one, because it will work in any channel regardless of access rights. Your app will need to have access to a channel in order to use the 2nd approach. (which can be an issue for some private channels).

When you use one of those approaches it will also ensure that post from your app always have the icon and name of your app (the one that the slash command is linked to).

Upvotes: 3

Related Questions