5

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.

2
  • 2
    Only the owner of a message can change it. So if the message was posted with your bot token, you would need to use the same bot token to update it. Can you confirm that you tried that? Commented Mar 27, 2019 at 16:15
  • Erik - The message was posted by a slash command in our same workspace (which posts them through the webhook), so I am thinking it might not be possible to update them. Commented Mar 27, 2019 at 16:21

1 Answer 1

3

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).

Sign up to request clarification or add additional context in comments.

2 Comments

This helped solve my issue. I posted a message earlier through the webhook with my bot and wanted to update it with chat.update but kept getting the "cant update message" error despite having the right scope. I then reposted the message with chat.postMessage and the update worked.
Thanks, this was also my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.