Azure Bot Framework: A Step-by-Step Guide to Creating and Deploying a Bot

Author

Reads 244

View from swirling fast wave of powerful transparent blue ocean in tropical country
Credit: pexels.com, View from swirling fast wave of powerful transparent blue ocean in tropical country

Creating a bot with Azure Bot Framework is a straightforward process. You can start by choosing a programming language and SDK, such as C# or Node.js, and then create a new bot service in the Azure portal.

The Azure portal provides a user-friendly interface to manage your bot's settings, including its name, description, and endpoint URL. You can also configure your bot's messaging endpoint and add any necessary credentials.

To deploy your bot, you'll need to package it as a ZIP file and upload it to Azure. This can be done using the Azure CLI or the Azure portal.

Prerequisites

To get started with the Azure Bot Framework, you'll need to meet some prerequisites.

First and foremost, you'll need an Azure account with an active subscription. If you don't have one, you can create a free account.

You'll also need to install the Azure CLI, which is the command-line interface for Azure. The version of the CLI you need depends on your programming language. For C# and JavaScript, you'll need version 2.39.0 or later. For Python, you'll need version 2.55.0 or later. And for Java, you'll need version 2.29.2.

If you're a Java developer, you'll also need to install Maven, which is a tool for managing dependencies in your project.

Finally, if your bot uses additional resources like a storage service or language services, you'll need to deploy them separately.

Planning and Deployment

Credit: youtube.com, Bot & Bot Framework SDK with Azure Bot Service Part 1

Planning and deployment are crucial steps in setting up your Azure Bot Framework. You can manage your bot's identity in Azure using a user-assigned managed identity, a single-tenant app registration, or a multi-tenant app registration.

To plan your deployment, consider how you'll manage the identities of your bot resources in Azure. You can use a user-assigned managed identity, which doesn't require you to manage the bot's credentials yourself, or a single-tenant app, which is supported in the C#, JavaScript, and Python SDKs. Alternatively, you can use a multi-tenant app, which is supported in all Bot Framework SDK languages.

For resource groups, it's recommended to use one until you're familiar with the process. You can deploy multiple Python bots to the same resource group, but keep in mind that you can't deploy a Python bot to a resource group that contains Windows services or bots.

Plan Your Deployment

You'll want to decide how to manage the identities of your bot resources in Azure.

Credit: youtube.com, Deployment Plan Intro sample

You can use a user-assigned managed identity, a single-tenant app registration, or a multi-tenant app registration. For more information, see Create an identity resource.

It's recommended to use one resource group until you're familiar with the process. For more information, see Manage Azure resources.

You'll also need to decide whether your bot will be regional or global. For information about regional bots, see Regionalization in Azure AI Bot Service.

Your bot identity can be managed in Azure in a few different ways. You can use a user-assigned managed identity, a single-tenant app, or a multi-tenant app.

The user-assigned managed identity and single-tenant app types are supported in the Bot Framework SDK for C#, JavaScript, and Python. However, these app types aren't supported in the other languages or in Bot Framework Composer, Bot Framework Emulator, or Dev Tunnels.

Here's a breakdown of the app types and their support:

Python bots can't be deployed to a resource group that contains Windows services or bots. However, multiple Python bots can be deployed to the same resource group.

Prepare Project Files

Credit: youtube.com, How to Write a Project Plan [PROJECT PLANNING STEPS THAT WORK]

Before you deploy your bot, you need to prepare your project files. This involves a few key steps that vary depending on the language or runtime of your bot.

For C# bots, switch to your project's root folder, do a clean rebuild in release mode, and run az bot prepare-deploy to add required files. This command generates a .deployment file in your bot project folder.

You'll also need to create a zip file containing all files and subfolders in your project's root folder.

For Node.js bots, switch to your project's root folder and run npm install. Then, run az bot prepare-deploy to add required files, which generates a web.config file in your project folder.

Azure App Services requires this file for Node.js bots. You'll also need to create a zip file containing all files and subfolders in your project's root folder.

Python bots don't require dependency installation on your local machine. However, you'll still need to list your dependencies in a requirements.txt file for the ARM templates.

Credit: youtube.com, 5 Essential Project Documents [YOU NEED THESE]

Here are the steps to prepare your project files for different languages:

Remember to include your built code with all necessary dependencies in the zip file being deployed, as Kudu assumes deployments are ready to run without extra build steps.

Azure Resources

To deploy your Azure Bot, you'll need to create the necessary Azure resources. This includes an Azure subscription, one or more resource groups, a user-assigned managed identity or an Microsoft Entra ID app registration, an App Service Plan resource, an App Service resource, and an Azure Bot resource.

You can use an existing resource or create a new one for some of these steps. It's a good idea to decide on the names of the new resources ahead of time to keep things organized.

Here are the types of resources your bot will use:

  • The Azure subscription that you'll use to provision, publish, and manage the bot
  • One or more resource groups
  • A user-assigned managed identity or an Microsoft Entra ID app registration
  • An App Service Plan resource
  • An App Service resource
  • An Azure Bot resource

Create Resources with ARM

To create resources with ARM templates, you'll need to use the az deployment group create Azure CLI command. This command is used to create the App Service and Azure Bot resources for your bot.

Credit: youtube.com, Creating Azure Resources like a Pro using ARM Templates

You can create an App Service resource for your bot within a new or existing App Service Plan. For detailed steps, see Use Azure CLI to create an App Service.

Creating an Azure Bot resource for your bot is a separate step that also uses an ARM template. For detailed steps, see Use Azure CLI to create or update an Azure Bot.

You can create these resources in either order, but if you create your Azure Bot first, you'll need to update its messaging endpoint after you create your App Service resource.

Here's a summary of the resources you'll need to create:

  • App Service resource
  • Azure Bot resource
  • App Service Plan resource (optional)

Kudu Files

Kudu is used by the web app deployment command to deploy C#, JavaScript, and Python bots.

To ensure successful deployment, include your built code with all necessary dependencies in the zip file being deployed.

The default behavior of Kudu assumes deployments from .zip files are ready to run and don't require extra build steps during deployment, such as npm install or dotnet restore/dotnet publish.

Credit: youtube.com, Azure App Service Advanced Tools a.k.a. Kudu

This means your bot won't work as intended if you don't include all necessary dependencies in the zip file.

To avoid this, include all files and subfolders in the zip file, just like in the example for C# bots: "Within your project's root folder, create a zip file that contains all files and subfolders."

Here are some key options to keep in mind when using the az bot prepare-deploy command:

For Python bots, dependency installation is performed on the server, so be sure to include your dependencies in a requirements.txt file.

Identity and Security

If you're building a bot on Azure Bot Framework, you'll need to add identity information to your bot's configuration file. This file differs depending on the programming language you use to create the bot.

For C#, JavaScript, and Python bots, the file is called appsettings.json, .env, or config.py respectively, and supports all three application types for managing your bot's identity.

Credit: youtube.com, Microsoft Bot Framework Web Chat Authentication for Single Tenant Bots C# | Azure Bot Entra ID Auth

The Java version of the Bot Framework SDK only supports multi-tenant bots, and its configuration file is called application.properties.

To add identity information, you'll need to provide the following values in your configuration file.

Here are the properties you'll need to add, depending on your bot's application type:

For single-tenant bots, you'll need to add the following properties:

For multi-tenant bots, you'll need to add the following properties:

These properties will help you manage your bot's identity and ensure secure communication with the Azure Bot Service.

Bot Creation

You can create an App Service and Azure Bot resources for your bot using an ARM template and the Azure CLI command. ARM templates are a great way to create resources in a structured and repeatable way.

To create an App Service resource, you can use the Azure CLI command to create a new App Service within a new or existing App Service Plan. You can find the detailed steps to do this in the article section on "Use Azure CLI to create an App Service".

Credit: youtube.com, Azure Bot Service Tutorial | Create Chatbots in minutes

Alternatively, you can create an Azure Bot resource first, but you'll need to update its messaging endpoint after creating your App Service resource. This is a good option if you want to create your bot resources in a specific order.

Here are the steps to create a bot using Visual Studio and the Azure Bot Framework:

  1. Create a new bot project using the Echo Bot template in Visual Studio.
  2. Use the default values when prompted by Yeoman to create your bot.
  3. From your working directory, run the command to download the echo bot template and its dependencies.

Customize the Dialog

The CampusQnADialog in SampleSkillBot starts with a welcome section that lists content categories. You can write the code for the dialog in the project created from a Bot Framework template or customize the code in SampleSkillBot.

Upon selection of a content category, the bot shows a list of questions related to a category. This is achieved by looping back to the categories after each answer.

The bot fetches the answer from the QnA Maker resource upon selection of a question. You can modify the code to connect to different skills, end the chat, add/remove categories/questions, and modify the QnA Maker resource.

Credit: youtube.com, Microsoft Bot Framework: Form Dialog

To test the bot in the emulator, you need to pass its Microsoft App Id and Microsoft App Password to the emulator and then click Connect. Note that the Microsoft App Id and Microsoft App Password are found in the appsettings.json.

You can design the End of conversation as shown below. If the visitor selects "No" to "Do you want to ask more questions?", the bot answers "Conversation End. Thank you!"

The ActivityRouterDialog.cs contains the code that enables bot visitors to select activities such as booking a flight and getting campus information.

Frequently Asked Questions

What is the difference between Azure bot and bot framework?

Azure Bot Service is a cloud platform for developing and deploying bots, whereas the Microsoft Bot Framework is a set of tools for building and connecting intelligent bots. In essence, Azure Bot Service is the platform, while Bot Framework is the toolkit that helps you build and integrate bots.

What is the bot framework?

The Bot Framework is a development platform for building conversational AI bots, allowing developers to create and test bots using a cross-platform SDK. It enables bot developers to test and debug their bots locally or remotely.

What is Microsoft Azure bot service?

Microsoft Azure Bot Service is a platform for building conversational AI bots, offering a low-code development environment for developers of all skill levels. It integrates with Microsoft Copilot Studio to simplify bot creation and deployment.

Walter Brekke

Lead Writer

Walter Brekke is a seasoned writer with a passion for creating informative and engaging content. With a strong background in technology, Walter has established himself as a go-to expert in the field of cloud storage and collaboration. His articles have been widely read and respected, providing valuable insights and solutions to readers.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.