Search code examples
botsslackbotkit

Using botkit for a Slack bot, is there a way to update messages when in a conversation?


This is about developing a Slack bot using Botkit.

Slack allows you to update messages in place - for instance, if you're getting input from the user (whether via text or buttons), you can update the message based on that. (More about this here, under "Replacing the original message": https://api.slack.com/docs/message-buttons).

Botkit supports this via replyInteractive(), as seen here: https://github.com/howdyai/botkit/blob/master/readme-slack.md#message-buttons.

However, a key function of Botkit is the support for conversation threads. While those allow you to ask a question and allow buttons as answers, I do not see a way to do an interactive reply (i.e. update the message) when in a conversation.

Any idea how to do this? A conclusive answer that it is not currently supported would be helpful as well. Thank you!


Solution

  • It is possible but not in an obvious way.

    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();
      });
    });
    

    Note how replyInteractive() uses reply instead of message.

    I know this is late but I hope it helps someone.