Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a slackbot button after clicking on it

I'm creating buttons for a slackbot using something like:

const messageB = {
        "attachments": [
            {
                "text": "Essa mensagem foi útil?",
                "callback_id": "button_feedback",
                "color": "#3AA3E3",
                "attachment_type": "default",
                "actions": [
                    {
                        "name": "button_click_yes",
                        "text": "sim",
                        "type": "button",
                        "value": "yes"
                    },
                    {
                        "name": "button_click_no",
                        "text": "não",
                        "type": "button",
                        "value": "no"
                    }
                ]
            }
        ]
    };

But the button remain active after the message was sent, and can be used again by the user. I want to deactivate it, or delete it after it was used. But i can't find about it anywhere in the docs.

like image 782
Newton Joaquim Avatar asked Dec 11 '17 13:12

Newton Joaquim


1 Answers

Clicking on a button will always fire a request to your Slack app. If you want to remove the button after it was clicked you need to update your original message with a new one that reflects the changed state (e.g. button removed). Its not possible to show deactivated buttons with Slack though, so you need to remove it.

To replace the original message all you need to do is respond to the Slack request with an updated message.

However, it will technically still be possible for users to click on your button twice (e.g. due to network delays), so you app should be able to response to multiple clicks on your buttons by the same user in an appropriate way.

See also here for the official documentation on the topic.

See also here and here for answer on a similar topic.

like image 182
Erik Kalkoken Avatar answered Nov 16 '22 07:11

Erik Kalkoken