How to connect Microsoft QnA Maker in Dialogue Studio

Introduction

In this guide we will teach you how to connect to Microsoft QnA Maker in Dialogue Studio. Microsoft QnA Maker can be used as a knowledge base for your own Anywhere365 SelfService Bot. This can be implemented as a chat-bot, by using a chat based application. For example the Anywhere365 WebChat, Microsoft Teams or Skype for BusinessSkype for Business (formerly Microsoft Office Communicator and Microsoft Lync) is an instant-messaging client used by Anywhere365. In order to use SFB, a Microsoft Skype for Business Server is required. Skype for Business is enterprise software; compared to Skype, it has different features that target businesses.. This can also be implemented as a voice bot by using the transcription configured in Anywhere365.

 

Prerequisites

For this scenario the following point must be done first:

 

Configuration

Bot greeting

Our first step is initiate the bot, greet the customer and wait for there response.

We are going to start with a “Incoming conversation” node. This node only listens to both audio/video and Chat. This node is connected to our server using SignalR.

Steps:

  1. Drag and drop Incoming Call Node

  2. Open Node

    1. Select / Configure server

    2. Filter on:

      1. All = If you want both a Voice- and Chat-bot

      2. Audio/Video = If you want a Voice-bot

      3. Chat = If you want a Chat-bot

 

Next is greeting and asking what their question is the customer, this can be done with a “Say” node. In here you can type the text, this will be converted to speech using the a Speech engine (Learn More).

Steps:

  1. Drag and drop a Say Node

  2. Open Node

    1. Enter text you want to play

  3. Connect end of the Incoming Call node with begin of the Say Node

 

The next step depends on if you only want kind of bot you want to create.

 

Interaction - Voice- and Chat-bot

Our next step is to receive the question from the customer. Both channels has there own way. For a Voice-bot we need to transcribe what the customer is saying, for a Chat-bot we need to retrieve a chat message.

Because we want to handle both channels in one flow, we need to make a Switch.

Steps:

  1. Drag and drop a Switch Node

  2. Open Node

    1. Change Property to msg.session.type

    2. Add an option for the chat channel

      == Chat

    3. Add the option otherwise for audio/video

  3. Connect end of the Say node to begin of the Switch Node

You can now continue with both the interactions below. Connect option 1 to the Chat-bot interaction, connect the otherwise option to the Voice-bot interaction.

 

Interaction - Chat-bot

Now for the Chat-bot we want to give the customer the option to say their message. This can be done with a Wait for Chat Node.

Steps:

  1. Drag and drop a Wait for Chat node

  2. Connect end of the Say node (or option 1 of the switch node) with begin of the Wait for Chat node

 

Interaction - Voice-bot

For the Voice-bot we want to listen to the customer. This can be done with the Transcriptor Node

Steps:

  1. Drag and drop a Transcriptor node

  2. Open Node

    1. Optional change the language of the node

  3. Connect the end of the Say node (or option otherwise of the switch node) with begin of the Transcriptor node.

 

By default the Transcriptor node will keep listening to the customer and restarting the flow. This is useful when integrating with natural language understanding API, which can hold an conversation (for example DialogFlow). In this case we need to stop after the first output. This can be done stopping the transcriptor with a stop payload.

Steps:

  1. Drag and drop Change node

  2. Open Node

    1. Create rule

      1. Set: msg.payload.stop

        to: true (Boolean)

  3. Connect "events with transcriptor" end with begin of the Change node

  4. Connect end of the Change node with begin of the Transcriptor node

 

Finally we need to store the output in an object we can use later. This can be done with a Change node.

Steps:

  1. Drag and drop a Change node

  2. Open Node

    1. Create rule

      1. Set: msg.payload

        to: msg.payload.transcriptor.transcript

  3. Connect "events with transcriptor" end with begin of the Change node

 

Connect to QnA Maker

Now that we got an our question, we need to send it to QnA Maker of Microsoft. This is done with using a HTTP Request.

First we need to make the package for the request, this is done with a Function node.

Steps:

  1. Drag and drop a Function Node

  2. Open Node

    1. Fill in the following function:

      Note The Endpoint key can be found in QnA Maker, in Settings, under Deployment details.

      msg.headers = {

      "Content-Type": "application/json",

      "Authorization": "EndpointKey [Endpoint key]"

      };

      msg.payload = {

      "question": msg.payload

      };

      return msg;

  3. Connect the output of the previous node(s) (Voice-bot = Change node / Chat-bot = Wait for Chat node) to the begin of the Function node.

 

Now that we have a message set, we can send it to Microsoft QnA Maker. This is done with a HTTP Request Node.

Steps:

  1. Drag and drop a http request node

  2. Open Node:

    1. Method = Post

    2. URL = QnA Maker URL

      Note The URL (host) can be found in QnA Maker, in Settings, under Deployment details.

    3. Return = a parsed JSON object

  3. Connect the end of the Function node to the begin of the HTTP request node.

 

Handle response

Now that we have our response, we need to handle appropriate. First we need to store the output in an object we can use later. This can be done with a Change node.

Steps:

  1. Drag and drop a Change node

  2. Open Node

    1. Create 2 rules

      1. Set: msg.answer

        to: msg.payload.answers[0].answer

      1. Set: msg.score

        to: msg.payload.answers[0].score

  3. Connect end of the HTTP request node with begin of the Change node

 

Next we need to filter out answers who haven't scored properly. This can be done with a Switch node.

Steps:

  1. Drag and drop a Switch Node

  2. Open Node

    1. Change Property to msg.score

    2. Add an option for a good scoring answer

      > 70

    3. Add the option otherwise for bad scoring answer.

  3. Connect end of the Change node to begin of the Switch Node

 

Now we need to send the answer to the customer. This can be done with a Say node.

Steps:

  1. Drag and drop a Say Node.

  2. Open Node:

    1. Switch to Expression.

      Use the following expression:

      "We have found the following answer.." & answer

  3. Connect option 1 of Switch node with begin of the Say Node.

 

Also we need to tell the customer that we didn't find the answer. This can be done with a Say node.

Steps:

  1. Drag and drop a Say Node.

  2. Open Node:

    1. Enter text you want to play.

  3. Connect otherwise option of Switch node with begin of the Say Node.

 

Finally we need to wrap up the conversation. This can be done with a Disconnect node.

Steps:

  1. Drag and drop a Disconnect Node.

  2. Connect the end of both Says node with begin of the Disconnect Node.