如何通过 API 将响应消息更新为斜杠命令?

How to update the response message to a slash command by API?

上下文

我正在构建一个基于斜杠命令的 Slack 应用程序,它正在创建一个 in_channel 带有按钮的响应消息供用户交互。斜线命令在私人频道中使用。

当用户单击按钮时,我的应用程序能够更新该消息以反映新状态 - 只需使用更新的消息回复斜杠请求并设置 replace_original = true.

问题

此外,我还想批量更新该消息,例如当计时器 运行 结束时。我一直在尝试使用 chat.update 更新消息,但出现 cant_update_message API 错误。

这是我在 Postman 中用于测试的请求:

https://slack.com/api/chat.update?token={TOKEN}&channel={CHANNEL}&ts={TS}&text=Updated&as_user=true

但是,根据 documentation 我应该可以更新机器人消息:

Valid message types

Only messages posted by the authenticated user are able to be updated using this method. This includes regular chat messages, as well as messages containing the me_message subtype. Bot users may also update the messages they post.

而且我要更新的消息显然属于我的 slack 应用程序,看起来像一条普通的机器人消息。以下是该消息在 conversations.history:

中的显示方式
{
    "text": "Some text...",
    "bot_id": "Bxxxxxxxx",            
    "type": "message",
    "subtype": "bot_message",
    "ts": "{TS}"
}

顺便说一句。我通过 chat.delete 使用相同的参数删除了该消息。

我错过了什么?

我与 Slack 支持人员讨论了我的问题,他们确认无法通过 chat.update 更新响应消息。

完整回复如下:

A in_channel slash command response cannot be updated by a user. Since a slash command response is not using the web API and therefore not associated with any particular token, it's not possible for the chat.update call to determine whether it's allowed to update the message or not. Hence the error.

My suggestion would be to send an ephemeral slash command response or a empty slash command response and then use the chat.postMessage API method to send an "in channel" message, which can be updated later using the chat.update API method.

按照建议,我现在将通过 chat.postMessage API 方法创建 "in-game" 消息,这样我可以稍后更新它。然而,这会产生私人频道的访问问题。为了缓解这种情况,我现在将要求用户将我的机器人用户添加到所有私人频道,这将使我的应用程序可以访问它。

我一开始就想避免这种方法,因为它为用户创建了一个额外的步骤,但没有更好的选择(顺便说一句,github 应用程序使用相同的方法).