microsoft / BotFramework-Services

Microsoft Bot Framework Services
Creative Commons Attribution 4.0 International
38 stars 11 forks source link

Slack Interactive Message Menus with DeliveryMode set to Ephemeral generate error #363

Open asaintsever opened 2 months ago

asaintsever commented 2 months ago

Add a Slack legacy interactive message menu to your activity:

IMessageActivity respActivity = Activity.CreateMessageActivity();
List<object> attachments = new List<object>();
List<object> actions = new List<object>();

// Build select menu
actions.Add(new
{
    name = "MENU_SELECT",
    text = "Select an account...",
    type = "select",
    options = new object[]
    {
        new
        {
            "text": "Account 1",
            "value": "account1"
        },
       new
       {
           "text": "Account 2",
           "value": "Account2"
       }
   }
});

attachments.Add(new
{
    fallback = "You are unable to choose an account",
    callback_id = "NA",
    color = "#3AA3E3",
    attachment_type = "default",
    actions = actions
});

respActivity.ChannelData = new
{
    text = "*Account Selection*",
    attachments = attachments
};

If you send the activity as defined above, no issue, it will show up on Slack, you can select an entry in the menu and an event is sent without any error. If you inspect the network traffic you'll see Slack sending this POST request:

POST https://my-bot-tests-xxx.slack.com/api/chat.attachmentAction?_x_id=61a2bc38-1719047525.780&_x_csid=nAVN34hw6lE&slack_route=XXX&_x_version_ts=1719018759&_x_frontend_build_type=current&_x_desktop_ia=4&_x_gantry=true&fp=8f&_x_num_retries=0

With payload:

{"actions":[{"id":"1","name":"MENU_SELECT","text":"Select an account...","type":"select","data_source":"static","options":[{"text":"Account 1","value":"Account1"},{"text":"Account 2","value":"Account2"}],"selected_options":[{"value":"Account1"}]}],"attachment_id":"1","callback_id":"NA","channel_id":"XXX","message_ts":"1718978926.546839","prompt_app_install":false,"team_id":"XXX"}

And response: {"ok":true}

Now, I want to display the interactive menu using an ephemeral message as I don't want other Slack users to see what account I selected. I just add following line to my code:

respActivity.DeliveryMode = DeliveryModes.Ephemeral;

Now, going back to Slack, my interactive menu is displayed properly with the Only visible to you mention, meaning it has been sent as an ephemeral message just like I wanted to. But when I select an entry in the menu, now Slack returns an error.

The POST request is almost identical as the previous one except for the "is_ephemeral":true payload field that is new. See:

POST https://my-bot-tests-xxx.slack.com/api/chat.attachmentAction?_x_id=61a2bc38-1719048029.946&_x_csid=pdl0xabFIAY&slack_route=XXX&_x_version_ts=1719018759&_x_frontend_build_type=current&_x_desktop_ia=4&_x_gantry=true&fp=8f&_x_num_retries=0

Payload with new "is_ephemeral":true field:

{"actions":[{"id":"1","name":"MENU_SELECT","text":"Select an account...","type":"select","data_source":"static","options":[{"text":"Account 1","value":"Account1"},{"text":"Account 2","value":"Account2"}],"selected_options":[{"value":"Account1"}]}],"attachment_id":"1","callback_id":"NA","channel_id":"XXX","is_ephemeral":true,"message_ts":"1719048014.000500","prompt_app_install":false,"team_id":"XXX"}

And response now contains an error: {"ok":false,"error":"dispatch_failed"}

Looking at the network traffic, Slack emits another call just after with additional error info:

POST https://slack.com/beacon/error

{"subtype":"missing_subtype","message":"hashed timestamp chat.attachmentAction not ok: dispatch_failed","stack":"dispatch_failed: 61a2bc38-1719048029.946 chat.attachmentAction not ok: dispatch_failed\n    at Hn._onNotOk (https://a.slack-edge.com/bv1-13-br/gantry-v2-shared.ea6777821724f355444d.min.js?cacheKey=gantry-1719018759:5:377182)\n    at Hn.resolve (https://a.slack-edge.com/bv1-13-br/gantry-v2-shared.ea6777821724f355444d.min.js?cacheKey=gantry-1719018759:5:376785)\n    at Hn._onLoad (https://a.slack-edge.com/bv1-13-br/gantry-v2-shared.ea6777821724f355444d.min.js?cacheKey=gantry-1719018759:5:361634)"}

If I remove the respActivity.DeliveryMode = DeliveryModes.Ephemeral; from my code, it works ok again.

So it seems there's an issue when Slack adds the "is_ephemeral":true field in the payload request and the Slack Bot Adaptor fails to handle it properly.

Note that my bot does not receive any event from Slack/Bot Adapter when the error occurs: the error sent as response to the Slack event comes from a higher layer (MS Slack Adapter maybe, to be confirmed).

geo-msft commented 1 month ago

Hi,

I raised this issue in the Bot builder SDK repo https://github.com/microsoft/botframework-sdk/issues/6657