Microsoft.Bot.Builder 4.10.3
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.
StaticSelectElementadapter.ProcessAsyncDeserialize the model properly and send the activity to the ActivityHandler
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