As you 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. This is called Key-Value Storage, which is being operated by a new VoxEngine module – ApplicationStorage. Follow the steps below to become acquainted with the principles of its usage.
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:
Key should be up to 200 characters and value – up to 2000 characters.
We declare a variable to make a comparison between a call counter and the initial value possible. Then we try to retrieve the 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!