Skip to content

Latest commit

 

History

History
402 lines (279 loc) · 14.8 KB

quest5.md

File metadata and controls

402 lines (279 loc) · 14.8 KB

Quest 5 - Master's trail

< Quest 4 - 🏠Home - Quest 6 >

🌟🌟 🕒 1 h

We are following the official Tutorial: Create a weather bot with Composer -- however: instead of connecting to a Weather API, we are going to connect to our Online Store Service and retrieve additional information of a specific order.

Video guide provided by our Mentors

Walkthrough video link

The video shall provide hints where lore, poetic code snippets, and narrative cannot.

Create an Empty Bot in Composer

  1. The Bot Framework Composer is already installed on your VM. Start the Bot Framework Composer and click on + Create new

Create Bot

  1. Enter a name for the bot, e.g. fetch_order_infos

Provide name

Note: You might be asked to do a Tour of the Bot framework. Just skip this for now.

Modify the Greeting

  1. Select the Greeting trigger in the bot explorer and select the Send a response action
  2. Select Send a response

Send a response

  1. Click on the existing text and replace it with something like Welcome to the SAP Online Shop Bot. Type "orders" to get started

replace response

  1. After that you can test the bot by clicking on Start Bot at the top of the window. When the Bot is running you can click on Open Web Chat to see the Greeting in a new window.

Open Web Chat

Note: You might get a warning regarding Firewall access. Click on Allow.

Running Bot

  1. Close the Bot Framework Windows (not the Composer) by clicking on the X

Close Bot

Create a new dialog

📺 Jump to the video

  1. Select the ... next to the fetch_order_infos bot in the Bot explorer and click on + Add a dialog

Add Dialog

  1. Enter Name get_order and description Get the details of a specific order in the Create a dialog window and click on OK

Add Dialog name

  1. In the Bot explorer you can now see the new dialog "get_order" with a trigger BeginDialog. Select this trigger, click on the + and select Send a response

Add Send a Response

  1. While the Send a response dialog is selected, click on Add alternative to enter your initial response for the step get_order, e.g. Let's lookup some order information

Note - If you cannot see the properties pane for the "Send a response", the Bot framwork migth still be running. In this case, close the windows of the running bot.

Add Send a Response

Start a dialog from a trigger

📺 Jump to the video

  1. Select the fetch_order_infos dialog in the bot explorer and click on Change in the properties for Recognizer Type/Dispatch type. Then select the Regular expression type and click on Done

Change to regular expression

  1. Now with the trigger changed to Regular expression, click on the ... next to the fetch_order_infos and select + Add new trigger

Change to regular expression

  1. In the new windows select Intent recognized under trigger type and user order for the name and input of the regular expression

order as trigger

  1. Next we need to link this new order trigger to our Dialog. Start by selecting the order trigger in the box explorer, click on the + and select Dialog management -> Begin a new dialog

Begin a new dialog

  1. Having the Begin a new dialog step still selected, select get_order from the Dialog name dropdown.

Link to get order

  1. With this we can again test the flow. Click on start bot / restart bot and open the Web Chat:

Restart Bot

  1. If you now trigger our flow (e.g. I need to lookup an order), you will get the response from our get_order dialog.

Another test

Prompt a user for input

📺 Jump to the video

  1. In the next step we need to ask the user for an order number. For this select the BeginDialog step under get_order and click on the + sign after the Send a response step. From there Click on Ask a question and Number.

Ask for Number

  1. Select the Prompt for a number step and click on Add alternative to add a question, e.g. What order ID are you looking for?

Note - You might need to Close the Chat window again.

Ask for Number

Ask for Number

  1. Next click on User Input and in the property field enter, user.orderID

Ask Order ID

Call the Online Shop OData service

📺 Jump to the video

  1. Now that we have all the information it is time to call the OData service. Under the User input dialog, click on the + and select Access external resource -> Send an HTTP request

Send HTTP request

  1. For the HTTP method, select "GET" and for the URL enter
http://13.81.170.205:50000/sap/opu/odata4/sap/zui_onlineshop_ms1_o4/srvd/sap/zui_onlineshop_ms1/0001/Online_Shop?$filter=OrderID%20eq%20%27${user.orderID}%27

