Search code examples
twiliotwilio-twiml

Twilio SIP: Making Outbound Calls


I have successfully set up a Cisco VOIP phone to register with Twilio via SIP

I have created a SIP domain, authenticated, and the phone is registered

I have set up a TwiML Bin that looks like:

<Response>
   <Dial callerId="+44203XXXXXXX">
          {{To}}
  </Dial>
</Response>

But I get an error:

Dial: Invalid phone number.
The area code or local exchange code of the phone number does not appear to be valid

And in the error the Request Body looks like:

<Response>
    <Dial callerId="+44203XXXXXXX">
          sip:[email protected]
  </Dial>
</Response>

However I think that the Request Body should look like:

<Response>
    <Dial callerId="+44203XXXXXXX">
          +44170XXXXXXX
  </Dial>
</Response>

How can I change the TwiML to dial just the phone number?


Solution

  • Twilio developer evangelist here.

    As you've discovered, the To parameter that a SIP phone delivers to the Twilio endpoint is not a phone number but a SIP address with a phone number embedded within.

    TwiML Bins aren't currently smart enough to extract that phone number using the templating functions. So, to do this you will need to host a small application that can rewrite the To parameter into a phone number.

    We have an example application, written in Python and deployable to Heroku (or wherever you want really), that does this already for you. Check out the code here and read about how to use it here.

    Let me know if that helps at all.