Home > Technology peripherals > AI > Step-by-step instructions on how to create a chatbot using Azure Bot Services

Step-by-step instructions on how to create a chatbot using Azure Bot Services

王林
Release: 2023-04-11 18:34:04
forward
1848 people have browsed it

Translator | Li Rui​

Reviewer | Sun Shujuan​

Messengers, network services and other software are inseparable from robots (bots). In software development and applications, a bot is an application designed to automatically perform (or perform according to a preset script) actions created in response to user requests. In this article, Daniil Mikhov, developer at NIX United, presents an example of creating a chatbot using Microsoft Azure Bot Services. This article will be helpful to developers who want to develop chatbots using this service. Why use Azure Bot Services? ​

The advantage of developing chatbots on Azure Bot Services is Microsoft’s high level of support for its products. The company's experts actively communicate with the technical community and quickly identify and fix vulnerabilities in the service. Additionally, Microsoft provides the ability to create custom JSON files to work with some of Messenger’s APIs, giving developers a lot of possibilities when creating chatbots.

It’s also important to remember the other benefits of Azure Bot Services:

Azure Bot Services allows Developers use open source SDK tools (software development kits) to create, test and deploy chatbots.

  • #Integration with cognitive services refers to services that use machine learning tools at work to solve typical tasks. Cognitive services ensure a better interaction process between the chatbot and the user.
  • Multi-platform refers to the ability to connect a chatbot to multiple channels without changing the original code.
  • Plenty of open source examples to facilitate the development process and get started quickly (there are many ready-made code examples on GitHub).
  • Developers can extend the chatbot infrastructure on the Azure platform by adding new features. For example, you can add more channels and use each channel for testing. The Cosmos DB service can be used to store conversation state and user-entered information. To train your chatbot, you can add language understanding (LUIS). It uses machine learning algorithms to better communicate with users. However, LUIS is not free, and not every client wants to allocate additional funds.

Analysis of Chatbot in Azure Bot Services​

The functional structure of a chatbot created on Azure can be expressed as:

You can see a list of possible channels connected to the chatbot on the right. This list will be continuously updated with new platforms. At the bottom of it are Microsoft Cognitive Services available on the Azure platform. These services allow communication with chatbots through voice requests, facial expressions, gestures, and more. Step-by-step instructions on how to create a chatbot using Azure Bot Services

Bot Builder SDK is used to develop chatbots on Azure. The product is in the public domain and its main advantage is ongoing support from developers. In a separate fork on GitHub, you can get the latest information about the service, or ask its developers questions.

Create Chatbot​

Before writing the code, analyze the nuances that you should consider before creating a chatbot on Azure Bot Service :

  • Updates that break functionality. Microsoft Corporation is constantly updating its products. New updates often break parts of code that worked before. So be sure to understand the patch list for new Bot Builder SDK versions, and other manuals used to develop chatbots may become irrelevant.
  • Not an obvious solution. When using the Bot Builder SDK, you should always be open to experimentation and willing to do things differently than you are used to.
  • Versatility. The same chatbot can be uploaded to different channels (Telegram, Skype, Slack, etc.) without changing the source code. You should keep in mind when developing chatbots that each platform has nuances that require developers to take a different approach when creating the working logic of the application.

(1) Can chatbots correctly understand people’s questions?

Communication with the chatbot takes place through the user interface. The user interface allows developers to communicate with the chatbot in a language it understands. For this purpose, Microsoft Azure uses a dialog system that follows a specific hierarchy:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Here you can See three basic ways to establish a conversation with a chatbot:

  • Prompts – Chatbots interact with users through prompts and answers. For example, chatbot information is given in the form of digital prompts. Prompt checks whether the user answered the prompt correctly. If successful, the conversation with the chatbot will continue. If an incorrect answer is received from the user, he will be prompted to enter valid data.
  • Waterfall – Waterfall is a method of gathering information from users through a series of consecutive tasks/questions. Each step of the waterfall dialog is implemented as an asynchronous function. At each stage, the chatbot asks the user to enter data, waits for a response, and then passes the results to the next step. The result of the first function is passed as a parameter to the next function, and so on until the entire problem loop has been passed.
  • # Components - Components are a way to break down a large dialog box into smaller, manageable parts. Components allow developers to create a reusable dialog box and use it later in a variety of independent scenarios. For example, you can use this to create a dialog box that will ask the user for a street name/address/zip code in sequence.

On the bottom line, you can see the allowed methods for creating custom requests for the chatbot:

  • Text query (text)
  • ##Number query (quantity)
  • Date/Time Request (Date Time)
  • Confirm Request (Confirm)
  • Select request (select)
  • ##Attachment request (attachment)
In essence, the query is a staged dialog: in the first stage, the chatbot requests input data

In the second phase, it returns a valid value to the user or restarts the data query loop if an invalid value is received.

(2) Controller and template

Look below## Code from the "Remind me later" chatbot example created by

