Building A Chatbot Using Azure Bot Services

Before reading this article, please go through the article given below to get some knowledge about Microsoft Azure.

But in this article, we are going to discuss the following things.

  • What is bot framework?
  • Creating a bot from Azure Management Portal.
  • Setting up LUIS for getting information.
  • Connecting Bot with Slack API.
Requirements
  • Slack Account
  • Azure Account
  • LUIS Account 

What is bot framework?

At Build 2016, Microsoft released bot framework to develop intelligent applications. In modern application development, there are a lot of services available as communication channels such as Skype, Facebook Messenger, Telegram and other such applications. For example, Discuss is a service company,which provides comment plugins for the developers to add on the Websites or on their blogs.

During the release, I thought how Microsoft bot Framework Service will work. Now, I realize that bot framework has many advantages. Services may communicate with each other without knowing their states or API or an event without knowing the destination. In the Windows 10 Operating System, Cortana is the best feature (from my point of view) and Skype with Cortana integration plays a major role in gathering information such as news, weather, tips and tricks etc.

Here, we are using communication channels such as Email, GroupMe, Skype, and Slack as an infrastructure for developing real-time Applications.

The examples for real-time applications are given below.

  • Hotel Booking System
  • Online food booking system
  • Taxi booking system
  • Online FaQ reader

Some of the applications with large data centers are Facebook, Twitter, Mail services etc.

Following are some of the benefits of bots.

  • Connecting with cross-platform Services.
  • Your customer is your business.
  • Go Server-less.
To build bot applications, we can use .NET SDK and Node.js SDK. These SDKs provide features for building the applications with dialogues and built-in prompts that make an application more interactive. These applications are very easy to use and interactive with real-time applications. REST API is used rather than .NET SDK and Node.js SDK by the users who are developing the applications.

 

 

Each and every bot provides some sense. This may be incorporated with LUIS for Natural Language understanding. For more information regarding bot intelligence, click here.

Best example for bot Service is Uber.

Why are they using bot Service?

To enhance security, Uber uses bot Service. Uber uses bot Service to deliver a Real-Time ID Check. The drivers need to authenticate their individuality, using selfies before they are able to agree to take the rides.

Creating a bot from Azure Management Portal

The steps given below are required to create a bot, using Azure Management Portal.

Login into Azure Management Portal to create a bot service using Azure Management Portal.

From Azure Management Portal, click New and then Intelligence + analytics. Subsequently, click Bot Service (Preview).

 

In bot creation, the wizard fills out the mandatory fields such as an app name, resource group and location.

 

App Name – Name of your bot Service. Make sure that it is a valid app name to create a bot Service in Azure and it should be your app URL to access it in a Web Browser.

Resource group - Configuring an app Service plan to deploy an Application.  

Once bot Service creation is successful, you will land on the page which is given below.

In order to work with a bot, we need to register an application with app ID and password. To register bot Service, click “Create Microsoft App ID and Password”. Now, you will be landed in the Application registration portal. Now, you will be able to find an app name and app ID. To generate a password, click “Generate an app password to continue”. Before clicking my opinion, copy and paste an app Id in Notepad because it is used in future. Now, a popup appears in it, copy app password and paste it in Notepad. Subsequently, click OK and subsequently click Finish. Go back to bot Service framework.

 
 
 

In bot Service page, paste app Id and app password, which is already copied from the application registration portal. If successful, choose language as Node.js.

  
It is mandatory to select bot Service Application template. In it, select the template as per your needs. Here, we are going to select “language understanding” and click Create bot to create a bot Service in Azure.

Finally, Language Understanding Pop-up appears, followed by reading the instruction and click OK.

 

Note

In order to connect and work with LUIS, we need to do the following two things

  • Create a blank LUIS app.
  • Use your key to connect your bot application.

It may take a bit to create a bot Service in Azure Management Portal. Hence, don’t go anywhere. Stick to the Azure Portal. Once the provision completes, you will land on the page given below.

  

 

