Dialogflower - Google Dialogflow for Alice Yandex


A few months ago, Yandex launched a beta of its voice assistant, Alice , in which it opened its API. And just recently rolled out everything in public. Now millions of users can launch various functions and services by voice directly from mobile search, navigator and from Yandex browser. Not surprisingly, voice skills are becoming more and more. But the dialog API suggests that you should be able to program, you should have your own server with HTTPS, and in addition you should be able to process requests in natural language ...

Meanwhile, there has long been a free and fairly convenient dialog constructor from Google called Dialogflow. He certainly does not support Alice’s protocol out of the box, so the thought came to correct this situation, so that developers (and not only) quickly and without servers created skills for Alice who can understand natural speech and the context of dialogue.

What is Dialogflow


image

Dialogflow is an online service from Google that allows you to create your chat bots or functions for Google Assistant (this is called the agent ). On Habré there are already some quite good articles in which the main tools of this product are considered. Here is one of them .

In fact, Dialogflow is able to match a user's phrase in natural language (and in Russian too) with some “non-linguistic” meaning (called intent ) and answer something. In addition, he also holds the context of the dialogue so that the next phrase can be responded to in the context of previous replicas.

The tool is quite simple to manage, and still keeps all the statistics of requests, so that you can in one click to train an agent with new intents or replenish existing ones. Actually, this is how training happens - you simply show examples of requests that relate to a particular intent in your agent, and Dialogflow automatically builds a model and understands the user better and better. He can also select some entities from the phrase, such as dates or cities, if you need it to perform some function.

Why is Alice


Alice has an API similar to the telegram API. In other words, to create a skill for Alice, you need to raise the server, which will receive a text request from Alice from the user and respond with data in the required format. Everything seems simple, but to create even the simplest skill, you will need to learn Alice’s protocol, set up your public server with HTTPS, write code that can understand human language and maintain the context of the conversation.

So that you do not have to do all these steps every time, and at the same time, if you are not a programmer, and the skill is really needed, you can use Dialogflow.

Dialogflower


image

Only here Dialogflow does not support Alice’s protocol, so it’s not so easy to turn an agent into a skill. For this, the dialogflower.com service was made, which is essentially an adapter - on the one hand it implements the Alice protocol, and on the other hand it connects to your agent on Dialogflow. And thus turns an agent into a skill. Without any servers and code.

image

Create an agent


image

So, now we can focus only on the logic of the dialogue itself in our agent. First you need to create this agent on the website dialogflow.com

After entering, we will be asked to come up with the name of the agent and choose his language. In the title you can use only Latin, and the language does not forget to switch to Russian.

After that you can add intents - topics that our agent will understand and somehow react to them.

Default welcome intent


This intent exists by default in each agent. It does not work for any user phrase, but for the welcome event. That is, when a user launches your skill in Alice with a phrase like "Start the skill is my most needed skill". Then there is still no command from the user, and the agent in response, as a rule, should simply tell what can be done next.

If you click on the Default welcome intent in the list of intents, then at the bottom of the page you can add Responses - answers from which the agent randomly chooses one each time and sends it to Alice.

Alice can also show buttons and links, then we will show how to add them to the answer

Click on Add response - Text response and add text response options.

Default Fallback Intent


image

And this intent is triggered when the user says a phrase that the agent cannot attribute to any of the existing intents. That is, when the agent simply does not understand the user's request. Here you can also set the answers that Alice will say when we don’t know what to answer.

We respond to replicas


If you click on the plus sign next to the word Intents in the left menu, you can add a new intent and specify a list of phrases for which you need to answer something. In the Training phrases list, add the phrases that the user is likely to utter. The more, the better.

Of course, Dialogflow understands English better than Russian. Therefore, do not expect that he will understand all the synonymous phrases that fit the meaning. In this regard, our analogue Aimylogic works better, which I will discuss below.

Do not forget to add answers to your intent and click on the Save button. Without it, nothing will work.
You can test right here - on the right side of the screen. Write your test phrase in the Try it now field and see what your agent answered.

Create a skill


