For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Platform docsVideosCommunitySign up
CapabilitiesGetting startedVoice AI OrchestrationVoxEngine PlatformAPI ReferenceFAQ
CapabilitiesGetting startedVoice AI OrchestrationVoxEngine PlatformAPI ReferenceFAQ
  • VoxEngine Development
    • VoxEngine concepts
    • Applications
    • Users
    • Scenarios
    • Routing rules
    • Phone numbers
    • Calls and sessions
    • Video calls
    • Management API
    • Account subusers
    • Integrations
    • Firewall
    • Cloud IDE
    • Type declarations
    • VoxEngine CI
    • Working with API requests
    • Working with the Voximplant's API
    • Remote session management
    • Key-value storage
    • Secret storage
    • Custom data
    • Limits and restrictions
    • Scenarios troubleshooting
    • How billing works
  • Management API
    • Overview
    • Developer Basics
    • Authorization
    • Callbacks
    • Child accounts
    • Accessing secure objects
  • Web and Mobile SDKs
    • iOS: CallKit
    • Android: ConnectionService
    • Screen sharing
    • Custom video sources
    • Mobile SDK statistics
LogoLogo
Platform docsVideosCommunitySign up
VoxEngine Development

Learn how to use key-value storage in Voximplant.
||View as Markdown|
Was this page helpful?
Edit this page
Previous

Remote session management

Next

Secret storage

Built with

On this page
  • Prerequisites
  • Scenario setup
  • Test your application

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

  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

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
1require(Modules.ApplicationStorage);
2
3VoxEngine.addEventListener(AppEvents.CallAlerting, async (e) => {
4 let r = { value: -1 };
5
6 try {
7 r = await ApplicationStorage.get('totalCalls');
8 if (r === null) {
9 r = await ApplicationStorage.put('totalCalls', 0);
10 }
11 } catch (e) {
12 Logger.write('Failure while getting totalCalls value');
13 }
14
15 try {
16 await ApplicationStorage.put('totalCalls', (r.value | 0) + 1);
17 } catch (e) {
18 Logger.write('Failure while updating totalCalls value');
19 }
20
21 e.call.answer();
22 e.call.say(`Hello. You call ${r.value} times`, { voice: VoiceList.Amazon.en_US_Joanna });
23
24 e.call.addEventListener(CallEvents.PlaybackFinished, VoxEngine.terminate);
25});

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
1try {
2 r = await ApplicationStorage.get('totalCalls');
3 if (r === null) {
4 r = await ApplicationStorage.put('totalCalls', 0);
5 }
6}

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

Increment the value
1try {
2 await ApplicationStorage.put('totalCalls', (r.value | 0) + 1);
3}
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

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!

Key-value storage

Learn how to use key-value storage in Voximplant.