As you might know, there is an Applications concept in Voximplant. The Applications allow linking scenarios, phone numbers, users, rules, and call queues. To put it simply, an application is the entry point for any Voximplant-based solution, so it’s necessary to firstly create one and then continue with scenarios, rules, etc.
Previously, applications didn’t “remember” any of the actions or calculations made by scenarios, so developers were forced to save values to 3rd party services or their backend servers. If you ever had experience with local storage in web development, our new functionality would seem quite similar as it allows you to save key-value pairs that are unique for each application in your Voximplant account.
WHAT YOU NEED
We suggest creating a simple scenario that “knows” how many times a user called a number. You will need:
VOXIMPLANT APPLICATION SETTINGS
First, log in to your account here: https://manage.voximplant.com/auth. On the left menu, select Applications, click New application and create a storage application. Then go to your new application, switch to the Scenarios tab, and create a countingCalls scenario with the following code:
The first line mounts the ApplicationStorage module, the rest of the scenario logic is placed in the CallAlerting handler.
We declare a variable to make a comparison between a call counter and the initial value possible. Then we try to retrieve a totalCalls value from the application storage. If there is no value, we create such a variable in the storage:
The next action to perform is to increment the value in the storage.
Each promise rejection should be handled as has been shown in the example above, otherwise, your scenario will fail during the execution. See the details here.
After working with the storage, the scenario answers a call with a synthesized message of how many times you called before. When the robotic speech is over, the scenario terminates a call session. That’s it.
When a scenario is ready, go to the switch to the Routing tab of your storage application and click New rule. Name it startCounting; use the created JS scenario in the rule and leave the default call pattern ( .* ).
The last action to perform here is to create a user for your application. Switch to the Users tab, click Create user, set username (e.g., user1) and password, then click Create. We’ll need this login-password pair to authenticate in the webphone.
HOW TO USE IT
Open https://phone.voximplant.com/ and log in, using your credentials. After successful login, enter an arbitrary string and click Call. If everything went properly, you’ll hear a synthesized greeting!
We wish you the best development experience with Voximplant. Keep an eye out – more great things to come!