📜 ⬆️ ⬇️

Breeding



Since the beginning of the 2000s, news about the introduction of chat bots into work has been appearing with enviable periodicity. In this article I will tell you where to start and give an overview of existing solutions, as well as share the experience of creating a bot for the company Selectel.

Scope of application


Business development is often accompanied not only by scaling up the core business, but also by debugging supporting processes. Chat bots are only a part of the business activity within the framework of routine automation. Communication and the implementation of simple tasks of the same type underlie the work of the chat bot. With it, you can perform not only repetitive tasks, but also those that a person is not able to perform, for example, monitoring activity on social networks.

I want to give a variety of applications for bots using the example of my own work at Selectel. Mini-spoiler: I began my work as a technical writer, now I am an engineer in the cloud solutions department. The way of introducing virtual assistants began with a bot for the marketing department, which keeps track of comments and references to the company in social networks. Such development is very simple, but it effectively complements existing solutions on the market, for example, the IFTTT service .

The following developments in my practice were an internal chat bot for the HR department and a bot for communicating with clients, presented as a demo stand during the SelectelTechDay conferences in St. Petersburg and Moscow . Both bots are created using different services and technologies. And before diving into technical details, consider the high-level scheme of the bots device.

Basic principles of botany




Chatbots activity is built around 3 main actions:

  1. Receipt or output of information occurs through certain communication channels, for example, in Slack or Vk.com dialogs
  2. Intent recognition is a comprehensive analysis of the information received to form a response.
  3. Processing an action is any work done on the server side that is necessary to prepare the correct answer. For example, if a weather forecast was requested, a request will be made to a certain API about the weather in the city N, and the results of this command will be sent to the user

The main actions of chatbots are combined as part of the task of preserving context to create a human-like form of communication and to support dialogue. The chat bot must “remember” the subject of the conversation and adapt its answers accordingly.

The issue of connecting a chat bot to social platforms is highlighted. Connectors to instant messengers and social networks can be implemented independently or maintained within the framework of existing products for creating chat bots.

At the moment there are many solutions that offer a ready-made service to automate technical support or sales processes. I will pay more attention to the tools that allow you to create a service that meets the company's internal security requirements, without complicating the development process.

Botany


The above 3 principles of chat bots (channel, analysis, action) can be implemented in different ways. The easiest option is to make comparisons of the incoming text and send the corresponding answers to the user.



Our goal is a little higher - to get a system to which you can quickly add new scripts and that will understand the user in most cases.

To do this, we need to understand what the user is talking about, control the course of the dialogue and, in some cases, perform certain actions (for example, book meeting rooms). This can be achieved using the following tools:



When choosing a product, the following factors are taken into account:

  1. How critical is the location of the executable bot code within existing systems
    For example, in the case of Wit.ai and Dialogflow, we do not control the entire process completely - we give the text to these applications and get a ready answer. Using the Rasa Core or Azure BotBuilder SDK, we can store all correspondence within the boundaries of internal systems.
  2. How many communication channels need to be connected
    Dialogflow provides the ability to use a limited number of connectors that connect instant messengers and social networks by specifying access keys. For Wit.ai and Rasa Core, you can use any number of channels, but the logic of connecting to them needs to be implemented independently (this is often a very trivial task). Azure Bot Service has the ability to use connectors to specific channels, but is not limited to them, and it can also be connected to other sources independently
  3. How easy is it to make changes to the bot's knowledge base
    When creating a bot in the form of a program code without using a visual interface to interact with it, we limit the circle of people who can make changes to the dialogues and answers of the bot. The functionality of adding and editing phrases should be available for everyone.

The Google Dialogflow platform was chosen for our internal virtual assistant of the Tireks chat bot, which provides visual editing of intentions, and actions are performed inside a private cloud in Selectel . The defining factors were the speed at which you started working with the bot, the security of sending messages and the presence of the Slack channel in the list of supported ones.



The idea of ​​creating a chat bot has long been in the air of the company, especially considering what problems could be solved with it:




Creating and connecting a bot in Dialogflow takes a few minutes. In the beginning we will look at the principles of the chat bot in the system, and then add the execution of complex actions.

Creating a bot in Dialogflow


Creation of architecture


Further in the text we will operate with such concepts as:


Dialogflow processes natural language and extracts all the necessary data for executing complex commands. For this purpose, agents are created that contain several intentions . Each of the intentions allows you to prepare a chat bot to understand the nuances and subtleties in the formulation of requests.

Intention includes training phrases , options and answers . Inside the training phrase, we select the parameters (for example, time or place) that are necessary to form a correct answer.

The answer is indicated either in the intention , or Dialogflow sends a request to our server, which performs the necessary work and returns the answer back using the example of our chat bot:




Work with intentions


Consider working with Dialoglow on the example of booking negotiation. We create a booking management agent and define the following intentions:


Each of the intentions is caused by training phrases. The more added, the more likely the desired action will be performed. In our example, the intention to “Book a meeting room” will be called with the following phrases:




The principle of data collection in the intentions is as follows:

  1. Based on the received input, Dialogflow understands what intention it is. In our example - booking negotiation
  2. If the required parameters were not specified in the first message (for example, meeting time), the chat bot will ask clarifying questions
  3. After receiving all the data Dialogflow will send a request to our server in VPC for booking the desired room

Let's look at this process in action:



Processing an action is done by sending a request with all the data to the previously added address of the action server (Webhook URL):



At website.ru/webhook is a server that performs processing of complex commands (in our example, returns the string "Hello from the server!"). Github Gist for a quick start:

# -*- coding: utf-8 -*- from flask import Flask, request, make_response, jsonify app = Flask(__name__) @app.route('/webhook', methods=['POST']) def webhook(): req = request.get_json(force=True) intent = req.get('queryResult').get('intent').get('displayName') print(intent) if intent == 'Sample intent': res = make_response(jsonify( { "fulfillmentText": "Привет от сервера!", } )) return res return make_response(jsonify( { "fulfillmentText": "Совпадений намерений не найдено!", } )) if __name__ == '__main__': app.run(host='0.0.0.0', debug=True, port=5000) 

Creating a bot with RASA


To use chat bots without third-party text recognition services, you can use tools like Rasa , which allow you to fully control the entire bot work process. Rasa is a set of open source software components that contain speech recognition and dialog management. You can already look at Boilerplate , which I prepared to get acquainted with the platform, and we will publish more detailed instructions if there are requests from the Habr community.

Chat bots and business


Whether to use automation services for customer service is a difficult question. Modern tools provide a variety of solutions when choosing between flexibility, start-up speed and safety. The systems of recognition of intentions in natural language are now available not only in proprietary form, but also freely distributed, which opens up great opportunities for own experiments. We considered one of the options that allows you to quickly implement chat bots to automate the tasks of the same type in your business without capital expenditures and with minimal labor costs. If you already use chat bots in your work, share feedback in the comments about your impressions and, of course, the impressions of your customers.

Source: https://habr.com/ru/post/436622/