ChannelData form Slack is not a valid format
When Slack sends a message to my bot I receive some information in the ChannelData property that I like to access. However the Channeldata comes in this format (value copied form the Watch window):
{{ "SlackMessage": { "type": "message", "channel": "D0ZFJ5ECR", "user": "U0Z1D812M", "text": "news", "ts": "1475639797.000055", "team": "T0YDZTCBD" }, "ApiToken": "some token" }}
Notice the "{{" section.
Based on this: https://docs.botframework.com/en-us/csharp/builder/sdkreference/channels.html
I believe I should be getting something like
{ "Payload":{ "SlackMessage": { "type": "message", "channel": "D0ZFJ5ECR", "user": "U0Z1D812M", "text": "news", "ts": "1475639797.000055", "team": "T0YDZTCBD" }, "ApiToken": "some token" }}
But I seem to be missing the "Payload:" element.
Is there a work around this? How can I access the Channeldata fields?
Thank you
The "Payload" section you are referring to is only sent in response to a button click event in Slack. A normal message from Slack should contain ChannelData with two properties; SlackMessage and ApiToken. SlackMessage is the raw message that was sent to the channel by Slack and ApiToken is your bot's Slack Api token that you can use to make direct Slack api calls if needed.
I'm not sure why you are seeing double brackets. Please add your bot Id and I'll dig into our logs and see if I can figure out what's going on.
Thanks. My bot app id is 122dd7ca-2596-4d72-b679-c696e212987a
If I could get rid of the double brackets somehow that would help.
I'm not seeing any malformed messages in the logs. Are you using the C# or Js sdk?
Hi Craig - I am using c# version 3.2.1. Thanks for looking into this.
I confirmed that the c# sdk doesn't alter the channeldata property. What do you get when you serialize the incoming activity message via JsonConvert.SerializeObject(message)?
I solved it. The problem was that I have tried to serialize the IMessageActivity object directly like this: ActivityJson = new JavaScriptSerializer().Serialize(Activity);
When done like this the above Activity.ChannelData property serializes to this result:
[[[[[]],[[]],[[]],[[]],[[]],[[]]]],[[]]]
But if I use this code to serialize the ChannelData property separately than it works fine:
JObject cdata = Activity.ChannelData as JObject; if (cdata != null ) { log.ChannelDataJson = cdata.ToObject
The result of this is something like this (which is what I needed): { "SlackMessage": { "type": "message", "channel": "D0ZFJ5ECR", "user": "U0Z1D812M", "text": "news from <#C0YFSM50S|general>", "ts": "1475997246.000095", "team": "T0YDZTCBD" }, "ApiToken": "some token"}
Thank you for your help.
Glad to hear. I'll go ahead and close this issue for now and you can reopen if you have additional questions.