首页 文章

使用botkit作为Slack机器人,有没有办法在对话时更新消息?

提问于
浏览
4

这是关于使用Botkit开发Slack bot .

Slack允许您更新消息 - 例如,如果您从用户那里获得输入(无论是通过文本还是按钮),您可以根据该消息更新消息 . (有关此内容的更多信息,请参阅"Replacing the original message":https://api.slack.com/docs/message-buttons) .

Botkit通过replyInteractive()支持这个,如下所示:https://github.com/howdyai/botkit/blob/master/readme-slack.md#message-buttons .

但是,Botkit的一个关键功能是支持会话线程 . 虽然这些允许您提出问题并允许按钮作为答案,但我没有看到在对话中进行交互式回复(即更新消息)的方法 .

知道怎么做吗?目前尚不支持的结论性答案也会有所帮助 . 谢谢!

1 回答

  • 2

    这是可能的,但不是以明显的方式 .

    bot.startConversation(message, function(err, convo) {
      convo.ask({
        text: "Here's some pretext",
        attachments: [{
          "text": "More text",
          "fallback": "Fallback text",
          "callback_id": "Test",
          "actions": [
            {
              "name": "yes",
              "text": "Yes",
              "value": "yes",
              "type": "button",
            },
            {
              "name": "no",
              "text": "No",
              "value": "no",
              "type": "button",
            }
          ]
        }]
      }, function(reply, convo) {// convo.ask callback
        bot.replyInteractive(reply, "This text replaces the previous message");
        convo.say("This is a regular message");
        convo.next();
      });
    });
    

    请注意 replyInteractive() 如何使用 reply 而不是 message .

    我知道这已经很晚了,但我希望它对某人有所帮助 .

相关问题