Skip to content

Latest commit

 

History

History
201 lines (177 loc) · 10.6 KB

File metadata and controls

201 lines (177 loc) · 10.6 KB

cafe bot

Bot Framework v4 cafe bot sample

Contoso cafe bot is a complete and fairly sophisticated sample that demonstrates various parts of the BotBuilder V4 SDK and BotBuilder CLI tools in action.

This sample relies on prior knowledge/ familiarity with the following tools and services

Concepts covered in this sample

Contoso cafe bot is a fairly sophisticated bot sample that uses the following concepts in the BotBuilder V4 SDK and BotBuilder CLI tools -

Scenarios demonstrated

  • Welcoming users
  • Using cards to interact with users
  • Using suggested actions to solicit user input
  • Single and multi-turn conversations with users
  • Interruptable, multi-turn conversations
  • Support for help and cancel
  • FAQ
  • Chit-chat conversations
  • Routing user input to appropriate dialog
  • Handling no-match
  • Prompting users for information
  • Implementing a custom prompt
  • Multi-turn conversations using dialogs
  • Implementing custom dialog solution
  • Managing user and conversation state

Services and tools demonstrated

  • Using LUIS for Natural Language Processing
  • Using QnA Maker for FAQ, chit-chat, getting help and other single-turn conversations
  • Using BotBuilder CLI tools to create, configure and manage all required services.

Scenarios covered via other samples

To try this sample

Testing the bot using Bot Framework Emulator v4

Microsoft Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.

  • Install the Bot Framework emulator from here

Connect to bot using Bot Framework Emulator v4

  • Launch Bot Framework Emulator
  • File -> Open Bot Configuration and navigate to samples/javascript_nodejs/51.cafe-bot/
  • Select contoso-cafe-bot.bot

Prerequisites

Install CLI tools

Ensure you have Node.js version 8.5 or higher

  • In a terminal
    npm i -g msbot chatdown ludown luis-apis qnamaker

Configure required services using MSBOT

  1. Follow instructions here to create an Azure account. If you already have an account, sign in. Click on all services -> search for 'subscriptions' -> copy the subscription ID you would like to use from the Home > Subscriptions page.
  2. Follow instructions here to create a LUIS.ai account. If you already have an account, sign in. Click on your name on top right corner of the screen -> settings and grab your authoring key.
  3. To create and configure required LUIS and QnA Maker services,
    • In a terminal,
      cd samples/javascript_nodejs/51.cafe-bot
    • Run MSbot Clone and pass in your LUIS authoring key and Azure subscription ID. This command will create required services for your bot and update the .bot file.
      msbot clone services -n <YOUR-BOT-NAME> -f deploymentScripts/msbotClone -l <Bot service location> --luisAuthoringKey <Key from step-2 above> --subscriptionId <Key from step-1 above> --noDecorate --appId <YOUR APP ID> --appSecret <YOUR APP SECRET PASSWORD>

NOTE: You can obtain your appId and appSecret at the Microsoft's Application Registration Portal

Optionally, you can use the LUIS, QnA Maker portals to manually import the models found under cognitiveModels folder of this sample.

Relevant commands for CLI tools

