VAPI forwarding a SIP call to another SIP endpoint
# support
m
We need to pass context from our servers to VAPI and return this context back. The only way I know is to use SIP and pass SIP headers around. But after forwarding our call to a VAPI SIP phone (e.g.
sip:somusername@sip.vapi.ai
), we cannot make VAPI to forward back the call using SIP: https://cdn.discordapp.com/attachments/1329106554041012265/1329106554330550334/vapi-sip-outbound.png?ex=67892270&is=6787d0f0&hm=715fdef6951f247c0eba29b14a34b7c5541c0f02ff6b1cc20bc1188cbf7c0dff&
v
@Manuel Saelices To pass context from your servers to VAPI and ensure that the context is returned back, you can indeed use SIP headers to carry this information. When forwarding a call to a VAPI SIP phone, you can include custom SIP headers to pass the context. However, if you're experiencing issues with VAPI not forwarding the call back using SIP, it's important to ensure that your receiving system is properly configured to handle SIP REFER messages, as VAPI utilizes SIP REFER to transfer SIP calls. If you've confirmed that your system is configured correctly and you're still facing issues, it might be necessary to look into the specific implementation details and any error messages you're receiving. If you need further assistance with this, please provide more details about the problem, and I'll do my best to help you resolve it. If the issue persists, you may need to reach out to support for more in-depth troubleshooting.
You can continue this conversation by mentioning me in the message.
m
@VAPI Tech could you help me?
v
@Manuel Saelices Yes, i can help you.
s
@Manuel Saelices you can try importing your own twilio number and in the payload we forward all of your sip headers as well. Do let me know how it goes.
m
Not sure what do you mean.
s
@Manuel Saelices You can forward the call to another SIP provider, and can pass SIP Headers as well.
Dynamic transfer: For the transfer tool, do not pass any destinations. We will send a transfer destination request to your server url. After that you can return the destination along with the Headers. @Manuel Saelices do let me know if you require further help.
m
How we can instruct the VAPI assistant to forward the call in the payload or prompt?
I tried by adding a SIP target with sip:... URI and it did nothing
s
[1] https://docs.vapi.ai/call-forwarding [Prompt-Instructions] trigger the transferCall tool with [2] > I tried by adding a SIP target with sip:... URI and it did nothing Could you share the call id so I could take a look?
m
@Shubham Bajaj sure. this is an example of failed call:
921d59f4-726b-4f0e-9453-cc32ba9b4496
@Shubham Bajaj is there any news?
s
@Manuel Saelices looking into it.
@Manuel Saelices Could you check your Twilio logs to see what you're getting? The call was transferred from our side, as you can see in the logs (screenshot) for your Twilio call SID. Most likely, you need to enable SIP REFER for your account. https://cdn.discordapp.com/attachments/1329106554041012265/1331522481672159252/Screenshot_2025-01-22_at_12.36.35.png?ex=6791ec72&is=67909af2&hm=4d95c8e80bf8ef9290178f595ba92513ab28653602c2dbdc5f5af396677d5de4&
It seems VAPI needs to add the
referUrl
to the SIP REFER request
s
Hi there, I'm new here please excuse my question if it is not up to the standard. I would like to tell the AI model to say "All calls are recodred for quality and training purposes" but in a machine-like sound, so it feels like a recorded message in a different tone / voice if possible How to do that in VAPI AI model? i use the native VAPI model with blocks, so the first block content is "All calls are recodred for quality and training purposes" Do you recommend another way?
s
Hey @Manuel Saelices you need to add the refer verb within your transfer request by default we don’t add it. Which you can find over here, https://api.vapi.ai/api under TransferDestinationSIP.
Ok, even knowing that the default values are just the ones I wanted, I've manually populated those as you can see in this payload: https://cdn.discordapp.com/attachments/1329106554041012265/1331743489578500176/image.png?ex=6792ba46&is=679168c6&hm=6e97e91390af403506f9f2fb090314c3028927a8785b3c5af4e66d38cc9ce85b&
It's still not working
The VA dashboard seems to be down, but this was the last call I tried:
dee65f9a-b23a-4f72-b47b-7972aa70a1e7
I repeat that it seems to be an error on VAPI's side as VAPI is not passing the
referUrl
, which is very different as the
REFER
verb, which it's passed. @Shubham Bajaj could you please ping to the eng team?
Any news on this?
s
@Manuel Saelices To provide some context, you are routing calls from the Twilio SIP trunk to us via Jambonz. We have instructed Jambonz to send you a SIP REFER to facilitate the call transfer, however, it appears that Twilio may be expecting something that we are not currently providing, which has led us to create this ticket for you. At this juncture, I have a few questions for you: - Is this issue causing any blockage for you? - What specific outcome are you aiming to achieve? - You have the option to import the number to us, so I would like to understand the rationale behind using Elastic SIP Trunking.
m
The need is to pass certain IDs between call legs back and forth. We can pass IDs to VAPI via SIP but, when there is a hand-off, we do need to pass that ID back to us to be able to match the call legs. If we don't use SIP refer, we can't pass any data.
s
@Manuel Saelices You may utilize the transfer-destination-request server event, which allows you to determine the appropriate destination for the call transfer. Additionally, this server event will provide you with SIP headers. Would this information be beneficial to you?
m
How can we identify which call comes to Twilio during a transfer? We need to know that the Twilio call SID CAxyz correspond with a previous call SID CAabc. Is the new Twilio call SID passed as part of the transfer-destination-request payload?
s
@Manuel Saelices Verification Of Context:- 1. First Call to VAPI:    - The initial call (Call Leg 1) is routed to VAPI from Twilio or another SIP provider.    - This call includes a custom SIP header (e.g.,
X-Call-ID
) that carries an identifier (e.g., Twilio Call SID for Call Leg 1, such as CAabc). 2. Second Call (VAPI to Destination):    - VAPI forwards the call to the destination (Call Leg 2), creating a new Twilio Call SID (e.g., CAxyz).    - The relationship between these two call legs needs to be established using the identifier passed in the SIP header (e.g.,
X-Call-ID
). 3. Association Between Call Legs:    - The identifier passed in the SIP header during Call Leg 1 (CAabc) allows the system to associate it with Call Leg 2 (CAxyz). Possible Solution:- 1. Custom SIP Header:    - Pass
X-Call-ID: <unique-id>
in the SIP headers for Call Leg 1. 2. VAPI and Transfer-Destination-Request:    - When VAPI triggers a transfer-destination-request event, your server receives this event.    - The event payload includes the SIP headers, allowing you to extract
X-Call-ID
. 3. Transfer and Correlation:    - Use the extracted
X-Call-ID
to determine the transfer destination.    - After the transfer is completed and Call Leg 2 is established, correlate the new Twilio Call SID (CAxyz) with the original Call SID (CAabc) using the
X-Call-ID
identifier. Notes 1. This approach works because the custom SIP header (X-Call-ID) acts as the bridge between the two call legs. 2. PSTN to SIP transfer is not available,  using Vapi.
@Manuel Saelices correct me here if mistaken to understood your context and issue.
m
That's correct, but what if we receive two calls at aprox the same time from the same origin phone (e.g. an shared office number) to the same destination number, so we create two calls, eg CA001 and CA002. Then, both calls are transferred to us at the same time, so we have two legs CA003, CA004. How we can know if CA003 is the second leg of CA001 or is the CA002 one? And same question for CA004.
If the event does not contain the future CA003 or CA004, we cannot know for sure to match both second legs to their first part of the call
s
@Manuel Saelices Isn't generating truly unique ID for every originating call leg (e.g., UUIDv4) will work for you?
m
I mean the Twilio Call SID. In the POST data for incoming calls in Twilio webhooks, we only have the data sent by Twilio which is Twilio Call SID, from number and destination number. So how can we match those second leg calls from same number to the same number at the same time?
s
@Manuel Saelices a quick call, will get it done?
m
Sure. Could be in five minutes?
I am ready for the quick call
s
@Manuel Saelices check your DM, let's do it over the call.
11 Views