📜 ⬆️ ⬇️

How we created a chat bot for a week and made it friends with a web application

Chat bots are a trendy trend with promising prospects: in most situations, artificial intelligence is more efficient than traditional web applications. However, with the integration of new technologies, we should not forget about users who do not want - or who are not able - to abandon the usual forms of interaction. Today we will talk about how to create a chat bot serving the conference during the week and make friends with the classic web application.

image
Photos chatbotsmagazine.com

First bank chat order


So, artificial intelligence has come to the banking sector and clearly intends to settle here. Technologies are far from perfect, chatbots are not yet able to completely replace a person. But today they can safely be entrusted with most of the routine tasks of interacting with customers. At least, they have much more prospects here than traditional web applications: 75% of bank employees surveyed by Accenture consulting agency called artificial intelligence the main vector of development for this area.

If the technology Bot Framework from Microsoft is really able to improve customer service, our bank simply does not have the moral right to stand aside. Using our chat bot using the Bot Framework solution, we decided to optimize the voting process. The fact is that we regularly hold presentations and other events where we introduce people to our latest achievements and innovations. The audience can vote for those sessions that they liked, leave comments and make suggestions.
')
Until now, we have offered participants after the event to fill in some kind of questionnaire on our website. However, it is obvious that this form of interaction is not active: quite often the user simply closed the web page. Another thing is adding ChatBot to your contact list. Our robot not only involves the client in the discussion process, but also keeps in touch with him after the event. Subsequently, through the chat bot, you can send ads, announcements and other information.

image
Photo nonworkplace.com

Created by us with the support of Microsoft and OpenDev, the chat bot is capable of supporting multiple channels — various devices and platforms that users bring to the event. Unlike the web form, our virtual assistant remains active throughout the event. He monitors participants' questions about sessions and speakers, and can conduct a poll or vote.

Principal Issues and Primary Architecture


Evaluation of the boundaries and volumes of the project took place in several stages. The task seems simple only at first glance. Having dug a little deeper, our team was faced with a number of issues that required serious brainstorming.


image
Photos chatbotsmagazine.com

We note that we ultimately abandoned the idea of ​​organizing group communication. The Bot Framework for Node.js — the platform on which we developed the chat bot — does not effectively manage multiple contexts. Therefore, communication support was implemented through a private channel.

We had no doubt that it was necessary to use the web form as an additional voting tool: it would be wrong to leave Telegram the only channel of communication. But for correct interaction it is necessary to achieve maximum identity of both channels. Of course, the dynamics of the process is different: a chat bot simulates a conversation, offering to begin the voting process. In addition, it introduces the user to the new report and provides it with additional information.

As mentioned above, the chat bot was developed in Node.js. As for the web form, it is a website written in Java. Both components use a MySQL database located in the OpenDev infrastructure. The choice of a database system was based on its simplicity and low server resource requirements. Initially, the architecture was implemented on a single MySQL server. The first version shown in the figure below looks extremely simple. It remains to improve this model by adding scalability and reliability.

image


Stress resistant chat bot


For starters, a little bit of terminology. By scalability, we understand the stress resistance of software, its ability to cope with increased load. Thus, in all situations, all simultaneous users should have the same experience - in terms of latency, load time, etc.

Reliability is determined by the time during which the system operates without interruption. In addition, for messaging, you must provide high availability to the application. In other words, users must send and receive messages during the appropriate time intervals.

Creating a robust and easily scalable architecture has been helped by the use of some advanced techniques.


Note that most of the architectural decisions have already been made in the Bot Framework and the Azure team. We only need to test the methodology in the process.



The second and final version of the architecture is shown in the figure below.

image

Authentication with options and other features of the system


Chat bot and web form interaction is required from the very first step - authentication. Consider to start the classic authorization through the site. We have tried to simplify the process as much as possible: the user enters his e-mail on the web form - and receives an email with two login options:


The second method is universal: the code is entered either in a web form or in a chat. Synchronization of chatbot content and web form occurs with any of the authentication methods. True, a user who is authorized in the web form must still enter the code in the chat. In this case, the chat bot welcomes the user by the name under which he registered on the site.

image

What is re-authentication by code? For additional security: in fact, after authorization of the user, the code serves as a token.

Now consider the "pure" authentication in the chat bot. The sequence is as follows:

  1. Type / start.
  2. Enter Email.
  3. Get the code and enter it.

