|
| 1 | +# Custom Dialogs |
| 2 | + |
| 3 | +Bot Framework v4 custom dialogs bot sample |
| 4 | + |
| 5 | +This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to sub-class the `Dialog` class to create different bot control mechanism like simple slot filling. |
| 6 | + |
| 7 | +BotFramework provides a built-in base class called `Dialog`. By subclassing `Dialog`, developers can create new ways to define and control dialog flows used by the bot. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- Java 1.8+ |
| 12 | +- Install [Maven](https://maven.apache.org/) |
| 13 | +- An account on [Azure](https://azure.microsoft.com) if you want to deploy to Azure. |
| 14 | + |
| 15 | +## To try this sample |
| 16 | +- From the root of this project folder: |
| 17 | + - Build the sample using `mvn package` |
| 18 | + - Run it by using `java -jar .\target\bot-customdialogs-sample.jar` |
| 19 | + |
| 20 | +## Testing the bot using Bot Framework Emulator |
| 21 | + |
| 22 | + [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. |
| 23 | + |
| 24 | + - Install the latest Bot Framework Emulator from [here](https://github.com/Microsoft/BotFramework-Emulator/releases) |
| 25 | + |
| 26 | +### Connect to the bot using Bot Framework Emulator |
| 27 | + |
| 28 | + - Launch Bot Framework Emulator |
| 29 | + - File -> Open Bot |
| 30 | + - Enter a Bot URL of `http://localhost:3978/api/messages` |
| 31 | + |
| 32 | +## Interacting with the bot |
| 33 | + |
| 34 | +BotFramework provides a built-in base class called `Dialog`. By subclassing Dialog, developers |
| 35 | +can create new ways to define and control dialog flows used by the bot. By adhering to the |
| 36 | +features of this class, developers will create custom dialogs that can be used side-by-side |
| 37 | +with other dialog types, as well as built-in or custom prompts. |
| 38 | + |
| 39 | +This example demonstrates a custom Dialog class called `SlotFillingDialog`, which takes a |
| 40 | +series of "slots" which define a value the bot needs to collect from the user, as well |
| 41 | +as the prompt it should use. The bot will iterate through all of the slots until they are |
| 42 | +all full, at which point the dialog completes. |
| 43 | + |
| 44 | +## Deploy the bot to Azure |
| 45 | + |
| 46 | +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. |
| 47 | + |
| 48 | +### 1. Login to Azure |
| 49 | +From a command (or PowerShell) prompt in the root of the bot folder, execute: |
| 50 | +`az login` |
| 51 | + |
| 52 | +### 2. Set the subscription |
| 53 | +`az account set --subscription "<azure-subscription>"` |
| 54 | + |
| 55 | +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. |
| 56 | + |
| 57 | +### 3. Create an App registration |
| 58 | +`az ad app create --display-name "<botname>" --password "<appsecret>" --available-to-other-tenants` |
| 59 | + |
| 60 | +Replace `<botname>` and `<appsecret>` with your own values. |
| 61 | + |
| 62 | +`<botname>` is the unique name of your bot. |
| 63 | +`<appsecret>` is a minimum 16 character password for your bot. |
| 64 | + |
| 65 | +Record the `appid` from the returned JSON |
| 66 | + |
| 67 | +### 4. Create the Azure resources |
| 68 | +Replace the values for `<appid>`, `<appsecret>`, `<botname>`, and `<groupname>` in the following commands: |
| 69 | + |
| 70 | +#### To a new Resource Group |
| 71 | +`az deployment sub create --name "multiTurnPromptBotDeploy" --location "westus" --template-file ".\deploymentTemplates\template-with-new-rg.json" --parameters appId="<appid>" appSecret="<appsecret>" botId="<botname>" botSku=S1 newAppServicePlanName="multiTurnPromptBotPlan" newWebAppName="multiTurnPromptBot" groupLocation="westus" newAppServicePlanLocation="westus"` |
| 72 | + |
| 73 | +#### To an existing Resource Group |
| 74 | +`az deployment group create --resource-group "<groupname>" --template-file ".\deploymentTemplates\template-with-preexisting-rg.json" --parameters appId="<appid>" appSecret="<appsecret>" botId="<botname>" newWebAppName="multiTurnPromptBot" newAppServicePlanName="multiTurnPromptBotPlan" appServicePlanLocation="westus" --name "multiTurnPromptBot"` |
| 75 | + |
| 76 | +### 5. Update app id and password |
| 77 | +In src/main/resources/application.properties update |
| 78 | + - `MicrosoftAppPassword` with the botsecret value |
| 79 | + - `MicrosoftAppId` with the appid from the first step |
| 80 | + |
| 81 | +### 6. Deploy the code |
| 82 | +- Execute `mvn clean package` |
| 83 | +- Execute `mvn azure-webapp:deploy -Dgroupname="<groupname>" -Dbotname="<botname>"` |
| 84 | + |
| 85 | +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. |
| 86 | + |
| 87 | +After the bot is deployed, you only need to execute #6 if you make changes to the bot. |
| 88 | + |
| 89 | + |
| 90 | +## Further reading |
| 91 | + |
| 92 | +- [Bot Framework Documentation](https://docs.botframework.com) |
| 93 | +- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0) |
| 94 | +- [Dialogs](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-dialog?view=azure-bot-service-4.0) |
| 95 | +- [Dialog class reference](https://docs.microsoft.com/en-us/javascript/api/botbuilder-dialogs/dialog) |
| 96 | +- [Manage complex conversation flows with dialogs](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-dialog-manage-complex-conversation-flow?view=azure-bot-service-4.0) |
| 97 | +- [Activity processing](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0) |
| 98 | +- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0) |
| 99 | +- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0) |
| 100 | +- [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest) |
| 101 | +- [Azure Portal](https://portal.azure.com) |
| 102 | +- [Channels and Bot Connector Service](https://docs.microsoft.com/en-us/azure/bot-service/bot-concepts?view=azure-bot-service-4.0) |
0 commit comments