Can't pass in Template Variables through SIP heade...
# support
s
I am following these guidelines https://docs.vapi.ai/advanced/calls/sip#1-create-an-assistant to pass variabels through SIP headers. See screenshot of the agent and code below: I would expect the agent to say "Hello bar" but it doesn't seem to have the variable. I
Copy code
const options = {
      method: "POST",
      headers: {
        Authorization: `Bearer ${vapiToken}`,
        "Content-Type": "application/json",
        "x-foo": "bar",
        ...dynamicVariablesHeaders,
      },
      body: JSON.stringify({
        provider: "vapi",
        sipUri: `sip:${callId}@sip.vapi.ai`,
        assistantId: agentId,
      }),
    };
    try {
      const response = await fetch(`${this.vapiUrl}/phone-number`, options);
      if (!response.ok) {
        const errorData = await response.json();
        console.error(
          `Failed to create sip uri for call ${callId}: ${JSON.stringify(errorData)}`,
        );
        throw new Error(
          `vapi sip uri creation failed: ${errorData.message || "Unknown error"}`,
        );
      }
      const data = await response.json();
      const { sipUri } = data;
      return sipUri;

///somewhere else in the codebase: 

        const voiceResponse = new VoiceResponse();
        const dial = voiceResponse.dial();
        console.log(`Dialing ${sipUri} for call ${callId}`);
        dial.sip(sipUri);
        res.set("Content-Type", "text/xml");
        res.send(voiceResponse.toString());
https://cdn.discordapp.com/attachments/1296944697666703360/1296944697968689183/CleanShot_2024-10-18_at_14.13.522x.png?ex=67142160&is=6712cfe0&hm=a3ebb611b2ac839931f3cb78149d9312c58760446d2cd6bf2bcda4a27b3c373d&
v
@Seb It looks like you're trying to pass a custom SIP header (
x-foo
) with a value (
bar
) to your VAPI assistant. If the assistant is not saying "Hello bar" as expected, there might be an issue with how the variable is being retrieved or used within the assistant's logic. To help you further, I would need to see the part of the code or configuration where the assistant is supposed to use the
x-foo
header value. However, here are a few things you can check: 1. Ensure that the assistant logic is designed to read the
x-foo
SIP header and use its value in the response. 2. Verify that the header is being sent correctly in the SIP INVITE request. 3. Check if there are any logs or debugging information that can provide insight into why the variable is not being used. If you have access to the assistant's configuration or code, please provide the relevant section where it handles the SIP headers. Otherwise, if you need assistance with the server-side logic that should respond with the assistant's configuration, please let me know, and I can guide you through that process.
You can continue this conversation by mentioning me in the message.
Got it. Tagging @User for additional help.
s
SIP header should originate from where you are trying to connect the SIP
also sip doesn't support POST or something like that
SIP is completely a different protocol just like HTTP
and all that
s
ah now i get it
thx
but how would I do that if I am connecting with twilio?
read this
s
thanks a ton!!
One more unrelated question, does Vapi charge the 5ct per minute if I forward the call (using the CallTransfer tool). Since I am using my own twilio I would assume that once the call is transferred I only pay the twilio costs and not the additional 5ct/min for vapi?
s
yeah once call is transfered you won't be paying for 5ct/min.
7 Views