Recently I released a dialog, available via NuGet, called the QnAMaker dialog. This dialog allows you to integrate with the QnA Maker service from Microsoft, part of the Cognitive Services suite, which allows you to quickly build, train and publish a question and answer bot service based on FAQ URLs or structured lists of questions and answers.
Today I am releasing an update to this dialog which allows you to add rich attachments to your QnAMaker responses to be served up by your bot. For example, you might want to provide the user with a useful video to go along with an FAQ answer.Right now the QnAMaker service only allows text based responses, so here is what you need to do to get going with rich attachments.
The first thing to do is to add attachment markup to your QnAMaker responses. An example markup snippet is below and you can alter this to return whatever type of attachment you wish, as long as it is supported by the Bot Framework and the channel you are targeting.
<attachment contentType=”video/mp4″ contentUrl=”http://www.youdomain.com/video.mp4″ name=”Video name” thumbnailUrl=”http://www.youdomain.com/video.png” />
Below is a screenshot of one of my services showing an answer with an attachment.
Next, you need to update to or install the latest version of the QnAMakerDialog via NuGet – you can read my original blog post which tells you how to setup and use the dialog.
If you are not using custom score handlers or overriding the DefaultMatchHandler then there should be nothing else to do. The dialog will now see the attachment markup in your answers, strip it out and send the appropriate attachment along with the answer 🙂
However, if you want to handle attachments in your own handlers you can use the helper method ProcessResultAndCreateMessageActivity which will generate a message activity with the answer and attachments ready to post back to the user. At this point you can override the answer text if you wish on the message activity, as shown below where I am overriding the DefaultMatchHandler.
1 2 3 4 5 6 7 8 9 |
public override async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result) { var messageActivity = ProcessResultAndCreateMessageActivity(context, ref result); messageActivity.Text = $"I found an answer that might help...{result.Answer}."; await context.PostAsync(messageActivity); context.Wait(MessageReceived); } |
That’s it! You should now be able to return rich attachments with the QnAMakerDialog! Reach out and let me know if you need any help implementing this or if you have any other great ideas for enhancements.
Does this work with Microsoft Teams ?
QnA Maker shouldn’t depend on the channel and I believe Teams supports video attachments too.
I did not suceed to make it work with Teams. I used an image however not a video but I guess it should work two. Could be an error in what I wrote though, I will check.
I need to suggest user some actions from my QnAMaker knowledge base. Please suggest as how we can achieve this? Basically, if user sends “horse”, and my bot does not returns proper result, I should be able to filter out the questions from my knowledge base and list some of them as SuggestedActions, so that user can directly tap on the Action, and my bot service should return results based on that action. Please suggest.
You can use the NoMatchHandler and return whatever message to the user you wish, that should be a good approach for you I think.
Hi Gary, is it possible to alter the chat window title within the bot code? Rather than the default “Chat” that comes with the qnamaker bot template?
Sure, you can find the web chat control on GitHub and alter the CSS and rebuild 🙂 https://github.com/Microsoft/BotFramework-WebChat
Hi How can I implement it using Node JS?
I’m afraid that I focus on C#, so haven’t implemented this for Node. You can easily call the service directly using Node and then parse your responses yourself to get what you are looking for though.
how do i add a new qna pair to an existing knowledge base using REST api and not the qnamaker.ai page
Hi! I have just released a C# library which does just that. Take a look over at and it is also available as a NuGet package too.