|
| 1 | +# NLP with Dispatch |
| 2 | + |
| 3 | +Bot Framework v4 NLP with Dispatch bot sample |
| 4 | + |
| 5 | +This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to create a bot that relies on multiple [LUIS.ai](https://www.luis.ai) and [QnAMaker.ai](https://www.qnamaker.ai) models for natural language processing (NLP). |
| 6 | + |
| 7 | +Use the Dispatch model in cases when: |
| 8 | + |
| 9 | +- Your bot consists of multiple language modules (LUIS + QnA) and you need assistance in routing user's utterances to these modules in order to integrate the different modules into your bot. |
| 10 | +- Evaluate quality of intents classification of a single LUIS model. |
| 11 | +- Create a text classification model from text files. |
| 12 | + |
| 13 | +This sample is a Spring Boot app and uses the Azure CLI and azure-webapp Maven plugin to deploy to Azure. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- Java 1.8+ |
| 18 | +- Install [Maven](https://maven.apache.org/) |
| 19 | +- An account on [Azure](https://azure.microsoft.com) if you want to deploy to Azure. |
| 20 | + |
| 21 | +### Use Dispatch with Multiple LUIS and QnA Models |
| 22 | + |
| 23 | +To learn how to configure Dispatch with multiple LUIS models and QnA Maker services, refer to the steps found [here](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-tutorial-dispatch?view=azure-bot-service-4.0). |
| 24 | + |
| 25 | + |
| 26 | +## To try this sample locally |
| 27 | +- From the root of this project folder: |
| 28 | + - Build the sample using `mvn package` |
| 29 | + - Run it by using `java -jar .\target\nlp-with-dispatch-sample.jar` |
| 30 | + |
| 31 | +- Test the bot using Bot Framework Emulator |
| 32 | + |
| 33 | + [Bot Framework Emulator](https://github.com/microsoft/botframework-emulator) is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel. |
| 34 | + |
| 35 | + - Install the Bot Framework Emulator version 4.3.0 or greater from [here](https://github.com/Microsoft/BotFramework-Emulator/releases) |
| 36 | + |
| 37 | + - Connect to the bot using Bot Framework Emulator |
| 38 | + |
| 39 | + - Launch Bot Framework Emulator |
| 40 | + - File -> Open Bot |
| 41 | + - Enter a Bot URL of `http://localhost:3978/api/messages` |
| 42 | + |
| 43 | +## Deploy the bot to Azure |
| 44 | + |
| 45 | +As described on [Deploy your bot](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-deploy-az-cli), you will perform the first 4 steps to setup the Azure app, then deploy the code using the azure-webapp Maven plugin. |
| 46 | + |
| 47 | +### 1. Login to Azure |
| 48 | +From a command (or PowerShell) prompt in the root of the bot folder, execute: |
| 49 | +`az login` |
| 50 | + |
| 51 | +### 2. Set the subscription |
| 52 | +`az account set --subscription "<azure-subscription>"` |
| 53 | + |
| 54 | +If you aren't sure which subscription to use for deploying the bot, you can view the list of subscriptions for your account by using `az account list` command. |
| 55 | + |
| 56 | +### 3. Create an App registration |
| 57 | +`az ad app create --display-name "<botname>" --password "<appsecret>" --available-to-other-tenants` |
| 58 | + |
| 59 | +Replace `<botname>` and `<appsecret>` with your own values. |
| 60 | + |
| 61 | +`<botname>` is the unique name of your bot. |
| 62 | +`<appsecret>` is a minimum 16 character password for your bot. |
| 63 | + |
| 64 | +Record the `appid` from the returned JSON |
| 65 | + |
| 66 | +### 4. Create the Azure resources |
| 67 | +Replace the values for `<appid>`, `<appsecret>`, `<botname>`, and `<groupname>` in the following commands: |
| 68 | + |
| 69 | +#### To a new Resource Group |
| 70 | +`az deployment sub create --name "echoBotDeploy" --location "westus" --template-file ".\deploymentTemplates\template-with-new-rg.json" --parameters appId="<appid>" appSecret="<appsecret>" botId="<botname>" botSku=S1 newAppServicePlanName="echoBotPlan" newWebAppName="echoBot" groupLocation="westus" newAppServicePlanLocation="westus"` |
| 71 | + |
| 72 | +#### To an existing Resource Group |
| 73 | +`az deployment group create --resource-group "<groupname>" --template-file ".\deploymentTemplates\template-with-preexisting-rg.json" --parameters appId="<appid>" appSecret="<appsecret>" botId="<botname>" newWebAppName="echoBot" newAppServicePlanName="echoBotPlan" appServicePlanLocation="westus" --name "echoBot"` |
| 74 | + |
| 75 | +### 5. Update app id and password |
| 76 | +In src/main/resources/application.properties update |
| 77 | + - `MicrosoftAppPassword` with the botsecret value |
| 78 | + - `MicrosoftAppId` with the appid from the first step |
| 79 | + |
| 80 | +### 6. Deploy the code |
| 81 | +- Execute `mvn clean package` |
| 82 | +- Execute `mvn azure-webapp:deploy -Dgroupname="<groupname>" -Dbotname="<botname>"` |
| 83 | + |
| 84 | +If the deployment is successful, you will be able to test it via "Test in Web Chat" from the Azure Portal using the "Bot Channel Registration" for the bot. |
| 85 | + |
| 86 | +After the bot is deployed, you only need to execute #6 if you make changes to the bot. |
| 87 | + |
| 88 | + |
| 89 | +## Further reading |
| 90 | + |
| 91 | +- [Bot Framework Documentation](https://docs.botframework.com) |
| 92 | +- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0) |
| 93 | +- [Using LUIS for Language Understanding](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-luis?view=azure-bot-service-4.0&tabs=js) |
| 94 | +- [LUIS documentation](https://docs.microsoft.com/en-us/azure/cognitive-services/LUIS/) |
| 95 | +- [Activity processing](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0) |
| 96 | +- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0) |
| 97 | +- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0) |
| 98 | +- [.NET Core CLI tools](https://docs.microsoft.com/en-us/dotnet/core/tools/?tabs=netcore2x) |
| 99 | +- [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest) |
| 100 | +- [Azure Portal](https://portal.azure.com) |
| 101 | +- [Language Understanding using LUIS](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/) |
| 102 | +- [Channels and Bot Connector Service](https://docs.microsoft.com/en-us/azure/bot-service/bot-concepts?view=azure-bot-service-4.0) |
| 103 | + |
0 commit comments