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.
You can check the first article regarding how to set-up Microsoft Bot Composer and create a chatbot, or check all the Microsoft Bot Composer articles here. After looking at the Bot Composer tool, and setting up our Azure infrastructure and cloud deployment, we will look into what should be an enterprise level chatbot lifecycle.
Enterprise Application lifecycle management has been a challenge since the first web application, with the increase of Agile processes and DevOps architectures, we have more sofisticated tools and ecosystems to manage application developement and deployment cycles. But with better resources, the users expectations have increased as well. We can no longer have the luxury of building application based on a manual deployment process.
Currently, Bot Composer doesn't provide a CI/CD feature integrated within the tool, therefor we need to evaluate our options regarding the necessary aditional tools to provide this service. In this article we will look into how to deploy a Microsoft Bot Composer chatbot project with the help of GitHub as a source control platform, and Azure DevOps for our Azure deployment process.
TLDR: We will build a CI/CD pipeline based on GitHub and Azure DevOps Pipelines with YAML definitions. As usual, you can access the example code at my github page.
Challenge: Architecture
We can start by taking a look into the Azure Architecture that support the chatbot deployment:
In Azure we have 3 main resources that support our chatbot:
- Azure Bot Services: Global service that provide channel integration for the chatbot service;
- Azure App Service: Application service that runs our chatbot implementation, in the Bot Composer case the system runs a standard implementation that reads the artifacts generated by the Composer (flows, replies, etc.);
- Azure Cognitive Services - LUIS: Cloud service that provides the NLP features to our chatbot, this is where the model training is made.
To ensure the chatbot deployment we need to upgrade the Azure App Service with the .NET runtime and Bot Composer artifacts, and we need to update the training model in LUIS. This will be our main goal.
Challenge: DevOps
So we discussed what needs to be done, let's see how will we do it.
We will develop our chatbot flows, replies and trainings with the Microsoft Bot Framework Composer tool. Has we seen in the first article, we can test the chatbot locally with Bot Framework Emulator.
After we have confidence in our chatbot developments, we need to push the project to a Source Control platform, in this case we will use GitHub. The project with the necessary artifacts is available in this GitHub repository.
When the Chatbot project is in the Source Control, Azure DevOps pipeline will be in charge of taking the artifacts produced by Bot Composer, set-up the .NET runtime and deploy it to the Azure App Service, as well as take the LUIS training models and push it into the Azure Cognitive Service. All this deployment is made in a specific resource group, so it is possible to extend the application to support multiple triggers and environment deployments, however the goal of this article is to show you how can Azure DevOps complete such task.
An Azure DevOps execution for the GitHub repository shared before is available in this Azure DevOps project.
Walkthrough
In this section we will look into the Pipeline definition and the steps necessary to build and deploy the application.
Reviewing the requirements to copy this solutions:
- Microsoft Bot Composer project in a compatible source control with Azure DevOps (Azure DevOps Repositories, GitHub, Bitbucket, etc.);
- Azure deployed infrastructure (in this case we will use the infrastructure created with the Microsoft Bot Composer Deployment Scripts - you can review the tutorial on the deployment section here);
- Azure Keyvault to store the keys for the DevOps pipeline:
- Microsoft App Id;
- Microsoft App Password;
- LUIS Authoring Key;
- LUIS Prediction Key;
- Service Principle configured in Azure DevOps Service Connections with RBAC permissions for the resource group and with access policy defined in the Azure Keyvault;
As we can see in the project repo, we have a pipeline.yml and a folder named pipelines (both not native in the MBF Composer project). The pipeline.yml has the template invocation with the necessary parameters, the file has the following content:
In this file, the values for the pipeline are detailed. You can set these parameters as variables in the DevOps pipeline execution, but let's leave it here for easier reading. Regarding the values:
- resourceGroupName: The resource group name where the resources are;
- appServiceResourceName: The App Service name where the bot will be deployed;
- luisResourceName: The LUIS prediction resource name;
- resourceGroupServiceConnection: The Azure DevOps Service Connection name configured for accessing the Azure Resource Group;
- keyVaultName: The keyvault name where the secrets for pipeline support are stored;
- microsoftAppIdSecretName: The name for the Microsoft App Id secret value in the keyvault;
- microsoftAppPasswordSecretName: The name for the Microsoft App Password secret value in the keyvault;
- luisAuthoringKeySecretName: The name for the LUIS Authoring Key secret value in the keyvault;
- luisEndpointKeySecretName: The name for the LUIS Prediction Key secret value in the keyvault;
For the detailed values above, the Azure Keyvault should have the following data:
Now let's take a look into the pipelines folder, where the template called before is detailed. In the pipelines\pipeline.yml file we have the execution of four main steps:
- Template writeAppSettings.yml: In this step the Azure Keyvault is accessed using the Resource Service Connection, and the values are temporarly written in the appsettings.json file of the project;
- Template publishAndConfigureLuis.yml: In this step the LUIS models are build and registered using the bf-cli;
- Template prepareBotDefaultRuntime.yml: In this step the last version of the bot runtime is downloaded from the Bot Framework Composer GitHub repo and the project artifacts are injected (copied into the folder structure);
- Template buildAndDeployAppService.yml: The last step is to take the runtime with the artifacts, build and publish it into the App Service running on Azure;
A pipeline execution example can be found here.
Conclusion
First of all, I would like to give a huge thanks to Rui Félix Pereira from Microsoft for helping to set up these scripts and allow me to share them with the community.
Although Microsoft Bot Composer still lacks in giving GUI configurations to enable a full collaborative CI/CD model, we can overcome that challenge with the usage of the Azure DevOps tool. However, there is still some challenges regarding this question:
- Capability of "power" users to use GIT based tools;
- The merge process can be a problem since all the artifacts are based on descriptive/configuration models;
- This solution still have some drawbacks regarding Cloud-to-local LUIS models sync;
- The scripts still require some fine tunning to be used within your organization (triggers, environments, etc.);
- Still lacking QnA deployment capabilities.
In the end we proved the concept and provide the necessary artifacts for teams to start provisioning their CI/CD models.
The last article permise still holds: "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."
You can access the example code at my GitHub, and the pipeline execution at my Azure DevOps organization.
As always, 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!