Tool calling
# support
s
How can I execute a function at call start, for example search client data from a db as soon as the call starts to pass it as context
v
@Sergio S To execute a function such as searching client data from a database at the start of a call, you would typically need to integrate that function into the call flow. This can be done by setting up an assistant configuration object that includes the necessary steps to perform the database search and then pass the resulting context to the call. Here's a general outline of how you might set this up: 1. Define a function that searches the client data from the database. 2. Create an assistant configuration object that includes a step to call this function at the start of the call. 3. Use the .start() function with the assistant configuration object to initiate the call. For example:
Copy code
javascript
// Define your database search function
function searchClientData(clientId) {
  // Your code to search the database goes here
  // Return the client data or context needed for the call
}

// Create an assistant configuration object
const assistantConfig = {
  onCallStart: () => {
    const clientData = searchClientData(clientId);
    // Pass the client data as context for the call
    return clientData;
  },
  // ... other configurations for your assistant
};

// Start the call with the assistant configuration
.start(assistantConfig);
Please note that the actual implementation details will depend on your specific database and how you've set up your assistant. If you need more detailed guidance or if you have a specific function you want to execute, please provide more information or ask support for more info on this.
You can continue this conversation by mentioning me in the message.
s
But it is an inbound call @Vapi
v
@Sergio S For an inbound call, you would typically set up your Voice API to trigger a function that searches for client data as soon as the call is connected. Here's a high-level approach to handle this: 1. Configure your Voice API to listen for inbound calls. 2. When an inbound call is detected, extract the caller's phone number or any other identifier provided. 3. Immediately call the function that searches the client data from the database using the extracted identifier. 4. Once the data is retrieved, pass it as context for the duration of the call to personalize the interaction. If you have a specific function ready to be called, please provide the details, and I can assist you with the next steps. If you need to set up such a function or require further assistance with the configuration, please ask support for more info on this.
s
Do you have code examples of how to use Dynamic variables? @Vapi
c
How come you just dont pass that data instead of calling it? You already have the data - put it in a variable.
s
use server event of type request assistant to pass the required data right before the call using assistant overrides. for more check https://docs.vapi.ai
2 Views