gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:38:07 33 4
gpt4 key购买 nike

我正在使用“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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com