I'm programming a bot that is using adaptive Cards ChoiceSet. Im trying to get the users choice. Now because the result doesnt Show in the Chat, I have to check in the OnTurnAsync
-Method, if the Message I get is a postback
.
How do i do this?
This is how I tried -> Null ReferenceException at
if (dc.Context.Activity.GetType().GetProperty("ChannelData") != null)
Edit from Botframework Support: Please do not use the code block below. It only works in Emulator. Instead, use:
if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
{
activity.Text = JsonConvert.SerializeObject(activity.Value);
}
My OnTurnAsync-Method:
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
DialogContext dc = null;
switch (turnContext.Activity.Type)
{
case ActivityTypes.Message:
if (dc.Context.Activity.GetType().GetProperty("ChannelData") != null)
{
var channelData = JObject.Parse(dc.Context.Activity.ChannelData.ToString());
if (channelData.ContainsKey("postback"))
{
var postbackActivit = dc.Context.Activity;
postbackActivit.Text = postbackActivit.Value.ToString();
await dc.Context.SendActivityAsync(postbackActivit);
}
}
await ProcessInputAsync(turnContext, cancellationToken);
break;
botframework
tag on your question, somebody on the Bot Framework team will get assigned to it to help you! - mdrichardson