Pavel 2.0: Reptiloid Consultant on JS, node.js with Sockets and Telephony
So our INTERCOM’18 has died down, with preference and business cases. As usual, the entrance to the conference was paid: anyone could buy tickets for the TimePad at full price, or get a discount from a reptilian consultant right on the site . Last year, it worked like a familiar callback: you leave the phone in a special form, Paul calls you in a minute and asks questions; the more correct answers, the higher the discount. This time we decided to change the mechanics, making it more difficult both technically and in terms of issues. Under the cut - Pavlik's guts 2.? with the current node and web sockets, do not forget to wear workwear before opening.

intercomconf.com from the desktop browser, in the lower right corner Pavlik “wakes up” in the form of a chat and offers to play a game. Enter the number, click "Here is my number" - after that Pavel raises the session between your browser and our backend.

If everything has successfully risen and your number has not yet participated in the drawing, then Pavel will offer to call 8-800. Here the Voximplant cloud is already entering and the quiz starts:

Answer: deadline /deadline. The basis taken meme 3r340. This is fine
.
Yes, the puzzles were like this. Three attempts were made for each question: first there was a “complex” picture, then simpler and at the end the simplest. The first attempts gave the most points; after 5 puzzles, Pavel counted up the points and either gave a free ticket or a 10% -30% discount.
At the same time, our reptiloid is smart enough: it gave error messages (if you entered the phone number incorrectly, for example), determined that the number was already participating in the drawing (“I see the familiar number on the screen of my non-existing mobile phone. One attempt in one hand - these are the rules. ") And, most importantly, correlated the browser and the cloud. How did this bold IVR work?
In the mouth
madness
Reptiloid
3r361.
Answer: call center. Nuff said.
Speaking dryly, Paul 2.0 is an IVR running in our cloud. Therefore, all reptiloid logic should be spelled out in a JS script, right? Yes, but no.
The second version of Pavel is synchronized with the client’s browser: Pavel shows the rebuses on the website, and he hears your answers on the phone, depending on which pictures are replaced and the result is displayed. At first glance, such an interaction could be realized with the help of our HTTP API 3r35757. :
first, the browser would run the script using the 3r3381 method. StartScenarios . In response, the method gives the parameters media_session_access_url and media_session_access_secure_url which contain URLs for HTTP and HTTPS, respectively;
a running script could be communicated using the obtained URLs;
the script would tell the browser which pictures to use and update the score using the 3r3-300 method. httpRequestAsync
.
But how to "catch" a custom browser? Indeed, in 3r3-300. httpRequestAsync
You must pass a unique URL. And yes, pictures - they also need to be stored somewhere.
Therefore, in addition to the cloud JS-script, we used our backend on express.js paired with socket.io : when the visitor entered the number, the browser gave this number to the http http, after which the http session turned into a session on web sockets. As a result, the script constantly communicated with the backend via http, and already the backend used web sockets to quickly transfer pictures and points to the browser.
In part of the web sockets, the backend looked like this: [/b]
3r3119.
But still, most of the logic was stored in the script. Consider a reptiloid from this side
We go on the scenario
3r3133.
Answer: machine learning /machine learning. Taken from Instagram3r3138. Arnie himself
.
From the obvious: be sure to connect the recognition module 3r3145. ASR
.
3r33232.
require (Modules.ASR);
From interesting:
in the script was an object questions with all the answers and file names .jpg ;
each time the script was run, the questions were mixed using the helper function 3r-3263. shuffle [/b] :
show code [/b]
3r3173.
A “top-level” handler for an incoming call (3r3-3181. CallAlerting
) Checks the phone for uniqueness, and also contains handlers for connecting and ending a call. Just inside onCallConnected there is an appeal to the backend (read, to socketio):
show code [/b]
3r3192.
just above, is seen. startGame , in it just the questions are mixed up, chopped up and sent to the backend along with the picture indices:
show code [/b]
startASR creates an instance of ASR and indicates the preferred recognition dictionary. When a player pronounces the answer, function stops the ASR and starts processing what was heard - onRecognitionResult ;
onRecognitionResult removes the excess from the answer:
3r33232.
let rr = e[0].replace ("this", "") .replace ("probably", "") .replace ("maybe", "") .replace ("maybe it", "");
rr = rr.replace (//g, '');
And then begins counting attempts, points, and also voiced comments along the way:
show code [/b]
Also, the function increments variables with attempts and a question number to switch to the next question or end the game;
the final function is 3r32r6363. gameFinished [/b] gives backend a sum of points, if a person has won a promotional code - this can be seen in the browser and heard on the phone, because Pavlik voiced winnings; after that, is done. hangup .
The overall listing of the script approaches 300 lines, the most voluminous piece is the processing of the recognition result, 3r-3263. onRecognitionResult [/b] .
Talking Fossil

Answer: Firefox. We have everything.
Although Paul and the dinosaur, but still keeps up with the times: it develops from year to year and still loves to joke. We hope you appreciate the second version of our reptiloid and "live", and in terms of implementation. Share your views in the comments, be healthy and remember - Paul loves you!
It may be interesting
weber
Author15-10-2018, 14:15
Publication DateWebsite development / Programming / Node.JS
Category- Comments: 0
- Views: 390
nursing test bank
nursing test bank