pythonflaskslackslack-apislack-block-kit

Not receiving block_action payload when interacting with a Slack Block Kit modal


I've been working on a Slack bot to help handle emergency engagement for my team. It works really well, but all the configuration is in JSON files and it's time to make it "more interactive."

The other day we ended up with an email storm that triggered the bot over and over and over again, so I thought that a great and relatively simple place to start with the "more interactive" would be to add a "Snooze" button to our bot (as opposed to killing the running process).

I successfully display the modal, and the UI functions correctly, but I do not receive a payload on interaction. I expect my Flask App to receive a POST request containing payload data for an interaction, but I don't see any arrive not at the "/" endpoint that handles the majority of my interactions with Slack or the /911_snooze endpoint which is the one directly connected to the Slash Command.

I get a little warning triangle with the following error:

Modal displayed with error message

The JSON below is mostly created by Block Kit Builder, with some hand-cut, and the drop-down is created programmatically, based on an external list. Block Kit Builder reports no errors.

{
    "title": {
        "type": "plain_text",
        "text": "911 Snooze Alerts",
        "emoji": true
    },
    "submit": {
        "type": "plain_text",
        "text": "Submit",
        "emoji": true
    },
    "type": "modal",
    "callback_id": "snooze_911_alerts",
    "close": {
        "type": "plain_text",
        "text": "Cancel",
        "emoji": true
    },
    "blocks": [
        {
            "type": "divider"
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Application to Snooze"
            },
            "accessory": {
                "type": "static_select",
                "placeholder": {
                    "type": "plain_text",
                    "text": "Application",
                    "emoji": true
                },
                "options": [
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "APP1",
                            "emoji": true
                        },
                        "value": "BOE"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "APP2",
                            "emoji": true
                        },
                        "value": "IBOE"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "APP3",
                            "emoji": true
                        },
                        "value": "GBOE"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "APP4",
                            "emoji": true
                        },
                        "value": "Swift"
                    }
                ],
                "action_id": "application_select_action"
            }
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "How long do you want to snooze for:"
            },
            "accessory": {
                "type": "radio_buttons",
                "options": [
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "5 minutes",
                            "emoji": true
                        },
                        "value": "minutes-5"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "30 minutes",
                            "emoji": true
                        },
                        "value": "minutes-30"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "60 minutes",
                            "emoji": true
                        },
                        "value": "minutes-60"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "90 minutes",
                            "emoji": true
                        },
                        "value": "minutes-90"
                    }
                ],
                "action_id": "radio_buttons-action"
            }
        }
    ]
}

Solution

  • The element block needs to be inside an action block, or input block with dispatch_action: true.

    See https://api.slack.com/reference/block-kit/blocks#actions and https://api.slack.com/reference/block-kit/blocks#input