Send HTTP request

Note - For the order ID we user the property stored in the answer from the user stored in {user.orderID}

  1. To authenticate with the user S4H_EXT, click on Add new in the Headers section and enter as follows

Key Value
Authorization Basic czRoX2V4dDpXZWxjb21lMQ==

Send HTTP request

Warning - Sometimes these properties are not stored. Before continuing with the next step, click on Add New to leave the focus of the current Value input field.

  1. We expect a response in json and we want to store the results in a variable, enter dialog.api_response for the Result property and json for the Response type.

Result properties

  1. With the response from the Online Shop we can now check if everything was OK. For that we create a if/else branch by clicking on the +, selecting Create a condition and using the Branch: If/else action

Create branch

  1. In the Branch: If/else dialog select Write an expression from the Condition drop down.

Select Write Expression

  1. Enter the expression, which checks if the status code is 200.
=dialog.api_response.statusCode == 200

Select Write Expression

  1. In the True branch, click on the + and select Manage Properties -> Set properties

Set properties

  1. For each of the following properties, click on Add new under Assignment.

Add new properties


Property Value
dialog.orderID =dialog.api_response.content.value[0].OrderID
dialog.Ordereditem =dialog.api_response.content.value[0].Ordereditem
dialog.Purchasereqn =dialog.api_response.content.value[0].Purchasereqn
dialog.Prstatus =dialog.api_response.content.value[0].Prstatus
dialog.quantity =dialog.api_response.content.value[0].quantity
dialog.DescriptionText =dialog.api_response.content.value[0].DescriptionText

Properties added

  1. We should have all the information now so we can write a response to the user. Click on + in the True branch and click on Send a response

Send response

  1. Since we want to reply with an Adaptive Card, click on + and select Attachments

Add Attachment

  1. Then click on Add new attachment -> Create from template -> Adaptive Card 📺 Jump to the video

Select Adaptive Card

  1. Copy and paste/replace the content from below in the Attachment field.

Note - To learn more Adaptive Cards format, read the documentation

AdaptiveCard code block

> To learn more Adaptive Cards format, read the documentation at
> https://docs.microsoft.com/en-us/adaptive-cards/getting-started/bots
- ```{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.2",
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "TextBlock",
            "text": "Order Item Information - ${dialog.orderID}",
            "wrap": true,
            "size": "Large",
            "weight": "Bolder",
            "color": "Accent"
        },
        {
            "type": "TextBlock",
            "text": "Information about Order ID: ${dialog.orderID} - ${dialog.Ordereditem}",
            "weight": "Bolder",
            "isSubtle": false
        },
        {
            "type": "FactSet",
            "facts": [
                {
                    "title": "Order ID",
                    "value": "${dialog.orderID}"
                },
                {
                    "title": "Order Item",
                    "value": "${dialog.Ordereditem}"
                },
                {
                    "title": "Quantity",
                    "value": "${dialog.quantity}"
                },
                {
                    "title": "Description",
                    "value": "${dialog.DescriptionText}"
                },
                {
                    "title": "PR Status",
                    "value": "${dialog.Prstatus}"
                },
                {
                    "title": "Purchase Requisition #",
                    "value": "${dialog.Purchasereqn}"
                }
            ]
        }
    ]
}```

Content Added

Warning - Make sure that header "> To learn more Adaptive Cards..." is still there.

  1. Also add a response for the False branch using:
Something went wrong: ${dialog.api_response.content.message}.

Error response

  1. In order to enable a second run we clean-up the property to enable the user to enter another Order ID. Under the True/Fail branch, under the Send a response, click on the +, select Manage properties and click on Delete a property

Error response

  1. Enter user.orderID in the Properties of the Delete a property field.

Delete order ID

Run the bot

📺 Jump to the video

Click again on Restart bot -> Open Web Chat to test the integration.

Demo bot run

(Optional) Publish the bot to Teams

Follow the steps outlined here to publish the Bot to Azure and from there to Teams.

Where to next?

< Quest 4 - 🏠Home - Quest 6 >

🔝