In bot Service Window, you will be able to find chat Window, which is cascaded at the right side. By using it, one sends a message to bot Service and finally, you get a response for the bot. Here, our bot application is working but it does not send any useful information which is needed by the users.

 

To configure the message, we need to follow the steps given below. Subsequently, login into LUIS (Language Understanding Intelligent Service), using your valid Microsoft account. Now, you will be able to find your applications in the application lists.

 
Now, click on your application and start configuring  to retrieve the best results. In LUIS API Application Window, click on Intents option, which is present on the left side on the Window. In Add, a new intent wizard; provide the credentials like intent name and example of an intent command and click save.

 
 
 

Add New Utterances by searching them and saving in the created intents. Once saving completes, you get a message that New Utterances Updated successfully.

Now, create new entities by providing an entity name and click save. Now, create an intent and click save button, as shown below. Now, add new utterances, select city name and mark it as city and save it in weather intent and click save button.

 

Now, we are able to see Add Entities under Entities area. 
 
 
 
 
 
Everything was done. Click publish button, as shown below. Now, click Train option, which is available under the LUIS Application Window. Once training completes, you will be able to find Publish button, as shown below.

 
 
 

Now, you will be able to find HTTP Service pop-up. In this click Update and publish the application to start publishing the changes.

 

Once changes are published, query the LUIS Application by using saved utterances and click enter, as shown below and the output given below confirms that our application starts working as expected.

 
 Test Output

 
It’s the time to make changes in our created Azure bot Application. Hence, add the code given below under Main Dialog with LUIS and make the changes, as shown below.

 

  1. .matches('Greetings', (session, args) => {  session.send('You option is for greetings' +JSON.stringify(args));    
  2. })
  3. .matches('Weather', (session, args) => {  session.send('You option is for weather' +JSON.stringify(args));    
  4. })  

If the changes are complete, save the changes and query the message, using cascaded chat Window.

Output

Query hai

 

Output

Q
uery Current weather in Salem

 

Output

Query Current weather in Namakkal

 

Connecting bot with slack

Now, click on the channels option, which is made available in bot application. Scroll down, find Slack and click on it to start configuring bot with Slack.

 

To configure bot with Slack, we need a Slack account. If you don’t have a Slack account, create a new one or else sign in with your existing account.

 
 
 
 
 

Now, you will land in the apps Window, as shown below. From it, click create an app. Now, create an app wizard appears. Provide an app name, development team and click create button.

 
 
 
Now, click on OAuth&permission option and add the redirected URL given below and click save button. Redirect URL must be https://slack.botframework.com and click save button.

 

Now, elect ‘Bot Users’ tab and add a bot to your app. You will find the default username and click Add bot to add the user to your bot Application.

 
 
 

Now, add the Interactive messages option and enable interactive messages. Now, add the Request URL as https://slack.botframework.com/api/Actions and click Enable interactive messages.



Now, click on Basic information and copy client ID, client secret key and verification token and paste in the Slack configuration page, as shown below. Once done, click Submit Slack Credentials, as shown below.

 
 

If your Slack account has multiple teams, select an appropriate team in which you need to configure bot. Now, click authorize button to complete this process.

 
Again, you will be navigated to Slack configuration page. In it, enable this bot on the Slack option and then click I’m done configuring Slack.

 

Note

Subsequently, you will be able to find the message, as the credentials are validated.

To check whether the bot is working correctly, now open up Slack and log in to your Slack team, where you will be able to find your bot Service, which is configured.

 

Congrats. Now, our bot Application is working on the slack account.

Output

Query
hai 

 
 
Output

Query
current weather in salem 
 
 

Summary

In this article, we discussed creating a simple bot and connecting bot applications with slack. I hope, you enjoyed reading this article. Thanks for reading.

Happy coding.


Similar Articles