Search code examples
c#botframeworkchatbotmicrosoft-teamsazure-bot-service

Not getting value of Team Bot Isback


I have been trying to show some information to user on clicking button of my bot.

var card = new HeroCard
{
    Title = "Welcome to Covid-19 Tracker",
    Text = "Type 'help' to see what bot can do?",
    Subtitle = "Know more about Covid-19.",
    Buttons = new List<CardAction>
    { 
        new CardAction(ActionTypes.PostBack, "How it spreads?", value: "spread"),
        new CardAction(ActionTypes.MessageBack, "Symptoms" , value: "Symptom"),
        new CardAction(ActionTypes.MessageBack, "Prevention Guidelines" , value: "Prevention")
    },
};

When i am clicking on these button from emulator i am able to read the value to property but when i am deploying it to Teams, value is coming as {}. I am retrieving value using below code.

turnContext.Activity.Value.ToString()

Solution

  • Microsoft Teams does not support postBack as a distinct action type from messageBack so it will interpret postBack and messageBack the same way. You can see the four properties you can use in a messageBack action here.

    Your action isn't working in Teams because you're trying to use a string for the value property. If you want to keep using a string then you can use the text property like Sandeep suggested, and then your bot will have to read the text from the incoming activity's text property instead of its value property. If you want to keep using the value property then you should use an object instead of a string like this:

    new CardAction(ActionTypes.MessageBack, "Prevention Guidelines", value: new { choice: "Prevention" })
    

    This would populate the value property of the incoming activity with that same object, so you could access the user's selection like this:

    var selection = turnContext.Activity.Value is null ? null : (JToken.FromObject(turnContext.Activity.Value) as JObject)?["choice"];