From Bright Pattern Documentation
< 5.3:Scenario-builder-reference-guide‎ | Exercises
Revision as of 04:10, 29 May 2024 by BpDeeplTranslateMaintenance (talk | contribs) (Updated via BpDeleteTranslateTags script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
• 5.19 • 5.3 • 5.8


How to Configure a Chat Scenario That Uses a Microsoft Azure Web App Bot

In our tutorial, How to Configure a Microsoft Azure Web App Bot for Chats, you learned how to set up a basic Web App Bot from a template.

In this scenario exercise, you will learn how to edit a Bright Pattern Contact Center scenario to use your Web App Bot in a chat conversation.

Procedure

Because we are using Bright Pattern scenario blocks for authentication to the Direct Line Bot Framework and for having a chat conversation, no integration account setup is needed. Simply download our example scenario, and follow the instructions to edit it.

Step 1: Import and edit example scenario

  1. In the Bright Pattern Contact Center Administrator application, open the scenario that will be using your bot.

  2. Import our example scenario File:App Azure Web App Bot Example.zip to get started quickly. This basic scenario includes comments to describe how the scenario blocks are being used.

Step 2: Add secret key in Set Variable

In the first Set Variable block, set the following properties:

  1. Variable name - Name the block (e.g., “Secret”)

  2. Value - The secret key generated by the Azure Bot Framework when you created the Direct Line channel. Your Bright Pattern scenario will use this secret key to authenticate the Direct Line API requests that it issues to communicate with your bot.


Variable scenario block with the secret key in the Value field


Step 3: Authenticate to Direct Line API 3.0

In the first Fetch URL block we will obtain a session token to authenticate requests to Direct Line API 3.0 by using the secret that you copied from the Direct Line channel configuration page.

Set the following properties:

  • Title text - Name the block (e.g., “Get token”)

  • Request type - POST

  • URL to fetch - https://directline.botframework.com/v3/directline/tokens/generate

  • Extra Headers - Authorization: Bearer $(secret)

  • URL parameters - None

  • Content Type - application/JSON

  • Body - Empty

  • Username - Leave blank

  • Password - Leave blank

  • Initial path in the result JSON - Leave blank

  • Scenario variable prefix for JSON data - jstoken


Fetch URL scenario block being used for authentication


Step 4: Add token to Set Variable

In the second Set Variable block, set the following properties:

  • Variable name - Name the block (e.g., “token”)

  • Value - $(jstoken.token)


Variable scenario block setting the token variable the Value field


Step 5: Start a conversation

In the second Send Message+ block, we will open a new Direct Line conversation by issuing a POST to the /v3/directline/conversations endpoint. While the conversation is open, both the bot and client may send messages.

If the request is successful, the response will contain an ID for the conversation (i.e., “conversationId” which is needed in later steps), a token, a value that indicates the number of seconds until the token expires, and a stream URL that the client may use to receive activities via WebSocket stream.

Set the following properties:

  • Title text - Name the block (e.g., “Start conversation”)

  • Request type - POST

  • URL to fetch - https://directline.botframework.com/v3/directline/conversations/

  • Extra Headers - Authorization: Bearer $(token)

  • URL parameters - None

  • Content Type - application/JSON

  • Body - Empty

  • Username - Leave blank

  • Password - Leave blank

  • Initial path in the result JSON - Leave blank

  • Scenario variable prefix for JSON data - conversation


Fetch URL block being used to open a new Direct Line conversation


Step 6: Send a message to the customer

In the Send Message+ block, specify the message you want to send in the conversation.

Set the following properties:

  • Media type - Chat

  • Message - Any text message (e.g., “Hello and welcome!”)


Send Message+ block being used to send a message to the customer


Step 7: Prompt for a customer response or wait

In the Request Input block, we can optionally prompt for a response from the customer and save the response to the "user_input" variable name. Alternatively, we can simply wait for text input from the previous scenario block.

Set the following properties:

  • Prompt with - text message

  • Message to send - Leave empty

  • Result variable name - user_input


Request Input block could be used to prompt for a customer response


Step 8: POST activities

In the third Fetch URL block, we will use the Direct Line 3.0 protocol to exchange activities supported by your bot, like message activities and typing activities. We will issue a POST to the /v3/directline/conversations/$(conversation.conversationId)/activities endpoint, where “$(conversation.conversationId)” is the ID that was obtained from the previous Fetch URL block’s POST request to the the /v3/directline/conversations endpoint.

Set the following properties:

{
    "type": "message",
    "from": {
        "id": "user1"
    },
    "text": "$(user_input)"
}


  • Username - Leave blank

  • Password - Leave blank

  • Initial path in the result JSON - Leave blank

  • Scenario variable prefix for JSON data - message_id


Fetch URL block being used to POST activities


Step 9: Retrieve activities

In the fourth Fetch URL block, we will retrieve activities (e.g., your bot’s answer) by using HTTP GET.

Set the following properties:


Fetch URL block being used to retrieve the bot's answer


Step 10: Set conditions for routing bot answers

In the If block and the Send Message+ block, we will specify that if the bot has an answer, then we will send that answer to the customer in a chat message using $(azure_bot_answer.text).

Set the following properties:

  • Exit label - Has an answer

  • Conditions

    • Scenario variable (string)

    • azure_bot_answer.replyToId

    • is

    • =

    • $(message_id.id)


If block being used to set conditions to send the bot's answer to the customer, if there is one


Step 11: Pass along the bot's answer to the customer

Under the “Has an answer” exit, add a Send Message+ block and set the following properties:

  • Media type - Chat

  • Message - $(azure_bot_answer.text)


Send Message+ block being used to send the bot's answer


Step 12: Get the next bot answer

In the Get Next Record block, we will get the next bot answer, if there is one.

Set the following properties:

  • Title text - Any name

  • Direction - Next record

  • Recordset name - azure_bot_answer


Get Next Record block being used to request the next bot answer


Step 13: Use Goto to request input again

If there are no more answers from your bot, request input again by using the Goto block.


Goto block pointing to Request Input


Step 14: Keep checking for bot answers

Add another Goto block and point it to the If block. Doing so will create a loop that gets the bot’s answer, sends it in chat, and checks for more bot answers until there are no more.


Goto block pointing to If block


Step 15: End the conversation

In the last Fetch URL block, we will end the conversation by sending a POST with the “endOfConversation” activity to the channel's messaging endpoint.

Set the following properties:

{
    "type": "endOfConversation",
    "from": {
        "id": "user1"
    }
}

  1. Username - Leave blank

  2. Password - Leave blank

  3. Initial path in the result JSON - Leave blank

  4. Scenario variable prefix for JSON data - Leave blank


Fetch URL being used to end the conversation


Step 16: Save

Save the scenario.


Step 17: Configure your chat scenario entry to use the scenario

In the messaging/chat scenario entry you wish to use, make sure to set the correct scenario and service for your Web App Bot-enabled chat.


Messaging/Chat scenario entry properties


Your configuration is now complete. You can now launch a chat and try it.

< Previous | Next >