Dynamic Variables during an Inbound Call?
# support
m
Hi all, We're working on a project and use vapi as a solution for this project. I need assistance with a concept: dynamic variables during inbound calls. Goal: A user calls in, before the call is answered by the vapi assistant, the server finds the user's name in a database using the incoming phone number. This name is passed back to vapi so that vapi can greet the caller in the first message as "Hello {{callerName}}! How can i help you today? I have read the dynamic variables documentation as well as the inbound call documentation. The current way i'm doing this is during the initiation of call , vapi send a post request to a server callback url i set up , the server then which responds with the following (attached). But this does not work. The assistant word for word says the first message as: Hello callerName how can i help you today? When the caller name needs to be dynamic. Any idea on how this can be done? Any help would be greatly appreciated. The assistant including the system prompt was all set up through the dashboard. https://cdn.discordapp.com/attachments/1246215202505101332/1246215202681126942/Screenshot_2024-05-31_at_5.31.05_PM.png?ex=665b93d9&is=665a4259&hm=71eb342f91389142acb22db187a5e0ecfd3561cb72572d4cd8d95461a136466c&
v
Hi @MikeKraz, I'm an AI assistant for Vapi. I'll analyze available sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Dynamic Variables]() * [Inbound Calling]() * [Dashboard]() * [Glossary]() -----------------------------
### Answer It seems there might be a slight misconfiguration in how you're utilizing dynamic variables for your inbound calls with Vapi. To ensure the dynamic variable
{{callerName}}
is correctly populated in your assistant's greeting, you should use the
assistantOverrides
parameter to pass the variable values during the call setup. Here's how you can set it up correctly: 1. **Modify your server callback**: Ensure that your server retrieves the caller's name correctly and constructs a response that includes this name as a dynamic variable. 2. **Configure the Vapi call setup**: When setting up the call from your server, pass the caller's name in the
variableValues
of the
assistantOverrides
object. Here is an example of how your JSON payload should look when initiating the call:
Copy code
json
{
  "assistantId": "your-assistant-id",
  "assistantOverride": {
    "variableValues": {
      "callerName": "Retrieved Name"
    }
  }
}
This setup ensures that when the Vapi assistant receives the call, it dynamically inserts the caller's name into the greeting message. For more details on how to use dynamic variables effectively in your scenarios, refer to the Vapi documentation on dynamic variables in calls [(1)]() . If the issue persists after adjusting your setup according to the guidance above, it might be useful to review the exact payload and response data between your server and Vapi to ensure the correct values are being passed and recognized.
Got it. Tagging @User for additional help.
m
Again, this needs to happen during an inbound call and not and outbound that was initiated server side
c
Just putting dynamic variables won't work, espically in instructions. You did not mention where this data is being pulled for it to be dynamic.
m
@Chowderr what do you mean?
The dynamic aspect would be getting the caller's name from a database using the incoming phone number
c
How are you linking the database?
m
thats not the issue. It's a mysql database that will send a response back only after it's been queried
c
So it is linked, but not working?
m
i need to know how can i physically get vapi to understand this assistantOverride with the variableValue
Ok i might have not explained fully, the screenshot above is just an example, driver_name will be populated with an actual value, but even if i hard code it now, it still won't be recoginized by vapi
c
I understand what you are saying (as I already do this).
so it actually doable or is it a restriction on the api level?
and dynamic variable can only be done with outbound calls?
c
It is not restricted at all.
lets assume it is, but still not workin no
@Vapi Support
v
Hmm.. Seems like I didn't receive a question. Please start a new thread with your question.
m
@Vapi Support check above
v
Thanks for the follow-up, @MikeKraz. I'll get back to you soon.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Dynamic Variables]() * [Server URLs]() * [Server Events]() * [Get Call]() -----------------------------
### Answer To correctly implement dynamic variables such as
{{callerName}}
during inbound calls with Vapi, you need to ensure that the dynamic variable is being set appropriately using the
assistantOverrides
functionality as part of the call setup. When Vapi initiates a call and contacts your server URL, your server should respond with the necessary
assistantOverrides
that include
variableValues
. This setup should include the dynamically determined
callerName
. Here's a detailed guide on how you might configure this: 1. **Server Configuration**: Your server should handle the POST request from Vapi and look up the caller's name using the incoming phone number. After retrieving the name, respond with an
assistantOverrides
JSON object that includes the
callerName
variable. 2. **Vapi Call Setup**: Ensure that your call setup JSON includes the
variableValues
with
callerName
correctly set from your server's response. Here’s an example of how your server might respond to Vapi when it sends a POST request to your Server URL:
Copy code
json
{
  "assistantOverrides": {
    "variableValues": {
      "callerName": "John Doe"
    }
  }
}
This response tells Vapi to replace
{{callerName}}
with "John Doe" in the assistant's greeting message. Ensure that your assistant’s first message is configured to use this variable, like so: "Hello {{callerName}}, how can I help you today?" If this setup is correctly implemented but the variable is still not being replaced, it would be beneficial to check the logs for the exact JSON payload being sent to and from Vapi. This will help in identifying if the variable is being passed correctly and whether the assistant configuration on Vapi’s dashboard is set up to utilize this variable appropriately. For more detailed instructions and possibilities with dynamic variables and assistant interactions, refer to the Vapi documentation on utilizing dynamic variables in phone calls [(1)]() .
Got it. Tagging @User for additional help.
c
This is a Transient?
m
Either Select an assistant or Please configure a Server URL in the Accounts Page. Vapi will send 'assistant-request' to your Server URL to fetch assistant. For More information check out https://cdn.discordapp.com/attachments/1246215202505101332/1246294144909967420/Screenshot_2024-05-31_at_10.47.51_PM.png?ex=665bdd5f&is=665a8bdf&hm=aa343ee919d8f9b4a0184ef1a579cbe7945a5af04010751c53b00df2e8de9077&
I don't think it was because i had an assistant selected and i found this written when i deselected it
i assume thats the write track?
s

https://www.youtube.com/watch?v=F57M9ljJkMU

Just check this out; you will understand it.
m
ty!!
31 Views