Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give an example with buttons and response handling #136

Open
michaelkruglos opened this issue Sep 11, 2019 · 6 comments
Open

Give an example with buttons and response handling #136

michaelkruglos opened this issue Sep 11, 2019 · 6 comments

Comments

@michaelkruglos
Copy link

Please, give an example of how to implement a slack bot, which proposes a few options by displaying buttons, and handles the button clicks.

@madhuracharya
Copy link

The RTM API doesn't support interactive messages. You will have to perform these using web API.
Please refer to this page for more information
https://api.slack.com/messaging/interactivity/enabling#responding_to_interactions

@leomozzer
Copy link

Follow the tutorial of this link https://api.slack.com/tutorials/intro-to-message-buttons

@chiumax
Copy link

chiumax commented Jan 5, 2020

Here, just add the attachment directly to params for postMessageToChannel.

Example:

    const params = {
        icon_emoji: ':smiley:',
        "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"
                        }
                    }
                ]
            }
        ]

    };
    app.postMessageToChannel(
        'general',
        'What\'s up laddies!', params
    )

Screenshot:
image

@prashant1k99
Copy link

prashant1k99 commented Jan 22, 2020

@dumblole How can I listen to the response of the button clicked by the user and take actions regarding that in interactive messages.
In simple words, which method is suitable for listening to response of the interactive blocks.

So as per your example if the user clicks Chess button, I want it to send to the server and based on that I want to respond with another message.

Such as responding with another interactive message of opening a modal.

@aliehsan90
Copy link

@prashant1k99 Did you found a solution for listening to the response?

@prashant1k99
Copy link

@aliehsan90 not yet, if you find it then please do tell us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants