Deploy Bot Composer to Azure

Chatbots have been a major hype in the IT industry for some time now. One of the major players in the enterprise spectrum is Microsoft with the Microsoft Bot Framework suite. In the last year the MBF low-code, open-source, platform has grow quite impressively. Microsoft Bot Framework Composer, or just Composer for character saving (Amazonia ain't gonna save itself) is a very robust platform for chatbot development.

This article is part of a Microsoft Bot Framework dedicated series, where we will look at the advantages of using Microsoft Chatbot solution, and how can we overcome the current pitfalls in the tool. The main goal is to reach a broader audience, but we will cover some deep topics that may require some IT/development knowledge, but don't stop now, we will tackle it together. 

So, we got our chatbot up and running in our local machine, together with an Azure Cognitive Service running our language understanding service (LUIS). You can check the first article regarding how to set-up Microsoft Bot Composer and create a chatbot. Now we will deploy it to Azure by creating the necessary infrastructure and configuring the Microsoft Bot Composer parameters for a seemless deployment!

There are several ways to create the infrastructure in Azure, from ARM templates to portal or third party automations, in this article we will look at Microsoft Bot Composer included script (ARM based), and the Azure Marketplace template (Web App Bot).

As usual, you can access the example code at my github page.

 

Azure Setup

First and most important thing, having an Azure subscription up and running. After that we will create a Resource Group specific for our deployment, in this case it should be 2 resource groups, but the script deployment method already provide us with Resource Group provisioning. In the end we will compare the generated resources and check for differences, if there are any.

So, in the end we will have this two resources which I'll use for our example:

  • dev-rg-pokebot-arm-dev: For script (arm) deployment;
  • dev-rg-pokebot-portal: For portal (web app bot) deployment;

Azure Deployment v1: Microsoft Bot Composer Script

The Microsoft Bot Composer team ships a nodeJS based deployment script that is generated when a new chatbot project is created within the Composer tool. The script is generated at the .\scripts\ folder. 

Since the script is generated within MBC tool, the respective updates may bring new script versions in the future, so ensure you have the last Composer version before using the scripts.

This is an approach that can be easly automated, however we will run it in our local machine for testing. This scenario is clearly easier for the typical developer role, if you don't have the necessary experience to run this scripts, the Portal version detailed below will also work for you, proving to be much easier from the low code perspective. But since there is no gain without loss, you can also have much more control by running the scripts and editing the parameters available. 

Microsoft Bot Composer makes available a Readme file within the chatbot project, you can also take a look at it for more information. One of those informations are the pre-requisites to run the script, that we will also address now.

 

Pre-Requisites

Since we well run the scripts on the local machine we need to make sure everything is ready to do so. Let's take a look at the list:

  • You need an Azure Subscription;
  • You need a project created within Microsoft Bot Framework;
  • You need to install the latest version of Azure CLI - Microsoft Docs;
  • You need to install NodeJS 12.13.0 version or later - Node.JS;
  • You need PowerShell version 6.0 or later;

Plentyful requirements, the easier thing to do is to follow up the links provided above to install each requirement.

 

Running the Scripts

Now what you have everything ready, let's start by openning the terminal in the scripts folder of out bot project:

 

First thing to do is to install the Node modules necessary to run the script, with the command:

npm install

In the next step we will generate the resources in Azure, to do so, we will need some parameters:

  • Azure Subscription ID;
  • The resource name to be deployed;
  • A password to be used in the Application Service, this password must have at least 16 characters with at least one number, one letter, and one special character;
  • The environment that will be set-up, in this case we will use dev.

The command to deploy the infrastrucure is defined as:

node provisionComposer.js `
--subscriptionId=<YOUR AZURE SUBSCRIPTION ID> `
--name=<NAME OF YOUR RESOURCE GROUP> `
--appPassword=<APP PASSWORD> `
--environment=<NAME FOR ENVIRONMENT DEFAULT to dev>

However, if you run the command like it is describe, you will deploy all the required and optional resources. To show you so, I did it and the result was the following:

 

The result in Azure is the following:

 

As you can see, there are a lot of resources that are not required for the chatbot, also we have the deployment made in West US per default.

For a more "lean" approach we will deploy the following command:

node provisionComposer.js `
--subscriptionId=##################### `
--name='dev-rg-pokebot-arm' `
--appPassword='###############' `
--environment='dev' `
--location='westeurope' `
--createQnAResource=false `
--createCosmosDb=false `
--createStorage=false

If you notice, we have a duplicated 'dev' in the resource provision name, you can change this by providing a name for the resource group in the command ('--resourceGroup=XXXX').

We end up with this resources in Azure:

Note: At the time of this article's writting, there's a typo in the script's Readme file, using the value provided "createCosmosDB" that won't prevent the CosmosDB resource to be created, you need to use the value "createCosmosDb".

Edit: Regarding the previous note: The issue regarding CosmosDB was a bad label on the Bot Composer documentation, already fixed.

Important: You should save the JSON output received in the CLI in a secure location, those keys will be important in the bot publish step.

 

Azure Deployment v2: Azure Portal - Web App Bot

For users that aren't so used to NPM, CLI, etc. this is a much easier way to achieve the same goal.

Before we start we need to create a Resource Group to host our resources, let's call it dev-rg-pokebot-portal.

Now we will create the Azure services that can support our bot, we are focusing LUIS here, but we will create the entire bot resources necessary to deploy the chatbot later on.

Go to Azure Portal and start by searching Cognitive Services in the search bar.

Afterwards just press the New button and you should see the available options:

 

Select the Web App Bot create option, afterwards fill the requested options:
- Bot handle: The name for your bot;
- Subscription: Your azure subscription;
- Resource Group: The resource group for the bot resources, advise to create a new one to segregate usage;
- Location: Location for the services hosting;
- Pricing Tier: The Bot Service messaging tier, just go with F0 (free) for the exercice;
- App name: The application endpoint name;
- Bot Template: Set it up with Basic Bot, so we have integrated creation of LUIS resources;
- LUIS App Location: Location for the LUIS (Cognitive Service) resource;
- LUIS Accounts: You can reuse an existing account since they use internal app ids for the trainings, however it is recommended to create a new one within the new resource group;
- App Service Plan: The application service tier, the default is S1, you can modify later on, however we are using F0;
- Application Insights: This helps you centralize the bot analytics so keep it on;
- Application Insights Location: Location for Application Insights hosting;
- Microsoft App ID and password: Leave it default for auto creation;

It should look something like this:

 

After everyting is filled just proceed with create.

Warning: I encountered an error/bug while creating the resource, the message was that the subscription didn't have Microsoft.BotService registered, solved by unregistering and registering the service again. If you are presented with the same error, check out Kóderé Bashir's article here, life saving.

After the resource is created, your resource group should have the following services:

 

Congratulations, you have just deployed the necessary resources to run your Chatbot in the Cloud.

Should we proceed to deploying our chatbot to the newly created infrastructure?

 

Deploy the Chatbot to Azure Resources

We have our infrastructure in Azure ready, so it's about time we send our bot to Azure right?

Let's start by openning the Bot Composer tool, and check the LUIS endpoint configuration. If you need to reconfigure it, the first Bot Composer tutorial explains in detail how you can access the authoring keys.

So go up to the Publish option in the left menu, and look at the Manage profiles option.

After that you will be redirected to the Project Settings area, where you can create a new Publishing Profile, let's call it dev-azure-deployment, and set it to Azure App Service mode, after that click Next: Configure resources.

In the next step we need to fill up the JSON file with all the necessary information regarding our deployment, if the deployment was done with the scripts, it's a simple copy-paste task, if the resources were created in Azure Portal, you may need to fetch some of the keys and IDs if not saved during the process:

{
"name": "dev-rg-pokebot-arm",
"environment": "dev",
"hostname": "dev-rg-pokebot-arm-dev",
"luisResource": "dev-rg-pokebot-arm-dev-luis",
"runtimeIdentifier": "win-x64",
"resourceGroup": "dev-rg-pokebot-arm-dev",
"botName": "dev-rg-pokebot-arm",
"subscriptionId": "#################",
"region": "westeurope",
"settings": {
"applicationInsights": {
"InstrumentationKey": "#################"
},
"luis": {
"endpointKey": "#################",
"authoringKey": "#################",
"region": "westeurope",
"endpoint": "https://westeurope.api.cognitive.microsoft.com/",
"authoringEndpoint": "https://westeurope.api.cognitive.microsoft.com/"
},
"MicrosoftAppId": "#################",
"MicrosoftAppPassword": "#################"
}
}

In this case we didn't add the storage, QnA and CosmosDB components. Then we go back to the Publish page, select the new profile and bot, and press Publish Selected Bots.

You will also need to provide a "comment message" for the deploy, and log-in in your Azure account to authenticate before running the deployment.

If everything went fine, you should be presented with a success message:

 

Then, you can go the Azure Bot Service resource and use the Test Webchat to test the newly deployed chatbot:

With this we deployed our chatbot, fully developed in Microsoft Bot Services, and fully hosted in Azure.

 

Conclusion

We looked at how can we deploy the necessary infrastructure in Azure, both through the Azure Portal, and the Microsoft Bot Framework scripts. 

I can say honestly that neither one is a best approach right now, Azure Portal template has a lot of missing resources, and the provided scripts still have a few minor bugs and feature needs to be a standard adopted solution. However, it should be easier to take the scripts and build a custom module with some specific deployment necessities.

If you already have a templating solution for Azure Resources, or even use ARM, the best case scenario at the moment would be for you to build your own templates for Chatbot infrastructure deployment to Azure based on your own needs.

Taking into account the "low-code" side of Microsoft Bot Composer, clearly it's not user-friendly ready to be set-up, developed and deployed by a low-code developer. Nevertheless Microsoft Bot Composer is evolving each day, and what is true today, maybe be false tomorrow. 

Microsoft Bot Composer is a great breakthrough to low-code developers, regarding chatbot development when compared to Microsoft Bot Framework SDK. And I hope the surrounding ecosystem can also take the leap.

This was the second step, in the following article we will look at how can we manage a chatbot lifecycle within Azure with the help of Azure DevOps so stay tunned!

Thank you for reading, and if you want to support the page or just give feedback share it on your social media by tagging me @filipelteixeira.

Bye!

Filipe Teixeira

Filipe Teixeira

Hello, I'm a CS Engineer with 8 years of experience and a passion for technology. Currently I work for Datadog as a Software Engineer.
Any opinions expressed are solely my own and do not express the views or opinions of any employer at the particular time.

Comments (0)

wave

Leave Comment

wave

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

Press ESC to close