Slack API - chat.update : “message_not_found”

馋奶兔 提交于 2019-12-05 09:17:39

I can confirm the chat.postEphemeral generates messages that cannot be updated :

curl -X POST 'https://slack.com/api/chat.postEphemeral?token=xoxp-mytoken&channel=C143CVGRE&text=blabla&user=U334D3FFF&pretty=1'
{
  "ok": true,
  "message_ts": "1506544109.000059"
}

Then :

curl -X POST 'https://slack.com/api/chat.update?token=xoxp-mytoken&channel=C143CVGRE&text=updated&ts=1506544109.000059&pretty=1'
{
  "ok": false,
  "error": "channel_not_found"
}

Whereas, messages sent with chat.postMessage can be :

curl -X POST 'https://slack.com/api/chat.postMessage?token=mytoken&channel=C143CVGRE&text=blabla&pretty=1'
{
    "ok": true,
    "channel": "C143CVGRE",
    "ts": "1506544023.000474",
    "message": {
        "text": "blabla",
        "username": "Slack API Tester",
        "bot_id": "B4X35D333",
        "type": "message",
        "subtype": "bot_message",
        "ts": "1506544023.000474"
    }
}

Then :

curl -X POST 'https://slack.com/api/chat.update?token=mytoken&channel=C143CVGRE&text=updated&ts=1506544023.000474&pretty=1'
{
    "ok": true,
    "channel": "C143CVGRE",
    "ts": "1506544023.000474",
    "text": "updated",
    "message": {
        "text": "updated",
        "username": "Slack API Tester",
        "bot_id": "B4X35D333",
        "type": "message",
        "subtype": "bot_message"
    }
}

I think it's just because of the very nature of ephemeral messages, that are directed to an end user in a channel and are not persistent. Quoted from https://api.slack.com/methods/chat.postEphemeral :

Ephemeral message delivery is not guaranteed — the user must be currently active in Slack and a member of the specified channel. By nature, ephemeral messages do not persist across reloads, desktop and mobile apps, or sessions.

Hope this helps!

Another way to update bot messages after user pressed a button (interactive messages). You can use the response_url that's also included in the payload coming from the button-push. Just make another POSTrequest to this response_url just like you would post a simple message.

This works with ephemeral messages as well !

var response_url = body.response_url;

var options = {
  url: response_url,
  method: 'POST',
  body: JSON.stringify(text)
}

request(options,function(err, response, body) {
  // Continue doing stuff
});

Reading this (https://api.slack.com/interactive-messages) there might also be an additional parameter you could use (although I don't know when and how) : "replace_original": true , but haven't tried that yet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!