Adding rich attachments to your QnAMaker bot responses

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.

 

 

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.

 

3 thoughts on “Adding rich attachments to your QnAMaker bot responses

      1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *