CTRLK

Shared components

Use IVR variables

|

View as Markdown

Variables make your IVR scenarios dynamic and flexible. You can use them to personalize greetings, branch into different paths depending on a customer's response, or connect your IVR with your digital ecosystem.

Variables are containers that temporarily store information, such as a caller's name, customer ID, or the result of an API call.

IVR actions can read from these variables and write new values to them. Variables enable your IVR to:

  • Communicate with external systems.

  • Keep track of what happens during a call.

  • Personalize the caller experience.

Set a variable

To set variables in your IVR scenario, you can use these options:

Launch outbound IVR with variables

For outbound IVR, you can send variables in the HTTP request that starts the scenario. For example, you might include a customer's name:

json
1 
2{
3 "messages": [
4 {
5 "from": "41793026700",
6 "destinations": [
7 {
8 "to": "41793026727"
9 }
10 ],
11 "scenarioId": "6298AA7707903A4ED680B436929681AD",
12 "parameters": {
13 "name": "John"
14 }
15 }
16 ]
17}

You can then reference the variable in your scenario, for example, in a Say action:

json
1 
2{
3 "say": "Hello ${name}"
4}

You can plug variables into your text using $``{name} as shown above. IVR supports variable expressions using the $``{} format, based on Unified Expression Language (UEL).

Set Variable action

You can use the Set Variable action to update variables as the scenario runs. This variable is useful for creating or updating information during the call.

Parse API responses

When your scenario calls an external API, each field returned in the response becomes a variable you can use elsewhere in the scenario. For example, if you get an order status from your backend, you can reference it as a variable throughout the rest of the call.

Collect DTMF

When you use Collect action to capture some digits or the Capture action to capture the speech, the result will be stored in a variable that can be used later on in the scenario.

Implicit variables

Every scenario includes built-in variables that are always available:

  • from: The caller's number (inbound) or the from number (outbound).
  • to: The destination number.
  • startTime: The time the call started.
  • answerTime: The time the call was actually answered.
  • __externalMessageId: The unique call ID, set through the launch parameter and included in delivery reports.
NOTE

You can use implicit variables anywhere in the scenario, but you cannot change them.

Action variables

Some actions create their own special variables. For example, after making an external API call, these variables are available:

  • __apiResponseStatusCode: The HTTP response code, so you can decide what happens next if your API call fails or succeeds.
  • __callApiCurrentTimestamp: The timestamp when the API call started.

Link IVR to the delivery report

To connect your IVR scenario with backend systems set the clientCallbackData variable. This variable appears in the delivery report and can pass user IDs or other custom identifiers back to your monitoring system.

If you are launching outbound IVR, you can alternatively include this data in your launch parameter called callbackData.

Variable behavior

  • Type: All variables are strings.
  • Nulls: There is no null. If you try to use a variable that has not been set, you get an empty string ("").
  • Expressions: You can use simple expressions, for example, ${digit == '2'} to resolve a pressed digit in an If action.

Best practices

  • Use ${variableName} to reference variables anywhere in your scenario.
  • Built-in variables give you info about the call, for free.
  • All variables are strings. Unset variables return an empty string.
  • You can pass variables when starting calls, set them mid-flow, or get them from API responses.

You can use variables to personalize and automate your call flows, making your IVR scenarios smarter and more connected.

Was this page helpful?