Rate this page:

Key-Value Storage

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 VoxEngine and by the management API.

Quick tip

You can use the Key-Value Storage module to mask phone numbers, for example, when creating a delivery service solution. An order number can be a key, and a courier's and customer's phone numbers – the values. Thus, the courier and the customer are connected by the order number and don't know each other's phone numbers.

Follow the steps below to become acquainted with the principles of the module usage.

What you need

We suggest creating a simple scenario that “knows” how many times a user called a number. You will need:

  • Voximplant developer account. If you don’t have one, sign up here
  • Voximplant application, JS scenario, rule, and user. Those will be created during this tutorial
  • Web client to make a call, we’ll use our webphone at https://phone.voximplant.com/

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:

Scenario code

Scenario code

Please note

Key should be up to 200 characters and value – up to 2000 characters.

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 the totalCalls value from the application storage. If there is no value, we create such a variable in the storage:

Compare the call counter and the initial value

Compare the call counter and the initial value

The next action to perform is to increment the value in the storage.

Increment the value

Increment the value

PAY ATTENTION

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!