node.js - Slack API-chat.update : "message_not_found"

标签 node.js slack-api

我正在使用“slack-node”npm 包为我的团队构建一个简单的 Slack 应用程序。到目前为止,机器人的初始化工作得很好。在使用自定义斜杠命令后,我得到它来向 channel 发布消息。此消息包含一个交互式按钮,在用户按下该按钮后,消息应该会更新。

来 self 的日志:

// 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' }

我确保我传递了正确的 channel ID 和消息 ts,我 100% 确定这些参数是正确的,因为您只需要比较响应(对象)。

这是我正在使用的包:https://www.npmjs.com/package/slack-node

这是我使用的代码片段:

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 包使用了 slack 的 web-api 但不确定。根据 Slack 的说法,“message_not_found”意味着不存在具有请求的时间戳的消息,这是不正确的,消息就在那里。

有没有人以前遇到过相同/相似的问题? 感谢您的任何建议。

最佳答案

另一种在用户按下按钮后更新机器人消息的方法(交互式消息)。您可以使用 response_url,它也包含在来自按钮按下的有效负载中。只需向此 response_url 发出另一个 POST 请求,就像您发布一条简单消息一样。

这适用于 短暂的 消息!

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 ,但还没有尝试过。

关于node.js - Slack API-chat.update : "message_not_found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46455540/

相关文章:

amazon-web-services - 如何在 AWS API Gateway 中不返回任何内容?

javascript - Slack API(JSON 数据)

node.js - npm 损坏 : cannot find module 'proto-list'

node.js - 在nodejs中读取child_process.spawn的stderr中的所有内容

node.js - 如何访问 express.js 中的 ejs 对象

javascript - Node-slack web api : chat. delete 返回所有 channel 的 channel_not_found 尽管 channels.list 返回所有 channel

slack - Slack 是否提供对 IP 白名单的支持?

javascript - 如何在 Nodejs 中的 map 上添加额外的验证?

javascript - 尝试将来自 node.js http 服务器的文本拆分为单词数组进行响应

ssl - rtm_connect 到 slackbot 给出 SSL 证书验证错误