SIP Quickstart
SIP (Session Initiation Protocol) is commonly used for VoIP calling. In this quickstart, you'll create a Twilio SIP Domain, register SIP clients, and place inbound and outbound calls through the PSTN. You'll also get demo users and a prebuilt IVR that routes calls to extensions.
Approximately 20-30 minutes
Before you begin, make sure you have the following:
- A Twilio account.
- A Twilio phone number with Voice capabilities.
- Node.js installed (version 14 or higher) on your local machine.
- A SIP softphone client such as Zoiper or Linphone.
- Basic familiarity with your terminal or command line interface.
A softphone is a software application that lets you make voice calls over the internet using your computer or mobile device instead of a traditional phone. Softphones connect to SIP servers so you can make and receive calls through your SIP account.
Info
This quickstart will use MacOS or Linux commands. Windows users can use Windows Subsystem for Linux (WSL) to run these commands.
The Twilio Command Line Interface, CLI, allows you to interact with the Twilio API from your terminal.
The suggested way to install twilio-cli on macOS is to use Homebrew. If you don't already have it installed, visit the Homebrew site for installation instructions and then return here.
Once you have installed Homebrew, run the following command to install twilio-cli:
brew tap twilio/brew && brew install twilio
Info
For other installation methods, see the Twilio CLI Quickstart.
The Twilio CLI supports plugins, which give you additional control and superpowers. Install the serverless plugin to deploy functions from your local machine.
twilio plugins:install @twilio-labs/plugin-serverless
The serverless plugin initializes an application from a template. The template includes everything you need: the ability to create and register a SIP domain, with demo users, a function that hosts an IVR (Interactive Voice Response) system to route calls to SIP users by extension, a splash page, and much more!
You'll examine the details after the application runs. For now, create your app.
This example names the project the same as the company, acme. If you want to name your project something else, replace acme in the commands below with your desired project name.
twilio serverless:init acme --template="sip-quickstart"
If the command runs successfully, it will look like the following:
1✔ Creating project directories and files2✔ Configuring Environment Variables in .env3✔ Saving README to /path/to/your/project/acme/readmes/sip-quickstart.md4✔ Installing Dependencies5✔ Creating asset: actions.private.js6✔ Creating asset: admin-client.js7✔ Creating asset: admin.css8✔ Creating asset: index.html9✔ Creating asset: shared.private.js10✔ Creating asset: statuses.private.js11✔ Creating asset: extensions.private.js12✔ Creating asset: index.html13✔ Creating asset: site.css14✔ Creating function: admin/check-status.js15✔ Creating function: admin/login.js16✔ Creating function: admin/perform-action.js17✔ Creating function: extension-menu.js18✔ Creating function: outbound-calls.js19✔ Creating function: sip-configuration.js20INFO Make sure to configure APP_NAME,ADMIN_PASSWORD,DEFAULT_SIP_USER_PASSWORD in the .env file21SUCCESS Downloaded new template into the "" subdirectories.22Check readmes/sip-quickstart.md for template instructions.23✔ Downloading template: "sip-quickstart"24✔ Downloading .gitignore file25✔ Installing dependencies26╭──────────────────────────────────────────────────────────────────────────────╮27│ │28│ Success! │29│ │30│ Created acme at /path/to/your/project │31│ │32│ Inside that directory, you can run the following command: │33│ │34│ npm start │35│ Serves all functions in the ./functions subdirectory and assets in the │36│ ./assets directory │37│ │38│ Get started by running: │39│ │40│ cd acme │41│ npm start │42│ │43╰──────────────────────────────────────────────────────────────────────────────╯
Info
If this command fails, make sure you have the latest version of the Twilio CLI and the serverless plugin installed. Then run the command again.
This creates a new folder named acme that contains all of your code.
cd acme
The serverless plugin deploys code from your local machine to the Twilio Serverless platform. Once deployed, your application runs at a publicly accessible URL.
twilio serverless:deploy
This command creates a Service that houses your hosted development environment. The command outputs all the functions and assets deployed to your dev environment.
Run this command whenever you want to make changes to your hosted live development environment.
Info
Note that the URLs are unique to your instance. This will create a new Serverless service and a new development environment.
We understand that you might want to know what is being deployed to your account before doing so. If you want to, you can jump down to the Learn More section to learn more about what functions will be deployed to your account.
Follow these steps to complete the setup of your SIP Domain with demo users:
When you deployed your application, the output presented a list of URLs. Find the URL that ends with /admin/index.html.
- Open the URL in your browser - it will look like:
https://your-service-name.twil.io/admin/index.html - You'll see a password prompt asking you to log in
- Enter the password:
default(this is the initialADMIN_PASSWORDfrom your.envfile) - Click Let me in to access the admin interface
After you log in, a message will say the following: The SIP Quickstart requires that you set up a few things on your account
- Click the button that says Initialize your application for your environment
- Wait for initialization to complete - this process creates:
- A SIP Domain.
- Three demo SIP credentials (
alice,bob,charlie). - A credential list.
- Necessary configurations for your SIP setup.
- The page refreshes and displays a Configuration Checklist.
After initialization completes, the admin interface displays a Configuration Checklist with status indicators showing:
- SIP Domain is created.
- Credential List contains 3 accounts (
alice,bob,charlie). - The default password for the SIP credentials (e.g.,
ThisIs1Password!). - Your incoming phone number.
- Links to the automatically initialized resources.
Note: There is a failing check for the admin password, since you haven't yet changed it from the default. You'll fix that later.
Info
The three demo users (alice, bob, and charlie) come pre-configured with extensions 100, 200, and 300, respectively. You use these usernames and extensions to register your SIP clients and route incoming calls.
There is a splash page that you can now share with your team up and running at /index.html. Open that up in a browser.
This page displays your call in number and your outgoing caller id. Both of these values can be changed on the previous admin page.
You can now register a SIP client with your domain. On this page you'll find a list of users and their registration SIP Domain. By default, the password is the same for all default users and appears on the admin page.
Now let's configure a softphone client to register with your SIP Domain. You can configure all three demo users (alice, bob, charlie) on separate devices or softphone instances.
For the first user (Alice):
- Download and install your chosen softphone client. This tutorial uses Zoiper.
- Open the softphone and select the option to add a new SIP account.
- Enter the SIP credentials:
- Username:
alice - Password: The default SIP user password shown on your admin page (for example,
ThisIs1Password!) - Domain/Server: The SIP Domain shown on the splash page (it looks like
your-service-name.sip.us1.twilio.com) - Transport: UDP or TCP (either works)
- Username:
- Save the configuration and the softphone will attempt to register with your SIP Domain
- Verify registration: You should see a status indicating "Registered" or "Connected"
Warning
Important: Use the correct SIP Domain format. Your SIP Domain must include the .sip.us1.twilio.com suffix (or the appropriate regional suffix). This is the registration endpoint for your SIP clients.
Using only the service name without the SIP-specific domain (for example, your-service-name.twil.io) will not work for SIP registration.
You can check availability in the Twilio Console under the SIP Domains section. If it doesn't work, add an additional identifier to the domain (for example, your-service-name-1234.sip.us1.twilio.com).
For additional users (Bob and Charlie):
Repeat the same process on other devices or softphone instances, using these credentials:
- Bob: Username
bob, Password from admin page, Extension 200 - Charlie: Username
charlie, Password from admin page, Extension 300
Info
All three demo users share the same password by default. You can find this password displayed on the admin Configuration Checklist after initialization. The SIP Domain will be the same for all users.
Once your softphone registers, you can make and receive calls through your Twilio SIP Domain.
Now that you have a softphone configured with your first demo user (for example, alice), let's test the different calling capabilities.
With your softphone registered and connected:
- Open your softphone client (the one you just configured with the
alicecredentials). - Dial any phone number using your softphone (for example, your mobile phone number).
- Press the call button in your softphone to initiate the call.
- Answer the call on your mobile phone - you should see the caller ID that was specified on the admin page.
This demonstrates that your SIP client places calls to the PSTN (Public Switched Telephone Network) through Twilio.
Test receiving calls through your SIP extension:
- From any telephone, call the incoming phone number displayed on your splash page (
/index.html). - Wait for the IVR - you'll hear a prompt asking you to enter an extension.
- Enter extension 100 (which corresponds to the
aliceuser). - Your softphone will ring - answer the call on your softphone to connect.
This shows how the dial-by-extension menu routes incoming calls to your registered SIP clients.
To test direct SIP to SIP calling between extensions, you'll need at least two registered users:
- Set up a second softphone on another device or computer (or use a second softphone instance).
- Register this softphone using different demo user credentials (for example,
bob) - follow the same connection steps from the "Connect your SIP account" section above. - Verify both clients are registered - both should show "Registered" or "Connected" status.
- From the first softphone (registered as
alice), dial the extension number for the other user:- To call Bob: dial
200. - To call Charlie: dial
300.
- To call Bob: dial
- The second softphone (registered as
bob) should ring. - Answer on the second softphone to establish a direct SIP to SIP call.
Extension reference:
- Alice: Extension
100 - Bob: Extension
200 - Charlie: Extension
300
This demonstrates peer-to-peer calling between SIP clients registered to the same domain, without routing through the PSTN.
Info
Make sure both softphone clients are registered and showing as "online" or "registered" before attempting SIP to SIP calls. You can dial users directly by their extension numbers (100, 200, 300).
You should definitely change that admin password. On your local machine edit the file .env.
Find the entry for ADMIN_PASSWORD and change it to something other than default.
ADMIN_PASSWORD=your_secure_password_here
Now make sure your file is saved and then deploy.
twilio serverless:deploy
After deployment, revisit your hosted /admin/index.html page, use your new password, and view your all-green checks.
Info
Anytime you make a change to your example application, remember to save and re-deploy your application.
Now that you've seen things working, you can explore how to further modify and extend this application to suit your needs.
Head over to your local project directory and checkout assets/extensions.private.js.
Info
This file's extension contains .private.js, which for the Serverless plugin prevents public access while allowing other functions to access it.
You'll notice that the demo users have all been added here. You can also add your own users here by following the same sort of format.
Warning
If you do make a change to this file, make sure to navigate to your hosted /admin/index.html and create the additional users automatically.
When you place an outgoing call from a SIP Device, your SIP Domain defines what happens. The Function functions/outbound-calls.js connects to the SIP Domain to handle this.
This function attempts to extract a number and then places a call to the PSTN, setting the callerId attribute on <Dial> TwiML verb. The Caller ID can be changed on your hosted /admin/index.html.
It's important to note too that this function is completely programmable. Explore and feel free to make it behave however you'd like. Remember to re-deploy!
During initialization, the system created a SIP Domain and added demo credentials to a new credential list. The SIP Domain enables registration, and the credential list manages registrants. The SIP API handles all of these operations.
You can locate this information on your hosted Admin page /admin/index.html or in the SIP section under Programmable Voice in your console.
Now that you have a working SIP infrastructure, explore these resources to expand your implementation:
- SIP Overview - Learn more about Twilio's SIP capabilities.
- TwiML Voice: Dial - Deep dive into the Dial verb and its parameters.
- SIP Interface API - Complete API reference for managing SIP domains programmatically.
- Twilio Functions - Learn more about serverless functions.
- SIP Trunking - Connect your existing phone system to Twilio.