Search code examples
slackslack-api

Slack: How to set default/selected value on interactive menu


I have slack interactive menu, which is working fine apart from the fact, that I want to have the currently selected value, shown in the menu. After reading the docs, I figured the attachment should look something like this:

{
    'text': 'settings.slack_notification_time ',
    'fallback': 'oops',
    'color': '#3AA3E3',
    'attachment_type': 'default',
    'callback_id': callback_id,
    'actions': [
        {
            'name': 'notification_time',
            'text': 'Choose a notification_time',
            'type': 'select',
            'selected_options': [
                {
                    'text': '07:00',
                    'value': 7
                }
            ],
            'options': [
                {text:'01:00',value:1},
                {text:'02:00',value:2},
                {text:'03:00',value:3},
                ....

            ]                       
        }
    ]
};

What is the correct way of setting the selected options?


Solution

  • Finally found the issue. Slack can apparently only compare string option.value. Forcing the values on both the options list and the select_options, to be strings, made it work.