Now everything is ready to fasten our created agent to Alice and test it in the Yandex Dialog console. To do this, go to dialogflower.com and click on Create skill . In the window that appears, you need to specify Client access token from your agent. It can be found on the agent settings page in Dialogflow. Click Done and in a second you will have a Webhook URL with which we will go to Yandex Dialogues.

image

Then create a new skill for Alice and in the settings specify this Webhook URL. In addition to it, for tests, you only need to come up with a naming of the skill, it is not necessary to fill all the other fields yet. Click Save and go to the Testing tab. Here you can write something and check that your skill works as expected.

We increase the functionality


Now our skill is ready, and all changes will affect only the agent on Dialogflow. Just add and change intents, do not forget to click the Save button and test the result in the Yandex Dialog console.

How to understand the context


Dialogflow can line up intents in chains so that your skill can react in the right way to phrases spoken in the context of the conversation. To do this, simply add an intent to another intent. To do this, go to the list of intents and hover your mouse over one of them. A barely noticeable Add follow up intent sign appears on the right. Click on it and add an intent that will work in the context of the previous one.

That is, for example, if you have an intent that responds to phrases like “What kind of weather”, then you can add an intent with phrases like “and tomorrow” to it. Then this phrase will be processed by the agent only if the user first asked to tell about the weather.

How to add buttons to Alice’s response


Alice can respond not only with text, but also show buttons and links. Pressing the button, the user as it forms a new request, just not saying it and not typing text.

To add buttons to the response, you need to write a piece of JSON in a format that Alice understands. To do this, go to the desired content, go to the answers and click Add Responses - Custom Payload . Here you can specify a piece of the response from the Alice API. For example, to add buttons, write

{"buttons": [ {"title": " ", "hide": true} ]} 


There is one button added that will send the request text to Alice when clicked and will automatically hide from the chat history after that. Here is another example.

 {"buttons": [ {"title": " ", "hide": true}, {"title": "  ", "url": "https://dialogflower.com"} ]} 


Two buttons will be added here, one of which is a link to the dialogflower.com website.

In general, you can write any JSON in Payload format in the “response” field from the Alice protocol .

Where is the logic?


Of course, it is not always necessary to answer, albeit with random, but static phrases. In order to add some logic, you will need to write a little bit of code. Well or a little, depends on you. But Dialogflow allows you to do this without renting servers.

Click the Fulfillment tab and turn on the Disabled switch. Here you can write Javascript code, which will react to the activated intent in the necessary way and execute some logic before the answer is sent to the user. Actually, the answer itself can be immediately redefined in code.

Here I will not describe how and what to do with this code, I will give just a good example on github , in which the agent can create events in the Google calendar, writing the user to repair the bike in his spare time.

The main advantage here is that you don’t have to set up a separate server in order to implement some logic for your agent. Google will do everything for you, and for free.

Eventually


Alice is being used by more and more people in the country. She works in search, navigator, and browser, and will soon go on sale home column with Alice on board .

Alice has an API and every day more and more voice skills appear for her.

Google's Dialogflow provides a good tool for developing voice applications, even without programming skills and with the possibility of running your own code on Google’s servers for free.

Dialogflower associates an agent on Dialogflow with Alice so that you can quickly create skills and experiment.

So what was the matter? Moreover, Dialogflower is as free as Dialogflow with Alice.

A spoon of tar


These were all interactive flowers, but not everything is so beautiful in the real world. Of course, Dialoglfow is a cool tool, but in Russian it does not work as well as in English. Until he understands many of the synonyms, and they will have to be scored manually when creating an intent.

Another disadvantage is that in Dialogflow it is quite difficult to manage at least some complicated dialogue. You just can not see it, because intents are just a flat list.

Just a couple of days ago , a tool with similar functionality was presented on Habré, which also knows how to understand natural Russian speech, but does it much better, understands synonyms, even if you only trained a bot on a couple of phrases. There are not many Dialogflow chips yet, such as entity extraction or statistics. But there is a cool visual editor, which immediately shows the entire course of the dialogue with the user. And you can also add logic without writing code.

However, in a lively competition among manufacturers of tools for developers, developers always win.

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


All Articles