Use custom function result as transfer number
# support
a
callid: 85fcdf27-3f6a-4792-a6ff-9b2ae6c258f2 Have a custom function that retrive phone number for a contact: transfer_destination_request After the query is done need to use the number/result to make the sip transfer, i see the REFER appear on the call, but variable is not replaced. Refer-To: <sip:{{transfer_destination_request.result}}@mydomain but transfer call seems to be getting it ok { "role": "tool_calls", "time": 1759145363628, "message": "", "toolCalls": [ "0": { "id": "call_Jj2CkWlQyLQ6Hn22cJBOH8mp", "type": "function", "function": { "name": "transfer_call", "arguments": "{\"destination\": \"sip:+34XXXXXXXXX@myomain\"}" } } ], "secondsFromStart": 30.968 } #1211483291191083018 #transfer_call
v
To ensure the transfer number is correctly used, your webhook for the
transfer-destination-request
event should return the resolved SIP URI directly, not a template variable. Here’s a sample response structure:
Copy code
json
{
  "destination": {
    "type": "sip",
    "number": "+34XXXXXXXXX",
    "sipUri": "sip:+34XXXXXXXXX@mydomain"
  }
}
Make sure your backend replaces the variable with the actual number before sending this response to Vapi, so the REFER header is populated correctly. Reference: [Vapi dynamic transfer docs](https://docs.vapi.ai/calls/call-dynamic-transfers#build-your-webhook-server) Source: - [Dynamic call transfers | Vapi Docs](https://docs.vapi.ai/calls/call-dynamic-transfers#build-your-webhook-server)
a
a reply like these for example "results": [ { "toolCallId": "call_Q1MYlwGnFkTsLvW2fDTXjFRM", "result": { "destination": { "type": "sip", "number": "+34XXXXXXXX", "message": "Transferring you to Contact", "sipUri": "sip:+34XXXXXXXX@myadomain" } } } ]
{ "name": "transfer_destination_request", "role": "tool_call_result", "time": 1759148267659, "result": { "destination": { "type": "sip", "number": "+34XXXXXXXX", "sipUri": "sip:+34XXXXXXXX@mydomain", "message": "Transferring you to Contact." } }, "metadata": {}, "toolCallId": "call_Q1MYlwGnFkTsLvW2fDTXjFRM", "secondsFromStart": 22.738 } but transfer_call use no arguments "role": "tool_calls", "time": 1759148268219, "message": "", "toolCalls": [ "0": { "id": "call_fWB90WyN2sJiQx3x7ZemKxT1", "type": "function", "function": { "name": "transfer_call", "arguments": "{}" } } ], "secondsFromStart": 23.298 } { "name": "transfer_call", "role": "tool_call_result", "time": 1759148268222, "result": "No transfer destination returned.", "toolCallId": "call_fWB90WyN2sJiQx3x7ZemKxT1", "secondsFromStart": 23.301 }
v
It looks like your transfer_call is firing before the transfer_destination_request result is actually injected, which is why you see {} instead of the SIP URI. In VAPI, you need to make sure the tool result is passed as an argument, for example {"destination": result.sipUri}. I’ve worked with similar setups where the REFER header was showing placeholders until the mapping was corrected. A quick check is whether your workflow explicitly maps the function result to the transfer_call input. How are you currently chaining the tool outputs into the next function? @adriaVidal
c
Hi adriaVidal, The issue appears to be related to variable replacement in SIP headers during transfers. For assistant-based warm transfers, you should structure the transfer configuration explicitly rather than relying on direct variable interpolation in the SIP headers. Here's how you can properly configure the transfer after getting the destination from your custom function:
Copy code
{
  "type": "transferCall",
  "function": {
    "name": "warmTransferAssistant"
  },
  "destinations": [
    {
      "type": "sip",
      "sipUri": "${transfer_destination_request.result}@mydomain",
      "transferPlan": {
        "mode": "warm-transfer-experimental",
        "transferAssistant": {
          "firstMessage": "Hi, I have a customer waiting. Are you available?",
          "maxDurationSeconds": 120,
          "model": {
            "provider": "openai",
            "model": "gpt-4o",
            "messages": [
              {
                "role": "system",
                "content": "You are handling a warm transfer. Check if the operator is available."
              }
            ]
          }
        }
      }
    }
  ]
}
The transfer destination should be set programmatically after your custom function returns the result, rather than trying to interpolate it directly in SIP header If this doesn’t resolve the issue, please let us know and we’ll be happy to step in and assist further.
a
varibles seem to not be passed to the transfer_call tool, had to make it fixed
c
Let me check for more specific information about variables and call transfers. Based on searching the documentation, I can explain what's happening with variable passing in call transfers. Here are the key points: 1. Call Transfer Variables: - Variables can be extracted and passed during call transfers using a
variableExtractionPlan
[1](https://docs.vapi.ai/call-forwarding) - The extracted variables are available to all subsequent assistants in the conversation chain 2. Configuration: You can set up variable extraction in two ways: - Through the destination configuration:
Copy code
{
  "destinations": [
    {
      "type": "assistant",
      "assistantName": "support-assistant",
      "variableExtractionPlan": {
        "schema": {
          "type": "object",
          "properties": {
            "customerName": {
              "type": "string"
            },
            "issue": {
              "type": "string"
            }
          }
        }
      }
    }
  ]
}
- Through the tool function parameters (which will also be sent as variables) If you're having issues with variables not being passed, make sure that: 1. You have properly configured the
variableExtractionPlan
in your transfer tool 2. The schema correctly defines the variables you want to extract 3. The variables are properly formatted according to the schema Let me know if you need help with specific variable passing configurations!
4 Views