We integrate Yandex.Alisa and sex shops through Spring boot.
The topic of voice assistants is gaining momentum, and I decided to join this trend by integrating the largest wholesale supplier of intimate goods and Yandex.Alisa.
Idea : the supplier has personal accounts of owners of online stores, and it is necessary to give analytical data from the supplier through the voice channel of Alice.
Integration consisted of two parts:
- Integration of the web service and the REST API of the supplier of goods.
- Integration of Yandex.Alice and a web service for processing user requests.
Web Service Integration and REST API of Merchandise Provider
The service should understand what exactly the user asked for and request this data from the supplier’s server. We decided to write a service on Spring Boot.
Project setup
We create a repository in Git and using
spring initializr we deploy the project on spring boot (we specify web in dependencies).
The request to the service comes in JSON format. It has a
well-documented structure , so generating classes is quite simple:
Conveniently, the query highlights keywords like the recognized address. They are located in the
“entities”
block:
But in our case it was more convenient to use the
Command
field. It contains the text dictated by the user. Since the integration service is engaged in the recognition of meaning, we need to parse requests. They are well separable from each other (requests for placed orders, requests for orders in processing), so we decided to use regular expressions to parse them.
Integration with the provider was implemented through the Apache httpclients library, and XML response deserialization through jaxb.
So, we sorted out the request and requested data from the supplier. But Alice is a strict girl, and therefore will not accept our answer later than three seconds later. And the user may want to get a comparative description of his store over the past two years, which will take more time. To solve this problem, we
enabled caching through the
ehCache library and configured the loading of user data. Faced a new nuance: Alice does not give almost any personalized user data. That is, you don’t even see email in the incoming request. There is only userId that displays the unique identifier of the device. It was made the key to identify users.
The key is there, the cache is, it remains to understand when to load information into it. The user does not immediately request data, but first launches the skill (this is the term used in Alice, I will talk more about it below). For the server, this looks like a request with an empty
Command
tag. At this point, you can start downloading client data, and then by the time the first user request is sent, all the data has already been uploaded to our service.
For full testing and further work in the prod, we decided to deploy the application in the cloud on Heroku. To do this, go to the
Heroku website, register, download heroku cli and install it. Then open the console and enter
heroku login
. Go to the directory with the project cd ~ / myapp and execute
heroku create
.
When you create the application, Git creates a remote repository named heroku, which is associated with your local Git repository. By default, Heroku generates a random name on the server for your project. You can replace it by passing the application name using
heroku create myapp
.
To check the launch of the application, execute the command.
heroku ps:scale web=1
And if you need to go along the “/“ path, then we execute
heroku open
.
The first integration point is ready.
Integration of Yandex.Alice and request processing service
We implement integration through the creation of the so-called skill on the Yandex platform. First, register in Yandex, and then go to
the developer's page . Click "create dialogue" and select the type of dialogue:
On the tab "Settings" and you need to fill in the fields:
- Skill name - the name that will be displayed in Alice’s catalog. With it, the user will be able to activate the skill, for example, “Launch the skill [Skill Name]”.
- Activation name - here you can specify various options for accessing the skill. By default, one option for the activation name is the skill name.
- An example of a request is a phrase by which Alice activates this skill. Requests will be presented as buttons in the directory after publication.
- Webhook URL - you must specify the URL of our web service that will process user requests.
- Yandex.Cloud - Yandex can give a grant to its cloud, but we will deploy the service on heroku, so we do not tick it.
- Voice - here you can choose the voice that your skill will speak. There are different variations of male and female. But it is worth considering that the user will most likely say: “Alice, launch the skill”, and if Alice answers with the male baritone, this can be somewhat confusing.
- Limitations on the platforms used - whether a screen is required when working with a skill. In our case, no, so do not put a tick.
- Privacy - check the box if you do not want the skill reflected in the catalog.
- Brand Verification Site - The site address for the skill. The skill for which you filled this field will only be moderated if you have confirmed the rights to the specified site in Yandex.Webmaster.
- Category - in our case, it is “business and finance”.
- Description - why do you need your skill. The skill description will be displayed in the skills catalog and will be available to users.
- Notes for the moderator - perhaps the most interesting field. To get into the catalog, the skill must be moderated, which means it must comply with certain rules, which are described here. In this field you can describe the testing process. For example, how to go through authorization and one typical user scenario.
- Age restrictions - despite the subject of the skill, we will transmit data suitable for any age group. Therefore, do not put a tick.
- Icon is a must :)
Save the dialogue. All changes to the skill setting take effect only after clicking the "save" button.
We configured the integration, wrote the service, now you can test it.
Go to the "Testing" tab.
Here you can check the performance of the skill. For the sake of convenience, we have added quick access to function buttons to the skill.
There are limitations: you cannot check the skill for the correctness of the starting phrase and you cannot check voice input / output. And if there shouldn’t be any problems with the phrase, then the correct pronunciation of the answers will be checked only after the publication of the skill.
After all the tests, the skill can be sent for moderation. To do this, go to the tab "General Information" and click on "Moderation".
After moderation, the Publish button will appear instead of this button. After publication, the skill will appear in the official Yandex catalog.
Features and limitations
At the moment, the skills are somewhat separate from Alice herself (I have to say “launch the skill”), which makes it difficult to perceive Alice as a full-fledged voice assistant. It would be great to shape your skills context and ask questions directly to Alice. There is no way to get any information about the user except userId, which is the device identifier. Therefore, on each device you need to re-authenticate, which makes it difficult to store a single user session. Also, the skill cannot send push messages, so it will not work to make the reminder skill.
On the other hand, skills can be a good platform for implementing voice control, for example, home appliances. Also, the skill can be useful in training or conducting experiments, in clarifying information on orders, prices, etc. In general, where users can ask a short exact question or give a short command.