Building and creating services

  • Parse .lu files into LUIS models
    > ludown parse toluis --in dialogs/dispatcher/resources/cafeDispatchModel.lu -o cognitiveModels -n cafeDispatchModel.luis --verbose
    > ludown parse toluis --in dialogs/bookTable/resources/turn-N.lu -o cognitiveModels -n cafeBotBookTableTurnN.luis --verbose
    > ludown parse toluis --in dialogs/whoAreYou/resources/getUserProfile.lu -o cognitiveModels -n getUserProfile.luis --verbose
  • Parse .lu files into QnA Maker KB and QnA Maker alterations file
    > ludown parse toqna --in dialogs/dispatcher/resources/cafeFAQ_ChitChat.lu -o cognitiveModels -n cafeFaqChitChat.qna -a --verbose
  • Import LUIS applications and update the .bot file with LUIS service references:
    • Follow instructions here to create a LUIS.ai account. If you already have an account, sign in. Click on your name on top right corner of the screen -> settings and grab your authoring key.
    • LUIS-AUTHORING-REGION can be one of [westus|westeurope|australiaeast]. See here for more information.
    > luis import application --in cognitiveModels/cafeDispatchModel.luis --authoringKey <Your LUIS authoring key> --region <LUIS-AUTHORING-REGION> --msbot | msbot connect luis --stdin
    > luis import application --in cognitiveModels/cafeBotBookTableTurnN.luis --authoringKey <Your LUIS authoring key> --region <LUIS-AUTHORING-REGION> --msbot | msbot connect luis --stdin
    > luis import application --in cognitiveModels/getUserProfile.luis --authoringKey <Your LUIS authoring key> --region <LUIS-AUTHORING-REGION> --msbot | msbot connect luis --stdin
  • Import QnA Maker KBs (Note: You don't need this if you have already run MSBOT clone)
    • Follow instructions here to create a QnA Maker subscription and copy your QnA Maker subscription key.
    > qnamaker create kb --in cognitiveModels/cafeFaqChitChat.qna --subscriptionKey <Your QnA Maker subscription key> --msbot | msbot connect qna --stdin
  • Train LUIS model
    > msbot get cafeDispatchModel | luis train version --wait --stdin
    > msbot get cafeBotBookTableTurnN | luis train version --wait --stdin
    > msbot get getUserProfile | luis train version --wait --stdin
  • Publish LUIS models
    > msbot get cafeDispatchModel | luis publish version --stdin
    > msbot get cafeBotBookTableTurnN | luis publish version --stdin
    > msbot get getUserProfile | luis publish version --stdin
  • Train and publish QnA Maker KB
    > msbot get cafeFaqChitChat | qnamaker publish kb --stdin
  • Replace QnA Maker alterations
    > msbot get cafeFaqChitChat | qnamaker replace alterations --in cognitiveModels/cafeFaqChitChat.qna_Alterations.json --stdin

Making updates to the models

Any time you change .lu files, you can update and publish the LUIS and QnA Maker models using the following commands. You can also script and automate the CLI tools to match your development workflow. See here for an example.

  • Parse .lu files into LUIS models
    > ludown parse toluis --in dialogs/dispatcher/resources/cafeDispatchModel.lu -o cognitiveModels -n cafeDispatchModel.luis --verbose
    > ludown parse toluis --in dialogs/bookTable/resources/turn-N.lu -o cognitiveModels -n cafeBotBookTableTurnN.luis --verbose
    > ludown parse toluis --in dialogs/whoAreYou/resources/getUserProfile.lu -o cognitiveModels -n getUserProfile.luis --verbose
  • Parse .lu files into QnA Maker KB and QnA Maker alterations file
    > ludown parse toqna --in dialogs/dispatcher/resources/cafeFAQ_ChitChat.lu -o cognitiveModels -n cafeFaqChitChat.qna -a --verbose
  • Rename current LUIS version
    > msbot get cafeDispatchModel --secret <Key if your bot file is encrypted> | luis rename version --newVersionId 0.1_old --stdin
  • Import a LUIS new application version
    > msbot get cafeDispatchModel --secret <Key if your bot file is encrypted> | luis import version --stdin --in cognitiveModels/cafeDispatchModel.luis
  • Deleting old LUIS application version
    > msbot get cafeDispatchModel --secret <Key if your bot file is encrypted> | luis delete version --stdin --versionId 0.1_old
  • Training a LUIS model
    > msbot get cafeDispatchModel --secret <Key if your bot file is encrypted> | luis train version --wait --stdin
  • Publishing a LUIS model
    > msbot get cafeDispatchModel --secret <Key if your bot file is encrypted> | luis publish version --stdin

Updating and publishing QnA Maker KB

  • Replace KB contents
    > msbot get cafeFaqChitChat --secret <Key if your bot file is encrypted> | qnamaker replace kb --in cognitiveModels/cafeFaqChitChat.qna --stdin
  • Train and publish KB
    > msbot get cafeFaqChitChat --secret <Key if your bot file is encrypted> | qnamaker publish kb --stdin
  • Replace QnA Maker alterations
    > msbot get cafeFaqChitChat --secret <Key if your bot file is encrypted> | qnamaker replace alterations --in cognitiveModels/cafeFaqChitChat.qna_Alterations.json --stdin