Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Building a Chatbot Using Azure Bot Services

DZone's Guide to

Building a Chatbot Using Azure Bot Services

In this thorough tutorial, learn how to develop a chatbot on Azure Bot Services and integrate your bot application with the Slack API.

· AI Zone ·
Free Resource

Insight for I&O leaders on deploying AIOps platforms to enhance performance monitoring today. Read the Guide.

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

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

  • What Bot Framework is.
  • Creating a bot from Azure Management Portal.
  • Setting up LUIS for getting information.
  • Connecting your bot with the Slack API.

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, and Telegram. For example, Discuss is a service company that provides comment plugins for developers to add websites to their blogs.

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 the Skype/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 infrastructure for developing real-time applications.

Examples of real-time applications include:

  • Hotel booking system
  • Online food booking system
  • Taxi booking system
  • Online FAQ reader

Some of the applications with large data centers are Facebook, Twitter, and mail services.

Following are some of the benefits of bots:

  • Connecting with cross-platform services.
  • Your customer is your business.
  • Go serverless.

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.

The best example for a bot service is Uber.

Why Are They Using Bot Service?

To enhance security, Uber uses Bot Service to deliver a real-time ID check. 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.

Log into Azure Management Portal, click New, and then click 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: The name of your bot service. Make sure that it is a valid app name — 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 the bot service creation is successful, you will land on the below page.

In order to work with a bot, we need to register an application with app ID and password. To register your bot service, click Create Microsoft App ID and Password. You will land in the application registration portal and 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 will be used in future. Now, a popup appears; copy the app password and paste it in the Notepad. Subsequently, click OK > Finish. Then, go back to the Bot Service framework.

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

It is mandatory to select your 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, a language understanding pop-up appears, followed by reading the instructions. Click OK.

In order to connect and work with LUIS, you need to create a blank LUIS app and use your key to connect your bot application.

It may take a bit to create a Bot Service in Azure Management Portal. Don't go anywhere. Stick to the Azure Portal. Once the provision completes, you will land on the page below.

In the Bot Service window, you will be able to find the chat window, which is cascaded on the right side. By using it, one sends a message to the 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 that the users need.

To configure the message, we need to follow the steps given below. Log into LUIS 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 the LUIS API application window, click Intents and provide the credentials like intent name and an example of an intent command and click Save.

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

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

Now, we are able to see entities under the Entities area.

Everything is done. Click the Publish button, as shown below. Now, click Trainunder the LUIS application window. Once training completes, you will be able to find the Publish button, as shown below.

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

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

Test output:

It's the time to make changes in our created Azure bot application. Add the code given below under Main Dialog with LUIS and make the changes below.


If the changes are complete, save the changes and query the message using the cascading chat window.

Connecting Bot With Slack

Now, click on the Channels option, scroll down, find Slack, and click on it to start configuring your bot with Slack.

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

Now, you will land in the Your Apps window, as shown below. From it, click Create an app. Now, create an app wizard appears. Provide an app name and development team, and click Create.

Now, click on OAuth & Permissions, add the redirected URL (https://slack.botframework.com) given below, and click Save.

Select the 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, select 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.

If your Slack account has multiple teams, select the appropriate team you're configuring the bot for. Click Authorize to complete this process.

Again, you will be navigated to the Slack configuration page. Enable this bot on the Slack option and then click I'm done configuring Slack.

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

Congrats! Your bot application is working on the Slack account.

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.

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

Topics:
azure ,bot development ,azure bot service ,chatbot ,ai ,tutorial ,slack ,microsoft bot framework ,sdk

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}