松弛 API - chat.update : "message_not_found"
Slack API - chat.update : "message_not_found"
我正在使用 'slack-node' npm 包为我的团队构建一个简单的 Slack 应用程序。到目前为止,机器人的初始化工作得很好。在使用自定义斜杠命令后,我得到了 post 一条消息到频道。此消息包含一个交互式按钮,在用户按下该按钮后,消息应该会更新。
来自我的日志:
// 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' }
我确定我传递了正确的通道 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' 的意思是请求的时间戳不存在消息,这是不正确的,消息就在那里。
有没有人以前遇到过 same/similar 的问题?
感谢您的任何建议。
我可以确认 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 :
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.
希望对您有所帮助!
另一种在用户按下按钮后更新机器人消息的方法(交互式消息)。您可以使用 response_url
,它也包含在来自按钮按下的有效负载中。只需向此 response_url
发出另一个 POST
请求,就像 post 一条简单消息一样。
这也适用于 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
,但还没有尝试过。
我正在使用 'slack-node' npm 包为我的团队构建一个简单的 Slack 应用程序。到目前为止,机器人的初始化工作得很好。在使用自定义斜杠命令后,我得到了 post 一条消息到频道。此消息包含一个交互式按钮,在用户按下该按钮后,消息应该会更新。
来自我的日志:
// 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' }
我确定我传递了正确的通道 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' 的意思是请求的时间戳不存在消息,这是不正确的,消息就在那里。
有没有人以前遇到过 same/similar 的问题? 感谢您的任何建议。
我可以确认 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 :
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.
希望对您有所帮助!
另一种在用户按下按钮后更新机器人消息的方法(交互式消息)。您可以使用 response_url
,它也包含在来自按钮按下的有效负载中。只需向此 response_url
发出另一个 POST
请求,就像 post 一条简单消息一样。
这也适用于 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
,但还没有尝试过。