node.jsslackbotkit

Update a bot message after responding to a slack dialog


I'm having some issues to update an interactive message after responding to a slack dialog. I'm using botkit on a node.js server.

Here is my workflow:

  1. User trigger an interactive message via a slash command
  2. User click a button on that message
  3. A dialog pops up, user fill the form and validate
  4. Something is done on the server side
  5. The first message should update

Now, here is the logic I'm using:

  1. User trigger an interactive message via a slash command

Nothing fancy, I use:

controller.on('slash_command', function (bot, message)

Then I parse the command, and send the appropriate message, with the appropriate attachments (buttons)

  1. User click a button on that message

Same, I use the event sent by botkit:

controller.on('interactive_message_callback', function (bot, message)

Then I create a dialog:

var dialog = bot.createDialog(
                        'Which book?',
                        JSON.stringify(callback),
                        'Ok'
                    )

Here I'm doing something really (really) dirty, and should not be done. But that's the only way I found to update the initial message after the dialog is filled. The callback_id actually contains an object, with the response_urlof the initial message (and something to identify the form).

  1. A dialog pops up, user fill the form and validate
  2. Something is done on the server side

Here, I use once more the event provided by botkit:

controller.on('dialog_submission', function (bot, message)

then I parse the message.submission.callback_id and detect the response_url. With this, I can create an object I call originalMessage.

  1. The first message should update

At the moment I use :

bot.replyInteractive(originalMessage, 'DONE, everything is saved.');

with originalMessagecontaining the response_url of the first message. It does work. The first message is being replaced by the new one.

But I'm really not happy with that solution, and was wondering if I was missing something somewhere. I've seen couple apps having that type of workflow, so there must be a way.

Thank you for your help :)


Solution

  • Slack has now changed their API and the way to persist data with the new Modals is a little different.

    When a dialog is submitted, your app receives an HTTP request. dialog_submission events contained a response_url that allowed you to post a message tied to the channel the dialog was initiated from. However, modals don't rely on a channel context. This means that the view_submission event will not contain a response_url.

    If you want to persist data when opening a Modal, you can pass whatever data you want to persist in a private_metadata field.

    Whatever data you passed will be returned to you on the modal submission callback.