I used the "no code" way to generate a Bot in Azure and connect it to a QnA Maker knowledge base.
I have then modified the code so that the Bot uses AdaptiveCards instead of HeroCards to support Markdown formatting in MS Teams channel (format used by QnA Maker).
I am trying to add SubmitActions to these adaptive cards when there are some prompts coming from the Knowledge Base. The objective is that if the user clicks on these SubmitActions it automatically send a message back to the Bot.
Please find below the code I implemented:
// adaptive card creation
var plCardBis = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
plCardBis.Body.Add(new AdaptiveTextBlock()
{
Text = result.Answer,
Wrap = true
});
// Add all prompt
foreach (var prompt in result.Context.Prompts)
{
plCardBis.Actions.Add(new AdaptiveCards.AdaptiveSubmitAction()
{
Title = prompt.DisplayText,
Data = prompt.DisplayText
});
}
//create the the attachment
var attachmentBis = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = plCardBis
};
//add the attachment
chatActivity.Attachments.Add(attachmentBis);
return chatActivity;
This works fine in the WebChat however in Teams if I click on a prompt it generates an error. Looking on internet I found that I should use an object for the Data field for Teams, instead of a simple string:
"data": {
"msteams": {
"type": "imBack",
"value": "Text to reply in chat"
},
}
Do you know how I could do that in C#? How could I update my code to add this object for the Data field? The number of Actions can vary according to the question asked by the user...
Any help would be greatly appreciated
Basically, there are two options for what you can attach to "Data" - either a plain string value, or any custom object. For your scenario, you need a custom object, so you need to define a class in your project to match what you need, something like:
public class MsTeamsDataResponseWrapper
{
[JsonProperty("msteams")]
public MsTeamsResponse MsTeamsResponse { get; set; }
}
public class MsTeamsResponse
{
[JsonProperty("type")]
public string Type { get; set; } = "imBack";
[JsonProperty("value")]
public string Value { get; set; }
}
then you'd use it like this:
...
Data = new MsTeamsDataResponseWrapper() { MsTeamsResponse = new MsTeamsResponse() { Value = prompt.DisplayText } }
...
In this case "Type" already defaults to "imBack", but you could also use it for "messageBack" at a later stage if you want to overwrite the default.