question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JsonReaderException when deserializing Slack payload to the InteractionPayload model

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
v-kydelacommented, Nov 19, 2020

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

1reaction
gabemilanicommented, Nov 19, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deserialize payload for interactive-messages · Issue #181
For this I have a basic endpoint which Slack sends a POST with the payload string: @RequestMapping(value = "/slack/action", method = ...
Read more >
Reference: Message payloads
All of the Slack APIs that publish messages use a common base structure, called a message payload. This is a JSON object that...
Read more >
Slack api request serialization
Somehow the model is not deserialized, but if change SlackResponse class to string, then inside will be raw json, as it may have...
Read more >
Handling user interaction in your Slack apps
If your app received an interaction payload after an interactive component was used inside of a message, you can use response_url to update...
Read more >
Verifying requests from Slack
Make sure that this request body contains no headers and is not deserialized in any way. Use only the raw request payload.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found