4

In the condition when there are multiple buttons present on the same chat history, the user may click the button from previous messages, therefore I am not able to identify from which dialog/message the input came from.

Example:

Refer this image

As chat bot is being implemented for multiple channels, I am avoiding to use Slack's interactive messages, so my aim is to handle this on bot framework itself. I tried getting information from session object as well as event_source but couldn't figure it out for a concrete solution.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
Ajaz
  • 43
  • 1
  • 4

1 Answers1

0

Use a unique ID in callback_id in your button attachment to distinguish between different sets of buttons, e.g. between prompt #1 and prompt #2. The callback_id will be included in the request that Slack sends to your app once a button is pressed.

Together with the general context information of a request like Slack Team ID, channel ID, user ID your app should be able to react correctly.

Example for button definition (from official documentation):

{
    "text": "Would you like to play a game?",
    "attachments": [
        {
            "text": "Choose a game to play",
            "fallback": "You are unable to choose a game",
            "callback_id": "wopr_game",
            "color": "#3AA3E3",
            "attachment_type": "default",
            "actions": [
                {
                    "name": "game",
                    "text": "Chess",
                    "type": "button",
                    "value": "chess"
                },
                {
                    "name": "game",
                    "text": "Falken's Maze",
                    "type": "button",
                    "value": "maze"
                },
                {
                    "name": "game",
                    "text": "Thermonuclear War",
                    "style": "danger",
                    "type": "button",
                    "value": "war",
                    "confirm": {
                        "title": "Are you sure?",
                        "text": "Wouldn't you prefer a good game of chess?",
                        "ok_text": "Yes",
                        "dismiss_text": "No"
                    }
                }
            ]
        }
    ]
}
Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • Yeah I am aware of callback_id, the thing is i am using Microsoft bot framework's prompt, which seems it doesn't allows to update callback_id in the payload. – Ajaz Aug 16 '18 at 18:51
  • hmm. can you set the name of a button? The API accepts any string as name, so you could also put a json string of an object there, e.g. `{"callback_id": "one", "value":"first"}`. see also this answer for more info on how that works: https://stackoverflow.com/questions/45969047/can-i-send-custom-properties-data-in-slack-message-attachments/45971885#45971885 – Erik Kalkoken Aug 16 '18 at 19:16