using .NET CLI 3.1.302
Bot Framework SDK 4.10.2
The bot is run with Slack using ngrok 2.3.35
My goal was to update the EchoBot base template have the bot react to a 'reaction_added' Slack event (adding a reaction emoji to a bot's message) by responding with a message (something like "Thanks for confirming"...). However the SlackAdapter fails to parse the JSON request I get from Slack on a 'reaction_added' event, creating a 500 Internal Server Error on my ngrok server and this stack trace in the .NET application:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
Newtonsoft.Json.JsonReaderException: Error reading string. Unexpected token: StartObject. Path 'event.item', line 1, position 149.
at Newtonsoft.Json.JsonReader.ReadAsString()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member,
String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member,
String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject[T]()
at Microsoft.Bot.Builder.Adapters.Slack.SlackAdapter.ProcessAsync(HttpRequest request, HttpResponse response, IBot bot, CancellationToken cancellationToken)
I think the problem is that the JSON deserialization happening within the SlackAdapter cannot handle nested objects; the JSON body received from a 'reaction_added' event looks like this: ( from the Events API page: https://api.slack.com/events/reaction_added )
{
"type": "reaction_added",
"user": "U024BE7LH",
"reaction": "thumbsup",
"item_user": "U0G9QF9C6",
"item": {
"type": "message",
"channel": "C0G9QF9GZ",
"ts": "1360782400.498405"
},
"event_ts": "1360782804.083113"
}
A 'message' event, which the bot and Slack Adapter handles correctly, looks like this - no nested object:
{
"type": "message",
"channel": "C2147483705",
"user": "U2147483697",
"text": "Hello world",
"ts": "1355517523.000005"
}
Steps to reproduce the behavior:
EchoBot.cs to handle 'reaction_added' events:protected override async Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
{
if(turnContext.Activity.Value is EventType slackEvent) {
// FIXME: Bot Framework SDK can't handle nested objects?
if(slackEvent.Type == "reaction_added") {
await turnContext.SendActivityAsync(MessageFactory.Text("Thank you for reacting!"), cancellationToken);
}
}
}
Bot should correctly parse the JSON request and respond with a message to the 'reaction_added' event.
@benbrown Could you take a look at this and respond to customer?
@JHaig343 - Thank you for the report. Does the app crash regardless of whether you have a handler defined?
@benbrown Thanks for the reply! - I just tested with all of my added handlers in EchoBot.cs removed (so only the OnMessageActivityAsync and MembersAddedAsync handlers that came with the template) and I can confirm that the application still crashes. I believe this is a adapter-level issue when processing a response from Slack Events API.
Thank you for confirming that! I'll get back to you ASAP when we learn more.
Gary let me know that this is a bug and can be addressed in the next release.
@garypretty Do you have any updates on this issue?
@tdurnford this should be on plan to fix in 4.11. @mrivera-ms this bug should be addressed as part of the next release.
Most helpful comment
@tdurnford this should be on plan to fix in 4.11. @mrivera-ms this bug should be addressed as part of the next release.