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.
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.
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 : (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: Here you can See three basic ways to establish a conversation with a chatbot: On the bottom line, you can see the allowed methods for creating custom requests for the chatbot: ; In the second phase, it returns a valid value to the user or restarts the data query loop if an invalid value is received. #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. 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. 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. 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. 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. Before starting the test, specify this link in the chatbot framework simulator: 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 : 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: 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: In the chatbot framework simulator, this code will be rendered like this: 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: From the visual Look, this method looks like this: 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. 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: 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". (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. 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). 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 Instruction,Author: Daniil Mikhov
In essence, the query is a staged dialog: in the first stage, the chatbot requests input data
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!