Best Practices for bringing in dynamic variables -...
# support
o
Hey Discord, I've been struggling to figure out the best practice for adding dynamic variables to a call based on the phone number calling in. I have reviewed the documentation and many YouTube videos, but they all seem scattered, and no one seems to answer the question. In my use case, I have a list of questions that need to be asked based on the customer segment. I have a persistent assistant that is assigned to a phone number - I want to use the same assistant for all calls. Sometimes calls are scheduled and sent outbound, and at other times, they are inbound (or the planned call is missed, and the customer calls back, making it effectively an inbound call). When a call begins, I need to check the number against my database. Depending on the customer segment the caller is from, it should retrieve and return the question set to the agent, allowing them to proceed with the flow. I also need the webhooks to fire at the end to send the final transcript to my endpoint for processing (I'm not sure if transient assistants can do this). Is there a way to use dynamic variables from a function call at call start or something like that? I've seen a bunch of approaches that seem like hacks to me. If anyone has a clean way to approach this, I'd appreciate a push in the right direction. Thanks!
v
Thanks for your detailed question about dynamic variables in Vapi! I understand you're looking for a clean approach to customize call flows based on phone numbers and customer segments. You've mentioned you're using a persistent assistant for both inbound and outbound calls, which is a good approach. I can see you're already familiar with [dynamic variables](https://docs.vapi.ai/assistants/dynamic-variables) and [webhooks for end-of-call reports](https://discord.com/channels/1211482211119796234/1341440757189578782). I have information about using webhooks to send call transcripts at the end of calls, but I'm missing some details about transient assistants and their ability to fire webhooks. Could you clarify if you've already tried implementing a solution using the Server URL approach? With this method, you could: 1. Set up a server endpoint that receives the incoming call information 2. Look up the phone number in your database 3. Return the appropriate dynamic variables with the assistant configuration This would allow you to dynamically set variables based on the caller's phone number without modifying your persistent assistant for each call. Have you explored this approach, or are you looking for a different solution? Sources: - [Dynamic Variables Documentation](https://docs.vapi.ai/assistants/dynamic-variables) - [Webhook End-of-Call Report Discussion](https://discord.com/channels/1211482211119796234/1341440757189578782) - [Server URL Precedence Documentation](https://docs.vapi.ai/api-reference/assistants/create-assistant)
o
@Vapi Support Bot - I already have the in-progress status updates coming to one of my endpoints for my automation, so I'm using the server messages in several different ways. I don't understand the practical application for this use case. A call starts, and my webhook gets pinged. At that point, I can search my database and then return the dynamic variable. What is the format to pass that back? Am I overwriting the entire assistant, or just the assistant override object? Or am I using hooks on callstart? I don't know where (or if) this is documented. It's a very straightforward case that I imagine is being handled by many clients, but I'd love some guidance and best practices to build out a prototype. I can build the dynamic variable into my system instructions for the assistant, I just don't know how to get that data object back to the assistant in a way it can use it in the flow. This is slightly different from a function call, I think, because the data isn't used immediately - it would be used later in the flow.
v
I understand your frustration with finding clear documentation on this specific implementation. You're right that this should be a common use case, and I've searched through our resources but can't find the complete answer to your specific questions about the format for passing dynamic variables back after a call has started. I've escalated your query to our technical team who can provide you with the exact implementation details you're looking for. They'll be able to clarify: - The precise format for passing dynamic variables back after your webhook gets pinged - Whether you're overwriting the entire assistant or just the assistant override object - If hooks on callstart should be used in your scenario - How to ensure the data is available later in the call flow A team member will get back to you with detailed guidance soon. Thanks for your patience, and for providing such a clear explanation of your use case!
k
Hey! To help track down this issue, could you share: - The call ID - When exactly this happened (the timestamp) - What response you expected to get - What response you actually got instead This would really help us figure out what went wrong!
10 Views