Botbuilder-dotnet: JsonReaderException when deserializing Slack payload to the InteractionPayload model

Created on 5 Nov 2020  路  8Comments  路  Source: microsoft/botbuilder-dotnet

Version

Microsoft.Bot.Builder 4.10.3

Describe the bug

JsonReaderException when deserializing Slack payload to the InteractionPayload model.

Problem: Newtonsoft.Json.JsonReaderException at Newtonsoft.Json.JsonTextReader.ReadStringValue
Message: Unexpected character encountered while parsing value: {. Path 'state', line 1, position 4505.

i.e. exception is thrown when a user selects an option from the Slack static select element.

Slack sends a dictionary of objects on state property and the Slack adapter library is trying to deserialize to a string.
Slack API reference: https://api.slack.com/reference/interaction-payloads/block-actions#fields
Microsoft.Bot.Builder.Adapters.Slack.Model.InteractionPayload class has the State property as a string property.

To Reproduce

  1. Create a chatbot project using the Microsoft.Bot.Builder.Adapters.Slack.SlackAdapter
  2. Configure the Slack app: set the Interactivity request URL to your chatbot endpoint
  3. Post a message to Slack using the StaticSelectElement
  4. Select an option from the select element
  5. See the error happening on adapter.ProcessAsync

Expected behavior

Deserialize the model properly and send the activity to the ActivityHandler

Bot Services bug customer-replied-to customer-reported needs-triage

All 8 comments

Thank you for the report, @gabemilani

I'm having trouble following your repro steps. Could you provide a bit more information about how to reproduce the problem? What is a StaticSelectElement?

Hello @v-kydela
The StaticSelectElement is a class from the dependency library SlackAPI. Here you can find more information about it: https://api.slack.com/reference/block-kit/block-elements#static_select
Whenever I use this and select an option the SlackAdapter throws an exception while trying to process the request.

@gabemilani - Thank you for the link. I've found the source code here, but can you elaborate a bit more by showing a code example of an actual static select element and how you're posting it to Slack?

Here is a example:

var blocks = new List<IBlock>()
{
    new SectionBlock
    {
        text = new Text
        {
            type = "mrkdwn",
            text = "Select a fruit"
        }
    },
    new ActionsBlock() 
    {
        elements = new [] 
        { 
            new StaticSelectElement
            {
                placeholder = new Text { type = "plain_text", text = "Fruit" },
                action_id = "select-fruit",
                options = new [] {
                    new Option
                    {
                        text = new Text { type = "plain_text", text = "Apple" },
                        value = "select-fruit|apple"
                    },
                    new Option
                    {
                        text = new Text { type = "plain_text", text = "Orange" },
                        value = "select-fruit|orange"
                    }
                }
            }
        }
    }
};

Send a post request to the following API URL https://api.slack.com/methods/chat.postMessage#arg_blocks with that blocks payload

Now it's happening with ButtonElement too.
A quick fix is to change the property state from the InteractionPayload class to an object instead of a string.

@gabemilani - I have reproduced the error and I'm working on a fix

That's great! Would you know a prediction of when this will be released?
Let me know if I can help with anything else. Thanks for your work @v-kydela !

@gabemilani - The PR is awaiting a code owner review

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonh-msft picture brandonh-msft  路  4Comments

sgellock picture sgellock  路  4Comments

nrandell picture nrandell  路  6Comments

digitaldias picture digitaldias  路  6Comments

tiagodenoronha picture tiagodenoronha  路  6Comments