Slack API - chat.update: "message_not_found"

I use the slack-node npm package to create a simple Slack application for my team. Initializing the bot works fine. I got it to send a message to a channel after using a custom slash command. This message contains an interactive button, which should be updated after the user clicks on it.

From my journal:

// User uses /event slash command
18:48:50 UTC - - Received [POST] to path [/event]

// API response after posting the message
{ ok: true, message_ts: '1506538130.000343' }

// Incoming request after user pressed the button
18:49:32 UTC - - Received [POST] to path [/button_reply]

// Extracted channel id and message ts
C3PEQESP5 1506538130.000343

// respond after using chat.update
{ ok: false, error: 'message_not_found' }

I made sure that I pass the correct channel identifier and ts message, I am 100% sure that these parameters are correct, since you only need to compare the response (objects).

This is the package I'm using: https://www.npmjs.com/package/slack-node

Here is the code snippet I'm using:

module.exports = {

 postEphemeral : function(text, body, callback) {

  slack.api('chat.postEphemeral', {
     attachments:JSON.stringify(text.attachments) ,
     channel:body.channel_id,
     user:body.user_id
  }, function(err, response){
     console.log(response);
     return callback(null);
  });

 },

 updateMessage : function(text, body, callback) {

  console.log(body.channel.id, body.message_ts)

  slack.api('chat.update', {
     attachments:JSON.stringify(text.attachments) ,
     channel:body.channel.id,
     ts:body.message_ts
  }, function(err, response){
     console.log(response);
     return callback(null);
  });

 }

}

, slack- node web-api slack, . Slack 'message_not_found' , , , .

- / ? .

+4
2

, chat.postEphemeral , :

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"
}

:

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"
}

, chat.postMessage, :

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"
    }
}

:

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"
    }
}

, - , . https://api.slack.com/methods/chat.postEphemeral:

- Slack . , , .

, !

+3

- ( ). response_url, , . POST response_url , .

ephemeral !

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
});

(https://api.slack.com/interactive-messages) ( , ): "replace_original": true, .

+3

Source: https://habr.com/ru/post/1686501/


All Articles