Botkit: response_type not working with interactive messages

Created on 22 Jun 2016  路  4Comments  路  Source: howdyai/botkit

https://api.slack.com/docs/message-buttons

I am not having luck with response_type: 'ephemeral' when using interactive messages:

    convo.ask({
      response_type: 'ephemeral',
      attachments: [
        {
          title: 'Do you want to proceed LOL?',
          callback_id: '123',
          attachment_type: 'default',
          actions: [
            {
              "name": "yes",
              "text": "Yes",
              "value": "yes",
              "type": "button",
            },
            {
              "name": "no",
              "text": "No",
              "value": "no",
              "type": "button",
            }
          ]
        }
      ]
    }, 

It is simply broadcasted to everyone.

Slack-related question

Most helpful comment

@dfischer @agassan I ran into the same problem and experimented on this a little bit myself. The result is a bit complicated to explain but let me give it a try:

As I see it you can use the 'response_type' attribute only in two cases:

  1. in response to a slash command (that's the use-case bot.replyPrivate() and bot.replyPublic() are made for)
  2. in response to a message button of a previously posted simple bot message (e.g. no message originating from a slash command) but only in combination with bot.replyInteractive() and setting 'replace_original' to 'false'.

Here is an example:

controller.hears('^experiment', ['direct_message', 'direct_mention'], (bot, message) => {
  console.log('Experiment started');
  bot.reply(message, {
    attachments: [
      {
        title: 'Experiment',
        callback_id: 'experiment',
        attachment_type: 'default',
        actions: [
          {
            name: 'public',
            text: 'Secret',
            value: '',
            type: 'button'
          }
        ]
      }
    ]
  });
});

controller.on('interactive_message_callback', (bot, message) => {
  console.log('Experiment continued');
  bot.replyInteractive(message, {
    text: 'Can you keep a secret?',
    replace_original: false,
    response_type: 'ephemeral'
  }, (err) => {
    if (err) {
      console.log(err);
    } else {
      console.log('Experiment finished')
    }
  });
});

As a result the 'Experiment' button will trigger the bot to answer with a hidden new message. I use this behavior to initiate a conversational user-interaction with buttons.

All 4 comments

Did you find a way to work?

@dfischer @agassan I ran into the same problem and experimented on this a little bit myself. The result is a bit complicated to explain but let me give it a try:

As I see it you can use the 'response_type' attribute only in two cases:

  1. in response to a slash command (that's the use-case bot.replyPrivate() and bot.replyPublic() are made for)
  2. in response to a message button of a previously posted simple bot message (e.g. no message originating from a slash command) but only in combination with bot.replyInteractive() and setting 'replace_original' to 'false'.

Here is an example:

controller.hears('^experiment', ['direct_message', 'direct_mention'], (bot, message) => {
  console.log('Experiment started');
  bot.reply(message, {
    attachments: [
      {
        title: 'Experiment',
        callback_id: 'experiment',
        attachment_type: 'default',
        actions: [
          {
            name: 'public',
            text: 'Secret',
            value: '',
            type: 'button'
          }
        ]
      }
    ]
  });
});

controller.on('interactive_message_callback', (bot, message) => {
  console.log('Experiment continued');
  bot.replyInteractive(message, {
    text: 'Can you keep a secret?',
    replace_original: false,
    response_type: 'ephemeral'
  }, (err) => {
    if (err) {
      console.log(err);
    } else {
      console.log('Experiment finished')
    }
  });
});

As a result the 'Experiment' button will trigger the bot to answer with a hidden new message. I use this behavior to initiate a conversational user-interaction with buttons.

Please let us know if this did not solve your issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iworkforthem picture iworkforthem  路  3Comments

benbrown picture benbrown  路  3Comments

koubenecn picture koubenecn  路  3Comments

TheJimFactor picture TheJimFactor  路  4Comments

JonnyBoy333 picture JonnyBoy333  路  3Comments