Register SIP account and receive calls with Twilio


Living across three different countries necessitates maintaining local phone numbers in each for various purposes, including 2FA, e-signatures, and general communication. While I don’t use all SIM cards simultaneously, receiving calls on these numbers remains important.

Previously, I managed this with a self-hosted Asterisk PBX on a VPS. However, to reduce maintenance overhead, I decommissioned it and transitioned to Twilio for managing my Direct Inward Dialing (DID) numbers, which were originally sourced from various providers.

Twilio provides several methods for call handling, with TwiML (Twilio Markup Language) being a flexible option. This post details how to use TwiML to register a SIP softphone and receive inbound calls.

Important Note on Regional POPs (Points of Presence): As of July 2023, Twilio offers POPs in the EU (region ie1), USA (region us1), and Australia (region au1). My experience indicates that full feature support, particularly for certain SIP dialing scenarios within TwiML, might be more straightforward or consistently available with the US POP (us1). I encountered difficulties (specifically error “32002: Your TwiML tried to Dial a Twilio SIP Domain that can’t be found”) when attempting to use TwiML to dial a SIP endpoint registered in the EU zone (ie1) from a number also configured within the EU. If you have successfully configured such a scenario using an EU POP, please share your insights. For the purposes of this guide, focusing on the us1 region for TwiML Bins and SIP domain configuration is recommended if you encounter similar issues.

Here are the steps to set up Twilio for SIP registration and inbound call handling:

  1. Create a SIP Credentials List: Navigate to SIP Credentials Lists in the Twilio console. Create a new list and add a username and password. This list will be used to authenticate your SIP softphone.
  2. Create a SIP Domain: Go to SIP Domains. Create a new SIP domain with a unique name (e.g., yourusername.sip.twilio.com). Enable SIP registration and associate the credentials list created in the previous step. Configure other settings like encryption as needed. Ensure you are creating this in the desired region (e.g., us1 for broader compatibility, or ie1 if you are specifically targeting the EU and are aware of potential limitations).
  3. Create a TwiML Bin: Go to TwiML Bins. Create a new TwiML Bin with the following content. Replace USERNAME with the username from your credentials list and YOURDOMAIN.sip.twilio.com with your actual SIP domain. Adjust the region parameter in the <Sip> noun if necessary (e.g., to us1 or au1).
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <!-- Say>Hello from Twilio!</Say -->

  <Dial answerOnBridge="true" sequential="true" ringTone="lt" record="record-from-answer-dual" trim="trim-silence">
    <Sip>sip:USERNAME@YOURDOMAIN.sip.twilio.com;region=us1</Sip> <!-- Example using us1 region -->
  </Dial>

  <!-- Example of Simultaneous Dialing (Optional) -->
  <!--
  <Dial answerOnBridge="true" ringTone="es" record="record-from-answer-dual" trim="trim-silence">
    <Sip>sip:USERNAME@YOURDOMAIN.sip.twilio.com;region=us1</Sip>
    <Number>+YOUR_OTHER_PHONE_NUMBER</Number>
  </Dial>
  -->

  <Say>Hello, the person you are trying to reach is unavailable. Please leave a message at the beep.</Say>

  <Record timeout="30" transcribe="true" playBeep="true"/>
  <Hangup/>
</Response>
*Note: The example above shows sequential dialing to one SIP endpoint. You can modify this for simultaneous dialing or other call flows. Ensure the SIP URI is correctly formatted (`sip:username@domain`).*
  1. Configure Phone Number: Purchase a DID number from Twilio Phone Numbers. In the number’s configuration, under “A CALL COMES IN,” select “TwiML Bin” and choose the Bin you created.
  2. Configure SIP Client: Download and configure a SIP client (e.g., Groundwire by Acrobits, Zoiper, Linphone). Use the username and password from your credentials list and your SIP domain (e.g., YOURDOMAIN.sip.twilio.com) for registration.
  3. Test Inbound Calls: Make a test call to your Twilio DID number. If issues arise, check the Twilio Debugger logs for errors.

Once everything is set up and tested, you can redirect your existing mobile phone numbers to your new Twilio DID number using your mobile carrier’s call forwarding feature (e.g., by dialing *21*+YOUR_TWILIO_NUMBER# on your mobile phone, though the exact code may vary by carrier).