Rinshin
04/11/2025, 10:13 AMVapi Support Bot
04/11/2025, 10:14 AMX-Call-ID: <unique-id>
in the SIP headers for the first call leg, which can then be used to associate calls and trigger your API.
### 2. Using Twilio as an Intermediary
A practical approach is to use Twilio to intercept calls before they reach Vapi:
It is possible to accomplish this without importing the phone number to VAPI. Twilio will send a request to your server URL, after which you will need to forward the calls to the VAPI API
There's a reference implementation available at [this GitHub repo](https://github.com/VapiAI/advanced-concepts-phone-call-provider-bypass) that shows how to set this up.
### 3. Personalizing the Conversation with the Data
Once you've fetched the customer data, you can personalize the conversation in several ways:
1. **Inject data into the system message**:
json
{
"assistant": {
"model": {
"provider": "openai",
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You're a support assistant. Customer info: [YOUR FETCHED DATA HERE]"
}
]
}
}
}
2. **Using dynamic variables**:
json
{
"variableValues": {
"name": "CustomerNameFromAPI",
"plan": "CustomerPlanFromAPI"
}
}
3. **Setting the customer field when creating a call**:
```javascript
const call = await vapiClient.calls.create({
phoneNumberId: "your-phone-number-id",
customer: {Vapi Support Bot
04/11/2025, 10:14 AMShubham Bajaj
04/11/2025, 8:22 PMShubham Bajaj
04/11/2025, 8:23 PMjavascript
// Example with Express.js
const express = require('express');
const app = express();
app.use(express.json());
app.post('/vapi-webhook', async (req, res) => {
// The webhook payload contains information about the incoming call
const { message } = req.body;
if (message.type === 'assistant-request') {
try {
// Extract the caller's phone number
const callerNumber = message.customer?.number;
if (!callerNumber) {
return res.json({
messageResponse: {
assistantId: "YOUR_ASSISTANT_ID", // Your existing assistant ID
error: null
}
});
}
// Fetch customer data from your database using the caller's number
const customerData = await fetchCustomerData(callerNumber);
// Return the assistant configuration with customer data as variables
return res.json({
messageResponse: {
assistantId: "YOUR_ASSISTANT_ID", // Your existing assistant ID
assistantOverrides: {
variableValues: {
// Add all your fetched customer data as variables
customer_name: customerData.name,
customer_plan: customerData.plan,
customer_status: customerData.status,
// Add any other relevant customer data
is_premium: customerData.isPremium,
last_interaction: customerData.lastInteraction
}
}
}
});
} catch (error) {
console.error('Error fetching customer data:', error);
// If there's an error, still proceed with the call but without custom data
return res.json({
messageResponse: {
assistantId: "YOUR_ASSISTANT_ID"
}
});
}
}
// Handle other webhook types if needed
res.json({ messageResponse: {} });
});
// Function to fetch customer data from your database
async function fetchCustomerData(phoneNumber) {
// Implement your database query here
// Return customer data object
}
app.listen(3000, () => {
console.log('Webhook server running on port 3000');
});
Shubham Bajaj
04/11/2025, 8:23 PMYou are a helpful customer service agent for {{company_name}}.
Customer Information:
- Name: {{customer_name}}
- Plan: {{customer_plan}}
- Status: {{customer_status}}
- Premium Customer: {{is_premium}}
- Last Interaction: {{last_interaction}}
Use this information to provide personalized service, but don't explicitly tell
the customer you have this data unless they ask for confirmation.
### Step 4: Deploy Your Webhook
1. Deploy your webhook to a publicly accessible URL
2. Ensure it has HTTPS (required by VAPI)
3. Update your VAPI configuration with this URL
## How This Works:
1. A customer calls your VAPI phone number
2. VAPI sends an "assistant-request" webhook to your server
3. Your server extracts the caller's phone number from the webhook
4. Your server queries your database for customer information
5. Your server returns this data as part of the assistant configuration
6. VAPI uses this configuration and data when connecting the call to the AI agent
7. The AI agent has access to the customer data in its variables
This approach allows you to provide personalized context to the AI agent without requiring the caller to identify themselves again, creating a much smoother customer experience.