Dynamic call transfers

Route calls to different destinations based on real-time conversation context and external data.

Overview

Dynamic call transfers enable intelligent routing by determining transfer destinations in real-time based on conversation context, customer data, or external system information. Unlike static transfers with predefined destinations, dynamic transfers make routing decisions on-the-fly during the call.

Key capabilities:

  • Real-time destination selection based on conversation analysis
  • Integration with CRM systems, databases, and external APIs
  • Conditional routing logic for departments, specialists, or geographic regions
  • Context-aware transfers with conversation summaries
  • Custom business logic execution before completing the transfer
  • Programmatic transfer control via Vapi’s Call Control API

Prerequisites

  • A Vapi account
  • A server or cloud function that can receive webhooks from Vapi
  • (Optional) CRM system or customer database for enhanced routing logic

How It Works

Dynamic transfers with live call control use a server-controlled pattern that gives you maximum flexibility:

  1. User initiates transfer: The user requests a transfer in natural language during the conversation
  2. Vapi triggers custom tool: Vapi fires your custom tool to your HTTP server
  3. Server receives control URL: The tool payload includes message.call.monitor.controlUrl for live call control
  4. Execute business logic: Your server performs any necessary operations:
    • Update CRM records with call summaries
    • Extract and store conversation data
    • Query databases for routing decisions
    • Enrich destination systems with context
  5. Complete transfer: Your server makes a POST request to the controlUrl with the transfer destination
  6. Call connected: Vapi transfers the call to the specified SIP or PSTN destination

Available context: Your server receives the full conversation transcript, custom parameters, call metadata, and the control URL, allowing you to make informed routing decisions and execute the transfer programmatically.

Parameters for custom tools are fully customizable. You can name and structure them however you like to guide routing (for example department, reason, urgency, customerId, etc.).

Sequence diagram


Quick Implementation Guide

1

Create a custom tool for dynamic transfers

Create a custom tool that will receive the transfer request and provide you with the control URL to execute the transfer.

  • Navigate to Tools in your dashboard
  • Click Create Tool
  • Select Custom as the tool type
  • Set function name: transfer_call
  • Add a description: “Transfer the call to the appropriate department or agent”
  • Define custom parameters based on your routing needs (e.g., department, reason, urgency, customerId)
  • Set your server URL to receive the tool call
2

Create an assistant with the transfer tool

  • Navigate to Assistants
  • Create a new assistant or edit an existing one
  • Add your custom transfer tool to the assistant
  • Configure the system prompt to guide when transfers should occur
3

Build your webhook server with Live Call Control

Your server will receive the tool call with message.call.monitor.controlUrl and use it to execute the transfer via Live Call Control.

1import express from 'express';
2import axios from 'axios';
3
4const app = express();
5app.use(express.json());
6
7app.post('/webhook', async (req, res) => {
8 try {
9 const { message } = req.body;
10
11 // Extract control URL from the call monitor
12 const controlUrl = message?.call?.monitor?.controlUrl;
13
14 // Extract tool call from toolWithToolCallList
15 const toolWithToolCall = message?.toolWithToolCallList?.[0];
16 const toolCall = toolWithToolCall?.toolCall;
17
18 if (!controlUrl || !toolCall) {
19 return res.status(400).json({ error: 'Missing required data' });
20 }
21
22 // Extract parameters from the tool call
23 const { department, reason, urgency } = toolCall.function.arguments;
24
25 // Execute business logic (optional)
26 console.log(`Transfer request: ${department} - ${reason} (${urgency})`);
27
28 // Determine destination based on department
29 let destination;
30 if (department === 'support') {
31 destination = {
32 type: "number",
33 number: "+1234567890"
34 };
35 } else if (department === 'sales') {
36 destination = {
37 type: "number",
38 number: "+1987654321"
39 };
40 } else {
41 destination = {
42 type: "number",
43 number: "+1555555555"
44 };
45 }
46
47 // Execute transfer via Live Call Control
48 await axios.post(`${controlUrl}/control`, {
49 type: "transfer",
50 destination: destination,
51 content: `Transferring you to ${department} now.`
52 }, {
53 headers: { 'Content-Type': 'application/json' }
54 });
55
56 // Respond to Vapi (optional acknowledgment)
57 res.json({ success: true });
58
59 } catch (error) {
60 console.error('Transfer error:', error);
61 res.status(500).json({ error: 'Transfer failed' });
62 }
63});
64
65app.listen(3000, () => {
66 console.log('Webhook server running on port 3000');
67});

SIP transfers: To transfer to a SIP endpoint, use "type": "sip" with "sipUri" instead:

1{
2 "type": "transfer",
3 "destination": {
4 "type": "sip",
5 "sipUri": "sip:+1234567890@sip.telnyx.com"
6 },
7 "content": "Transferring your call now."
8}
4

Test your dynamic transfer system

  • Create a phone number and assign your assistant
  • Call the number and request a transfer to different departments
  • Monitor your webhook server logs to see the tool calls and control URL
  • Verify transfers are executing to the correct destinations

Routing Patterns

Common Use Cases

  • Customer support routing - Route based on issue type, customer tier, agent availability, and interaction history. Enterprise customers and critical issues get priority routing to specialized teams.

  • Geographic routing - Direct calls to regional offices based on customer location and business hours. Automatically handle time zone differences and language preferences.

  • Load balancing - Distribute calls across available agents to optimize wait times and agent utilization. Route to the least busy qualified agent.

  • Escalation management - Implement intelligent escalation based on conversation tone, issue complexity, and customer history. Automatically route urgent issues to senior agents.

Transfer Configuration

  1. Warm transfers provide context to receiving agents with AI-generated conversation summaries, ensuring smooth handoffs with full context.

  2. Cold transfers route calls immediately with predefined context messages, useful for simple departmental routing.

  3. Conditional transfers apply different transfer modes based on routing decisions, such as priority handling for enterprise customers.

  4. Destination types include phone numbers for human agents, SIP endpoints for VoIP systems, and Vapi assistants for specialized AI agents.

Security considerations: Always verify webhook signatures to ensure requests come from Vapi. Never log sensitive customer data, implement proper access controls, and follow privacy regulations like GDPR and CCPA when handling customer information in routing decisions.

Troubleshooting

  • Tool call not received: Verify your server URL is correctly configured in the custom tool and is publicly accessible. Check your server logs for incoming requests.
  • Transfer not executing: Make sure that you are sending a valid destination object (type number or sip). See API reference here.
  • Invalid destination format: For phone numbers, use "type": "number" with E.164 format. For SIP, use "type": "sip" with a valid SIP URI.
  • Transfer fails silently: Check your server logs for errors in the axios/httpx request.
  • Call Forwarding - Static transfer options and transfer plans
  • Webhooks - Webhook security and event handling patterns
  • Custom Tools - Build custom tools for advanced routing logic