Create a bot with Azure

APPLIES TO: Composer v2.x

This article shows how to create a bot using the Azure Bot resource.

Note

The nightly builds include pre-release features and may change how some operations are performed. The Composer documentation supports the latest stable release of Composer, and some aspects of the nightly builds may not work as described in the documentation. For more information about nightly builds, see Application settings.

Prerequisites

Create an Azure Bot resource

The Azure Bot resource provides the infrastructure that allows a bot to access secured resources. It also allows the user to communicate with the bot via several channels such as Web Chat.

  1. Go to the Azure portal.

  2. In the right pane, select Create a resource.

  3. In the search box enter bot, then press Enter.

  4. Select the Azure Bot card.

    Select Azure bot resource

  5. Select Create.

    Create Azure bot resource

  6. Enter the required values.

    Create Azure bot resource values

  7. Select Review + create.

  8. If the validation passes, select Create. You should see the Azure Bot and the related key vault resources listed in the resource group you selected.

  9. Select Open in Composer.

    Open bot in Composer

The Composer application opens. It the application isn't installed, you'll be asked to install it before you can proceed with the next steps.

  1. In the pop-up window, select Create a new bot.

    Create bot in Composer

  2. Select Open.

Azure Key Vault

When Azure creates the Azure Bot resource, it also generates an app ID and an app password and stores the password in Azure Key Vault.

Key Vault is a service that provides centralized secrets management, with full control over access policies and audit history. For more information, see Use Key Vault references for App Service and Azure Functions. You're charged a small fee for using the service. For more information, see Key Vault pricing.

Create a bot

Create a bot by following the steps described below.

Create a bot from a template

  1. Open Composer.
  2. Select Create New (+) on the homepage.
  3. Composer shows a list of templates. The templates provide a starting point for your new bot. For the purposes of this quick-start, select the Empty bot template under the C# section. This template creates a bot containing a root dialog, initial greeting dialog, and an unknown intent handler. Then select Next.
  4. Fill in the Name for the bot as Menu_bot. Then select Azure Web App from the Runtime type, and a location for your bot on your machine.
  5. Select OK. It will take a few moments for Composer to create your bot from the template.

Add bot functionality

The bot created from the Empty bot template contains an unknown intent trigger. This acts as a fallback whenever your bot doesn't know how to respond. When your bot doesn't recognize the intent of user input, it will send a response letting the user know.

This section describes how to add basic bot functionality to your empty bot template. You'll add:

  • A dialog called Menu that displays a text message with menu items.
  • A trigger for the Menu dialog. This makes it possible for your bot to recognize the intent, and connects the menu dialog above.

Add a dialog

Now you can add functionality for intents that you want your bot to recognize.

Dialogs are a convenient way to organize conversational logic. This section shows you how to add a dialog. In the next section, you add a trigger to the bot's main dialog to call the new dialog.

  1. Click the three dots next to your bot project, Menu_bot, and select + Add a dialog.

  2. In the Name field, enter Menu, and in the Description field, enter A dialog that shows the menu.. Then select OK.

  3. Select BeginDialog underneath the Menu dialog.

  4. In the authoring canvas, select the + button under BeginDialog. Then select Send a response.

  5. Enter the following menu text in the response editor on the right.

    Today's menu
     - Pizza
     - Burger and fries
     - Chicken sandwich
    

Your authoring canvas should look like the following.

Menu text response

Create a trigger to recognize the menu intent

Now that your dialog is ready to send a response of menu options, you need to create a trigger so that your bot recognizes when users want the menu item displayed.

  1. Select your bot project, Menu_bot.

  2. On the right, select the Regular expression recognizer for the Recognizer type. This recognizer provides a simple example without adding natural language understanding. For a real-world bot, explore language understanding.

  3. Now, add a trigger to the Menu_bot dialog.

    1. The default trigger type is Intent recognized.
    2. Enter Menu in the What is the name of this trigger (RegEx) field.
    3. Enter menu in the Please input regEx pattern field.
    4. Select Submit. This creates a trigger, named Menu, which will fire when the user sends a menu message to the bot.
  4. Now you need to start the Menu dialog you created previously from the trigger. Select the + under the Menu trigger on the authoring canvas. Go to Dialog management and select Begin a new dialog.

  5. Go to the right and select the box underneath Dialog name. You should see the Menu dialog you created previously; select it. Your authoring canvas should look like the following.

    Begin a new dialog - menu

Your menu bot is now ready to test!

Next steps