Authentication using a data source in the MySQL database made the process simple and convenient, while making it possible to partially synchronize the context. Full context synchronization would require the introduction of multifactor authentication. And this is an unjustified complication of logic, plus an increase in the load on the backend. In our case, when the life cycle of user interaction with applications is limited to a few days, this approach has no practical meaning.

image

Below is the code with which the confirmation procedure is implemented. As you can see, the code is first checked with a regular expression, confirmed on the backend. It then replaces the set of constants with user data and ends the process by welcoming the user by name.

``js promptCode() {    return [        (session, args) => {            if (!_.isEmpty(args) && args.code) {                return session.replaceDialog('/promptName', session.userData);            }            if (!_.isEmpty(args) && args.reprompt) {                return Prompts.text(session, '   **4-** :');            }            return Prompts.text(session, ' ,    email: ');      },        (session, result) => {            if (/^[0-9]{4}$/.test(result.response)) {                return auth.makeUnauthRequest({                url: '/login',                method: 'POST',                body: {                        password: result.response,                        login: session.userData.email                }                }, (err, res, body) => {                if (err) {                        console.error(err);                        return session.replaceDialog('/error');                }                 if (body.status >= 300 || res.statusCode >= 300) {                    console.error(body);                 return session.replaceDialog('/promptName', session.userData);                  }                  session.userData.code = result.response;                  session.userData.id = body.id;                  session.userData.permissions = body.permissions;                     session.userData.authToken = body.authToken;                        session.userData.allowToVote = !_.isEmpty(body.permissions)                        && (body.permissions.indexOf("PERM_VOTE") !== -1                        || body.permissions.indexOf("PERM_ALL") !== -1);                    return auth.makeAuthRequest({                        url: '/login',                        method: 'GET',                        authToken: body.authToken                    }, (err, res, body) => {                        if (err) {                              console.error(err);                            return session.beginDialog('/error');                 }                        if (!_.isEmpty(body) && !_.isEmpty(body.name)) {                              session.userData.name = body.name;                            return session.endDialogWithResult(session.userData);            } return session.replaceDialog('/promptName', session.userData);                    });                });            }            return session.replaceDialog('/promptCode', {reprompt: true});       }    ]; } `` 

When interacting with a chat or web form, you can get information about reports without authorization in the system. Chat bot offers to evaluate the report and write a comment to all customers. But only authenticated users will be able to do this. Otherwise, the bot sends an authentication request, as shown in the following code snippet.

 ``js rate() {   return [       (session) => {           if (_.isEmpty(session.userData.authToken) && !_.isEmpty(this.socket.actualPoll)) {               session.send('  ,      .\n\n' +               '  `/start`  ! ');               return session.endDialog();         }           if (!session.userData.allowToVote) {               session.send('       ');               return session.endDialog();           }               Prompts.choice(session, '  ', RATES);       },       (session, res) => {           if (res.response) {               let result = parseInt(res.response.entity, 10) || res.response.entity;               if (!_.isNumber(result)) {               result = RATES[result.toLowerCase()];               }               return auth.makeAuthRequest({               url: `/polls/${this.socket.actualPoll.id}/vote`,               method: 'POST', body: {                       myRating: result               },               authToken: session.userData.authToken              }, (err, response, body) => {               if (err) {        console.log(err);                       return session.beginDialog('/error');                } else if (body.status === 403) {                     session.send('       ,  ');                } else {                     console.log(body);                     session.send('   ');                }                return session.endDialog(); })           }           session.endDialog();       }   ]; } `` 

Among other things, chat bot can tell you the following steps. This is especially important for customers using a bot as the main way to communicate with the system.

 ``js help() {   return [       (session) => {           const keys = _.keys(commands);           const result = _.map(keys, (v) => (`**/${v}** - ${commands[v]}`));           session.send(result.join('\n\n'));           session.endDialog();       }   ]; } `` 

To be continued?


It can be stated that our experiment with Microsoft's Bot Framework on the introduction of artificial intelligence in the banking sector was completed successfully. It is worth adding that the project is fully implemented by one developer during the week. During this time, a full-featured chat bot was created with a botnet hosted in Azure, as well as Application Insights support and some useful user preferences in Bot logic.

image
Photo letzgro.net

However, it is better to see once. Experimental chat bot has already entered the service in our bank. So we suggest that you, if possible, attend one of our conferences in order to test and evaluate the work of this little virtual assistant in practice.

Mikhail Brantov, Director of Testing and Quality Control at Otkritie Bank

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


All Articles