How I taught Yandex.Alice to talk about sex toys

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:





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:



image



Conveniently, the query highlights keywords like the recognized address. They are located in the “entities”



block:



image



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:



image



On the tab "Settings" and you need to fill in the fields:



image





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.



image



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".



image



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.



All Articles