#Daniil Mikhov, whose main task is to remind him of any action he needs to take in the future.

To create the chatbot, Mikhov used the Empty Template provided by Visual Studio, which includes several types of controllers: BotController and NotifyController.

BotController receives messages for the chatbot and passes them to the chatbot framework. Chatbot also includes several deployment templates for easier deployment of applications to the Azure platform.

Step-by-step instructions on how to create a chatbot using Azure Bot Services

The Notify Controller determines when to send a message to the user. This issue will be discussed in more detail later.

(3) Start the function and populate the ToDoDialog tab

##Go to Startup.cs tab to view its contents. Here you can see the registered error handler AdapterWithErrorHandler. If an error occurs in a program, the application's reaction to the error is necessary. Note registering ConversationState - use this to let the chatbot know which user it is communicating with and at what stage of the conversation.

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Let’s take a look at the contents of the ToDoDialog.cs tab. Mikhov declares waterfallSteps, which is a set of steps in the waterfall dialog box, which has been mentioned above. In waterfallSteps, specify which asynchronous functions are used in each step to build the conversation between the user and the chatbot.

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Below you can see what type of input prompts the chatbot will use. The content here is pretty standard: the chatbot will ask people some questions about the event and then provide scheduling reminders.

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Now run the chatbot and test its operation using the Bot Framework Emulator interface.

# (4) First launch and test in the chatbot framework simulator

When running this application, a link to the URL where the chatbot will wait for user messages will appear.

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Before starting the test, specify this link in the chatbot framework simulator:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

In the first communication step, the chatbot asks the user to enter the name of the event that needs to be reminded. To do this, call the following code :

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Now, when When the chatbot is called, it will return the following text: Please enter a description of the event. After declaring the event (such as buying milk) that you want to be reminded of, call the code in the second step. Here, the chatbot will provide one of three reminder time options:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Pay attention to the use of stepContext. It saves all information about the dialog box, recording intermediate values. To implement a list of possible reminder times, ChoicePrompt is used. This method will provide the user with three options and a possible reminder time (2 minutes, 5 minutes, or the same time the next day) . There could have been more choices, but only three were chosen.

Using selection to represent each new selection time, you can get:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

In the chatbot framework simulator, this code will be rendered like this:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

You can use Parse to parse the results. As a reminder, parsing is an automated process of collecting data and structuring it. The chatbot will then ask the user if they are sure about the selected reminder time, using ConfirmPrompt to confirm the agreement:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

From the visual Look, this method looks like this:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

The last step is to take out the previously filled in information from stepContext and Generates a SavedNotificationModel to which a conversationReference must be added. Without it, the chatbot cannot resume the conversation with the user or determine which user specifically addressed the issue.

Step-by-step instructions on how to create a chatbot using Azure Bot Services

MikhovUsing the dictionary method as a temporary repository for these events, thanks to its adoption, The chatbot assigns its unique instanceId to each specific dialog:

Step-by-step instructions on how to create a chatbot using Azure Bot Services

This will end up with the chatbot dialogue. You can display text to the user indicating the end of the dialog box and create a corresponding reminder request: "Thank you. The notification was saved successfully".

Step-by-step instructions on how to create a chatbot using Azure Bot Services

(5) How does a chatbot travel through time​

For To locate the chatbot in time, Mikhov created the notifiedcontroller method NotifyTimeCheck(). This approach allows the application to be systematically polled and if a certain event is about to occur, the chatbot will retrieve the event from the dictionary and send a notification to the user.

Step-by-step instructions on how to create a chatbot using Azure Bot Services

To get notified, the BotAdapter's ContinueConversationAsync() method is called, passing the ConversationReference to it. The first parameter of ContinueConversationAsync() must always be the appId (application ID) of the chatbot service, otherwise, it will not work.

In addition, the chatbot also needs to be reminded that when a certain time arrives, the event must be reminded to the specific user. Developers can use Azure Function (BotTimerFunction), which will be triggered by a time trigger (TimerTrigger).

Step-by-step instructions on how to create a chatbot using Azure Bot Services

Every minute, the function will send a request to this endpoint and start checking for the specified events. If it reaches the correct time frame, the chatbot will notify the user that the scheduled event is about to occur.

Today, WhatsApp, Facebook Messenger, Telegram and other communication tools are not only communication platforms, but also business platforms. Chatbots help businesses effectively sell and promote goods and services online. Automating daily processes, providing necessary product information to customers in a timely manner, receiving and processing requests – all these features of a properly configured chatbot will help convert users into customers. Therefore, as a developer, you should remember how popular this tool is now and how cool it is to be able to create such an application and become a popular expert as a result.

Original title: How to Create a Chatbot Using Azure Bot Service: Step-by-Step InstructionAuthor: Daniil Mikhov


The above is the detailed content of Step-by-step instructions on how to create a chatbot using Azure Bot Services. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template