Dynamic Variables
Vapi makes it easy to personalize an assistant’s messages and prompts using variables, allowing each call to be customized.
Prompts, messages, and other assistant properties can be dynamically set when starting a call based on templates.
These templates are defined using double curly braces {{variableName}}
.
This is useful when you want to customize the assistant for a specific call.
For example, you could set the assistant’s first message to “Hello, {{name}}
!” and then set name
to John
when starting the call
by passing assistantOverrides
with variableValues
to the API or SDK:
Utilizing Dynamic Variables in Phone Calls
To leverage dynamic variables during phone calls, follow these steps:
-
Prepare Your Request: Construct a JSON payload containing the following key-value pairs:
assistantId
: Replace"your-assistant-id"
with the actual ID of your assistant.assistantOverride
: This object is used to customize your assistant’s behavior.variableValues
: An object containing the dynamic variables you want to use, in the format{ "variableName": "variableValue" }
. For example,{ "name": "John" }
.
customer
: An object representing the call recipient.number
: Replace"+1xxxxxxxxxx"
with the phone number you wish to call (in E.164 format).
phoneNumberId
: Replace"your-phone-id"
with the ID of your registered phone number. You can get it from the Phone number in the dashboard.
-
Send the Request: Dispatch the JSON payload to the
/call/phone
endpoint using your preferred method (e.g., HTTP POST request).
Note: You will need to add the {{variableName}}
in this format in all your prompts, whether it is the first message or anywhere else you want to use it.
Default Variables
By default, the following variables are automatically filled based on the current (UTC) time,
meaning that you don’t need to set them manually in variableValues
:
Advanced Date and Time Usage
We use LiquidJS for dynamic variables. You can use the date
filter to format the date and time in the timezone you want.
This should return the current date and time in New York.