Let's do it quickly: voice bot on Dialogflow and Voximplant
Voice bots have been and remain a useful feature for communicating with customers. Because if something is possible to automate, then it is urgent to do it. Confirmation of orders and information about them, record feedback from customers, voice recognition and actions according to what was recognized, etc. By the way, the last thing is to make the bot with recognition in 2018 even easier: Voximplant perfectly knows how to recognize and transcribe speech, and the Dialogflow tool from the “good corporation” analyzes the text well. Below I will show how you can quickly assemble a demo bot, which tells about the weather in the named city.
Why “demo” -bot?
Because the principle. This article shows the principle of creating bots on Dialogflow + Voximplant. Therefore, the dialogue with the bot will be simple, for example:
Bot: - Hi! Ask the weather in Moscow or another city. Subject: - What is the weather in London? Bot: - Today in the city of London - cloudy. ')
Voximplant will allow you to rent a phone number, recognize and transcribe your voice, and interact with Dialogflow and openweathermap.org. We will pass to Dialogflow a string transcribed from the user's response, after which NLP (Natural Language Processing) will return us JSON, in which the city name will be in the nominative case. We will give the name of the city to openweathermap.org, which, in turn, will tell us what's wrong with the weather in the specified city.
Create an NLP secret agent
Dialogflow is a powerful NLP service owned by google. The service is free, but to use it, you need a Google account. Go to https://dialogflow.com/ and register. The service operates with the concept of “agent” - in fact, the agent is the bot. By default, the new account has no agents. There are prebuild agents in the service, but you can't add them right away. Therefore, we create a new agent just to get access to the pre-installed agents; It sounds like a crutch, but believe me, this is it.
Enter a name for the agent, the remaining parameters can be left as default. The Google project field implies a project in Firebase (if you do not have Firebase projects, a new one will be created). Click Create and get into the Dialogflow console, this is the name of the main screen of the service. On the left, the vertical menu, click on Prebuild Agents, find the Weather agent and click Import. Done, now there is a weather agent in our account!
By default, the agent supports only English, so we take the agent for editing (at the same time, you can change his name if you wish), go to the Languages ​​tab, add the Russian language and click “Save”.
Now our agent has a choice of language. Alas, the agent does not know how to communicate in Russian "out of the box", but nothing, we will teach. Click “ru” to make Russian active and then fall through to “Intents”.
In the Intents list that opens, select the topmost one - weather. On the new screen, we see the User says section, there should be user replicas: the more variations, the better. We still get by with the phrase “what is the weather in Moscow?”. When you enter it, Dialogflow will almost immediately highlight the name of the city and assign it a match in the returned JSON! Be sure to use this in our code. Also on this screen you can see the name of the context / topic of conversation - weather.
Now we can check the work of the agent either in the Dialogflow service (upper right corner, Try it now), or make a request via cURL. To smoke less documentation, you can see an example of cURL and returned JSON here.
Please note that the query text must be URIencoded and the key must be transferred in the header (the key can be found in the agent settings). If a context is specified in the request, then it is desirable to set unique session numbers for all subsequent requests in order not to “mix” contexts.
Now that we know the city, we can request the weather. I used a fairly simple openweathermap.org API. We register, get an API key, and we can make requests of the form:
Knowing the weather, we can synthesize this information into a call.
All together now ..!
It is time to reflect all these steps in a Javascript script. So what do we want to do?
The user calls the rented number.
Our cloud responds to the user with the words “Hi, user! Ask about the weather in Moscow or another city. ”
A person asks, “what is the weather in {CITY NAME},” our cloud recognizes the request and makes a request with the resulting string in Dialogflow.
Having received the answer, we check the presence of the weather topic in the answer and if there is a city in the answer. If something went wrong, the robot speaks about it and asks again to ask a question about the weather.
If there is a city in the response from Dialogflow, then the cloud turns to openweathermap.org, substituting this city in the request.
After receiving a response about the weather, we voice the user “Today in {CITY NAME} - cloudy / overcast / light snow” and hang up.
It remains only to create an “application” in the Voximplant control panel, and then link the created script and the rented number to it (details are on our website ).