Introduction
In this article, we will be learning how to create or build an intelligent Azure Bot using Microsoft QnA Maker and Azure Bot service. Also, we will be deploying this Bot to the application live.
For novice cloud developers, aspiring cloud architects, pre-sales consultants, and all other IT professionals associated with the cloud computing, especially with Microsoft Azure and Artificial Intelligence, this article will explain the capabilities of Microsoft Bot service and Microsoft cognitive QnA Maker.
Pre-requisite
Overview
Earlier in this year January, I had an article on Creating FAQ Bot with BOT Framework's QnA Maker (it also got featured ๐) and was going through the same. But noticed much change, though small but really smart changes. I wanted to write this article as a continuation of the earlier article but when I tried it out, it was really cool and much easier to build intelligent bot with quick time using QnA Maker and Azure Bot service.
QnA Maker
When it comes to FAQ Bot, an important member of the Cognitive family is QnA Maker. It basically creates a database or in QnA term, a Knowledgebase with given set of FAQ data.
Now, this data could be in the form of existing Live, accessible to public web page URL. Or could be in the form of a document with data in question and answers format. This document can be either FAQ pages in .tsv, .pdf, .doc, .docx and .xlsx format or product manuals in .pdf format. You can upload up to five files, with a size limit of 5 MB each. Also, you can manually enter a question and answer into QnA maker web portal.
Would recommend reading Creating FAQ Bot with BOT Framework's QnA Maker article for better understanding of its functional working.
Azure Bot Service
This offering is an intelligent bot service which scales on demand. It comes with a pricing option of ‘pay for only use’. It offers an ability for our bot to get connected with multiple channels like Skype, Skype for business, Cortona, Bing, Telegram, Facebook Messenger, and many others.
Building C# Corner FAQ Bot
For practical understanding, let’s build up a C# Corner FAQ bot using QnA Maker and Azure bot service.
Open QnA Maker web portal => Sign up the portal with valid Email ID.
Click on link, ‘Create new service’.
The section would allow us to add a content source to seed the data into our bot knowledgebase.
- Service Name – Name the service. This would-be reference name of our C# Corner FAQ knowledge base. Let give it as csharpcornerfaq.
- URL as Source - Here we need to provide URL(s) of the FAQ pages or product manuals that we want data or content to be extracted from for using in our bot.
For our Bot, it’s of C# Corner FAQ page: http://www.c-sharpcorner.com/faq, Copy FAQ webpage URL.
Once the inputs are provided, it would look like,
We can add multiple URLs by clicking on link ‘+ Add another ‘
- File as Source - We can upload files containing our questions and answers. We can upload up to five files with a size limit of each less than 5 MB.
For our bot, we will upload word file name, csharpcorner-bot.docx, containing five questions and answer. Refer below image for sample.
Once the inputs are provided, it would look like,
We can add multiple files by clicking on button ‘Select file.. ‘
And last source option is to add manually.
Once done with adding URLs, and uploading files,
Click on Create.
Once the service is created, we will redirect to Knowledgebase page. Here we can see and verify all the Question and Answers extracted from different sources provided.
- Editorial Source: Greet message with Input questions as ‘Hi’ and response as ‘Hello’ is added by default. We can change any message of our choice with multiple input question responding with the same response.
For this bot, we added two new questions as Input with custom Greet message as a response.
- From URL as Source,
And from Files as source,
We can test our knowledgebase by clicking "Test" section.
Here, we can add, modify the Input questions and answers by rephrasing the same questions in different forms.
These are the most important Buttons or Links in the entire Data seeding exercise.
- Save and retrain - After adding data to the knowledge base, or updating any single data in the knowledgebase and before Publishing our knowledge base, Hitting Save and retrain makes sure to have the recent most Data saved & Trained in our knowledge base. It acts like commit changes kind of behavior.
- Publish – Once the data is saved & retrained, and our knowledge base is ready to go live, hitting Publish would publish our knowledge base and generates an endpoint to be used by Bot service, other bot Frameworks or through any application.
After clicking on Publish, it navigates to Review page,
Click on Publish again once reviewed.
This will take fewer seconds for publishing our knowledge base & creating an endpoint.
After publishing it provides with sample Http request.
Also, you can again click on Edit service for massaging your knowledge base.
Azure Bot Service
Now we have our csharpcornerfaq bot knowledge base ready. What’s Next!
To use this knowledgebase, we have Azure Bot service.
Open Microsoft Azure Porta.
Click on ‘+ New‘ => AI + Cognitive Services => Bot Service
Note
At the time of writing this article, both QnA Maker and Bot Service are in the preview.
Enter all the required details for creating Bot service,
- App Name
- This will be our Bot name.
- Response to Chat with the user would be by this name.
- For our Bot, we named it as ‘csharpcornerbot’
- Subscription
- Microsoft Azure Subscription
- You can very well try this out with Free trial subscription also
- Resource Group
- Bot service is part of Azure resources. It has to be grouped with Resource group, a logical clubbing of all Azure resources associated with a product.
- You can select from existing resource group or create a new resource group.
- For our Bot, I have selected from existing resource group.
- Hosting Plan
- App Service Plan - Configure app service plan from a range of pricing tier available along with the location. Free Tier is also available in pricing options.
- Consumption Plan – Pay as you go option is available as Hosting plan.
- For our Bot, I have selected App Service Plan with Free Tier and Central US as location.
Once done with providing all details, Pin it to Dashboard!
- Click on Create.
Service will take fewer minutes to get deployed & we will be landed at below Bot service page.
Here, we need to select programming language from the available option, C# and Node.js. Also, need to select chat bot template among five templates.
- Basic – It’s a template for bot with single dialog that echoes back the user input
- Form – It’s a template for bot that shows how to collect input from a user using a guided conversation using
- Language Understanding – It’s a template for a bot that shows how to handle natural language using the Cognitive Services LUIS API.
- Question and Answer – It’s a template for the bot that transforms information into conversational, easy-to-navigate answers.
- Proactive – It’s a template for a bot that shows how to use Azure Functions to trigger events in Azure bots.
As our bot is of Question and Answer pattern, we will be selecting, C# as language and Question and Answer as our bot template.
Click on Next to proceed.
Create a Microsoft App ID
Now in order to authenticate our bot with the Bot Framework, will need to register our application and generate an App ID and password.
This involves two steps,
- To Register our bot with Microsoft to generate a new App ID and Password.
- Click on button ‘Create Microsoft App ID and Password’.
- This will open up new window, just follow the instructions.
- Click on ‘Generate an app password to continue’ button to create password.
- And to enter this newly created App ID and Password, along with agreeing to given Terms & policies.
- Copy above generated App ID and Password and enter the same.
Note
Before Accepting the terms, policies do read it carefully.
Click on Create bot
Once authenticated and registered, bot service needs the knowledge base to converse with outer world.
As we have selected Question and Answer Template, next it opens up QnA Maker dialogue window.
Here, we need to select our Csharpcornerfaq as knowledgebase.
Click OK
Next, the bot will get provisioned and it may take fewer minutes.
Status messages can be seen
And finally, our Bot service with csharpcornerfaq knowledge base is ready to use!
Under Build section, you have different options to modify or work on your code.
- Online Code Editor – Clicking on this option, will open up new window with App code editor. Under highlighted sections, we have our code with C# as language.
- The second option is for downloading the source code and open it with Visual Studio.
- And third option comes with having our code into repositories like VSTS or GitHub for enabling Continuous Integration.
Testing our Bot
We can test our Bot right from Azure Portal, i.e. under Test section in Bot service.
Connect to Channel
We can connect our bot with different channels like Cortona, Facebook Messenger, Telegram, Skype for Business and all other listed in below image.
We can see that by default, it's seen running for Skype and Web Chat.
Let’s use this Web Chat into application and deploy the same on Cloud, to experience it live!
Click on pen icon, to configure Web Chat.
Configure Web Chat
- Click on Show, to copy Secret Key.
- Copy the embed code. And enter the secret key in source URL.
- Embed code: <iframe src='https://webchat.botframework.com/embed/csharpcornerbot?s=YOUR_SECRET_HERE'></iframe>
After configuring Web Chat, use this embed code in to our application.
Here I have created a small project with HTML file name c-sharpcorner-faq-bot.html
We will be using Web Chat embed code in to this HTML file.
This application is uploaded to Azure web app with
URL
http://faqbots.azurewebsites.net/c-sharpcorner-faq-bot.html, and it looks like,
Now, our C# Corner FAQ bot is Live on Cloud!
Let’s ask few questions.
Interesting isn’t it?
Also, you can create this entire bot right from scratch in less than 15 minutes!
I know you will not believe in what I say until you yourself see it happening. Have created a video following above steps for creating C# Corner FAQ Bot.
Watch How to build C# Corner FAQ Bot using QnA maker and Azure Bot service in less than 15 minutes!
Summary
Microsoft is really working hard to help us to build super intelligent & Smart bots. QnA Maker and Azure Bot service are among wide AI & Cognitive offerings to achieve a scalable, on demand, profitable, of course, an intelligent product.
Would highly recommend to learn, dive into this article and try to create a bot for your organization or personal blog or product.
Do let me know your findings of it.
Happy Azure Coding! Thank You!