Search code examples
botframeworkazure-qna-maker

Call QnA API, Get Response and Display in Chat Bot Window as Bot Response


I'm working on a project using Bot Framework. Now one of the requirements of the project is the capability to search for a QnA result using the QnA Maker Generate Answer API "https://{QnA-Maker-endpoint}/knowledgebases/{knowledge-base-ID}/generateAnswer". We have a Search Box on a Web Page which then passes the "Question" variable to the JSON body which returns the result. I wanted to see if there is a way to display the API result on the actual Chat Bot window.

Thank you!


Solution

  • If you use BotFramework-WebChat, v4, you can achieve this quite easily. The 04.api/d.post-activity-event demonstrates a similar use case.

    Essentially, after the button is pressed, when an answer is successfully returned from QnA the page will emit an event. The event will make use of Web Chat's store.dispatch() method to post an activity to Web Chat that will then send to the bot. The activity can be a message, event, postBack, or messageBack type, as documented here.

    Hope of help!