Create, deploy, and embed the Azure bot
Written by Medina Dacić, Software Developer Softray Solutions
These days, we can see a lot of chatbots around us. So, what is a chatbot?
At the most basic level, a chatbot is a computer program that simulates and processes human conversation (either written or spoken), allowing humans to interact with digital devices as if they were communicating with a real person.
Every interaction between the user (or a channel) and the bot is represented as an activity. In a conversation, people often speak one at a time, taking turns speaking. It’s the same with the bot and user. A turn consists of the user’s incoming activity to the bot and any action the bot sends back to the user as an immediate response.
Interactions between users and chatbots involve exchanging activities, which are handled in turn.
There are many different types of chatbots out there. Let’s split them into 3 main types:
A) FAQ chatbots
B) Transactional chatbots
C) Virtual assistants
FAQ (frequently asked questions) chatbots are bots designed to answer common questions people usually ask about a company’s products or services. Usually, FAQ chatbots are used on websites, e-commerce stores, or customer service apps. They help the user quickly find an answer without reading through knowledge-based articles and searching your site.
Transactional chatbots can help customers self-serve with answers to FAQs and retrieve information such as the status of a package or update a record in a system such as a user delivery address. Again, organizations are automating this capability rather than taking up limited resources and chasing down answers so customers can self-serve.
Virtual assistants chatbots can understand user’s questions, no matter how they’re phrased. With AI and natural language understanding (NLU) capabilities, the bot can quickly detect all relevant contextual information shared by the user, allowing the conversation to progress more smoothly and conversationally.
So lets start playing with Azure chatbots!
1. Create a bot
There are a different ways of creating a bot. Lets show you few of them.
a) Create an Echo bot with SDK
Bot Framework SDK offers a few bot templates, such as Echo, Core and Empty bot. More templates are available on this GitHub page. Echo Bot is a simple chatbot that returns back everything the user entered in the chat.
Prerequisites:
Create new project in Visual studio, and select Echo Bot project.
Bot Framework Emulator is a desktop application that allows bot developers to test and debug bots, either locally or remotely. Using the Emulator, you can chat with your bot and inspect the messages that your bot sends and receives. The Emulator displays messages as they would appear in a web chat UI and logs JSON requests and responses as you exchange messages with your bot.
Open the Emulator. Click on File -> Open Bot. In Bot URL fill the endpoint of your chatbot and add suffix /api/messages, which should be: http://localhost:3978/api/messages.
Once you run it, you can start adding additional features to the app using SDK, such as Dialogs (prompting), interactive cards, speech and other.
b) Create a FAQ bot with Azure cognitive services
First create a Language service in Azure. Navigate to that Language resource and open Features. In features check the checkbox, and create a new service for Azure Cognitive Search service:
Login with Azure credentials in Azure Language studio https://language.cognitive.azure.com/home, select tab Understand questions and conversational language, and then choose Custom question answering.
Create a simple excel file, with a few questions and answers, like on the image:
Click Add source -> Files, and then upload the excel file that you created. After you’re done, you should be able to see generated Knowledge base (KB), and click on it:
You will see on the left side different options such as editing and deploying KB. In the center you will see question-answer objects. You can add a new one, or edit an existing one. While editing you can add prompts (which are actually suggestions, shown like button to the user). You can also test your KB.
Once you’re done with setting up a KB. Click on Deploy knowledge base, and deploy it. If you click on Create a bot button, it will create all needed infrastructure for you and also setup the configuration per service as needed.
c) Create transactional bot with Bot Framework Composer
Prerequisites:
Bot Framework Composer, built on the Bot Framework SDK, is an open-source IDE for developers to author, test, provision, and manage conversational experiences. From Composer, you can test your bot and publish it to Azure. Composer supports features that let you extend your bots with code for more complex tasks, such as system integration.
Once you download Composer, run the app and choose one of its templates, for example, Empty Bot.
Create your own trigger by clicking on Add new trigger:
Once you created trigger, you can click on “plus” sign and create a lot of different things, such as asking a question, sending dialogs and answers, hitting API, using if/else conditioning, and so on…
- Language Understanding (LUIS) is an Azure Cognitive Service that uses machine learning to understand natural language input and direct the conversation flow.
You will need to setup also LUIS in Configure tab simply by creating new LUIS service. And the bot should work!
2. Deploy a bot to Azure
I’m going to show deployment process for the Echo bot. Azure Services that you’re going to need are App Service (also creating new App Service plan with it), and Azure Bot.
a) Deploy bot code to the Azure App Service
We’re gonna show two ways of deploying bot code to the Azure App Service.
1st approach: Publish directly from Visual Studio. Right-click on the project, and click on Publish.
Choose Azure -> Azure App service -> Log in Azure -> you will see your services, choose the app service you want -> Publish.
Once you did this process you will generate Deploy.pubxml file, so next time you can just hit the Publish button.
This approach is fine, but you’re not using versioning control. If you want to have a versioning control or continuous deployment use second approach.
2nd approach: Published my app to Github, then connected App service with that repository on Github, and enabled continuous deployment.
In GitHub actions we can check deployments:
b) Connect App Service with Azure Bot
In Azure Bot Service navigate to Configuration, and enter the url of app service, and add sufix /api/messages:
Save somewhere the Microsoft App ID. Click on Manage password. Create a new password. You will be able to copy the VALUE just upon the creation (if you leave the page, you will not be able anymore to copy it). In the Bot code fill these values in appsettings.json file. But in appsettings.development.json make them empty, because the emulator will fail with 401 errors. Deploy your bot code one more time.
If you did everything properly, you should be able to run your bot in Test in Web Chat:
3. Embed a bot
First we’re gonna embed it directly in web app. You should use this approach if it’s for testing, development. If it’s production, then we would have to gather a token with a secret key, and then get embedded code with that token.
In Azure Bot service, click on Channels -> Web Chat:
Then click on Default Site. In the HTML page, copy embedded code, and replace YOUR_SECRET_HERE with real secret key, and that’s it!
You can use it in other channels such as Slack, Alexa, Facebook, Teams, and similar. For embedding in a Teams, just click on Teams in Channels, and create one. And then open it via Teams:
Summary:
The purpose of this blog is to show you some basics regarding the chatbots.
After following this blog, you should be able to create a bot in a few different ways, deploy your infrastructure in Azure, and embed your bot within your app or any other channel such as Teams.