How to return selected option value of static_select block element in slack bolt

Viewed 1136

I am working with slack_bolt and trying to make different responses according to static_select in block element. How to print the value from selected_option?

the block is like this

        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Pick an item from the dropdown list"
            },
            "accessory": {
                "type": "static_select",
                "placeholder": {
                    "type": "plain_text",
                    "text": "Select an item",
                    "emoji": True
                },
                "options": [
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "value-0",
                            "emoji": True
                        },
                        "value": "value-0"
                    }, ....

In this case, how can I print the value("value-0") I selected after I select one option?

What variables do I need to use? with blow function

@app.message("hello")
def show_event(event, say):
        
        say(
            blocks=blocks,
            text="Pick a date for me to remind you"
        )

@app.action("select_action")
def handle_some_action(ack, body, logger, say):
        ack()
        logger.info(body)
        say(***"the variable to return selected value"***)
1 Answers

You need to add 'block_id' & 'action_id' in your static select block.
And then you can access it as:
state.values['block_id']['action_id'].value

You can use Block Kit Builder to test it real time.
Check the Action Preview tab to see the response payload. Block Kit Builder

Related