Rate this page:

Key-value storage

Voximplant provides a built-in database for key-value pairs, available throughout the application.

You can store unlimited key-value pairs in the database, your keys can be up to 200 characters string, your values can be up to 2000 characters string.

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 do not know each other's phone numbers.

In this article, we create a simple scenario that “knows” how many times a user calls a number.

Prerequisites

Copy URL
  1. Create an application.
  2. Create a scenario.
  3. Create a routing rule and attach it to the scenario.
  4. Create a user to log in your client.

You need a working web or mobile application to make calls. Refer to the Basic call functionality to learn how to create it.

You can use our web phone to make a call.

Scenario setup

Copy URL

In the scenario, require the ApplicationStorage module that manages the key-value storage. Use the put method to create or update the value and the get method to get the current value.

Learn more about the methods in our API reference.

Take a look at the scenario code for our task:

Scenario code

Scenario code

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

Test your application

Copy URL

Open https://phone.voximplant.com/ and log in with your credentials. After successful login, enter an arbitrary string and click Call. If everything goes properly, you hear a synthesized greeting!