Bot Core - microsoft-campus-community/workshop-shopping-list-bot GitHub Wiki
the bot calls the shopping list API first.
Prerequisite: You should have finished reading aboutGeneral Information
Previously, you have learned how to implement the fundamental building blog for a bot which are dialogs. On this page, you will learn how it comes all together. Using the AddItem
dialog, you will see how the bot finds out if the AddItem
dialog is the fitting dialog to start based on the chat participant's message. After the dialog queried all the information for an item, you will need to process this information.
For this page, you should open the shopping-list-bot/src/dialogs/mainDialog.ts
file in your IDE.
Main Dialog Basics
The MainDialog
class is the connector of the LUIS API, shopping list API, and the other dialogs. All these pieces are handed over to the constructor. When writing tests for the MainDialog
, the pieces can easily mock them.
When the bot's message handler receives an activity, it will call the run()
operation of the MainDialog
. When the stack for this conversation contains a dialog, then the MainDialog
will continue this existing dialog. If the dialog stack is empty, the main dialog will push itself onto the stack.
Like any other WaterfallDialog
, the MainDialog
consists of steps. The introStep
, actStep
, and finalStep
. The introStep
sends a hint to the chat participants about what they can do. Afterward, the actStep
calls the LUIS API and starts the best fitting dialog depending on the LUIS response. Lastly, the finalStep
processes the result of the dialog previously started. Furthermore, the finalStep
calls the shopping list API.
actStep
If LUIS is not configured, the default dialog to start is the AddItem
dialog. Otherwise, the bot will call the LUIS API to get the intent and entities for the message. Afterward, the top intent determines which dialog to start. For the following, assume that the top intent is the AddItem
intent. Before starting the AddItem
dialog, the LUIS result is parsed to directly get any input for the item from the chat participant's message. By implementing the AddItem
dialog, you have seen, that this allows the bot to skip steps of the AddItem
dialog when the item name or the unit are already known through the initial message. The AddItem
dialog is pushed onto the stack with the item as input and started. This ends the actStep
.
finalStep
The finalStep
processes the result of any dialog started in the actStep
. It passes the item retrieved from the result of the previous dialog to the FunctionService
we implemented before. The FunctionService
then calls the shopping list API, i.e., the Azure Functions, to persist the item and notifies the chat participants of its success or failure to persist the item.