4

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!

Chasseur
  • 190
  • 2
  • 10

1 Answers1

5

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.

keelan
  • 66
  • 1
  • 2
  • 1
    Thank you! Indeed this method works, that's what I ended up doing. I should have posted it here but forgot :( thank you for posting, I sure hope it helps people in the future since as you point out it's not obvious. – Chasseur Sep 05 '17 at 01:47