Proxy Public Beta is currently closed for new customers. Please consider using Twilio Conversations and Programmable Voice directly if you are building your masking application.
Note that this does not have any impact on Twilio Flex customers.
Twilio's Proxy API is currently available as a Public Beta product. Some features are not yet implemented and others may be changed before the product is declared as Generally Available.
Public Beta products are not covered by a Twilio SLA.
With just a few lines of code, you can have a text and/or voice conversations between two cloaked participants.
In this Quickstart, you will learn how to:
To test this quickstart, make sure you have two phone numbers you wish to connect ready to go (perhaps two cell phones?).
The first thing you need in order to set up a proxied session is a Twilio-powered phone number. You can grab one to use in the console here.
Make sure that it has SMS and/or Voice enabled for the purposes of this quickstart. Note that in many countries, numbers will only have either Voice or SMS capability; to test both features you will need both types in your number pool. US and Canadian numbers will have both capabilities.
You'll want at least two phone numbers in your Proxy pool.
Once you buy your preferred numbers, make a note of the Twilio string identifier (SID) of the number. You'll need it for this quickstart.
You can find these in the Twilio Console.
For all of our code snippets and curl examples, you will need to authenticate with the Account SID and Auth Token.
The next steps will involve writing some code. We've provided examples in multiple languages, but you will need a working development environment in at least one of them. Here are some guides we've written to help you get your Twilio development environment up and running:
We also provide examples for the curl command line which should work from a Linux or macOS terminal.
Note: You can also create Services via the console for Proxy.
Let's create a service that will contain our sessions:
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createService() {11const service = await client.proxy.v1.services.create({12uniqueName: "unique_name",13});1415console.log(service.sid);16}1718createService();
1{2"sid": "KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"chat_instance_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"unique_name": "unique_name",6"default_ttl": 3600,7"callback_url": "http://www.example.com",8"geo_match_level": "country",9"number_selection_behavior": "prefer-sticky",10"intercept_callback_url": "http://www.example.com",11"out_of_session_callback_url": "http://www.example.com",12"date_created": "2015-07-30T20:00:00Z",13"date_updated": "2015-07-30T20:00:00Z",14"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",15"links": {16"sessions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions",17"phone_numbers": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers",18"short_codes": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes"19}20}
Take a note of the service SID (KSxxxx
) that you get as a response.
We need to associate the number(s) we bought with our newly created service. The phone numbers you add will be added to the anonymous number pool for your proxied communications.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createPhoneNumber() {11const phoneNumber = await client.proxy.v112.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.phoneNumbers.create({ sid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" });1415console.log(phoneNumber.sid);16}1718createPhoneNumber();
1{2"sid": "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",5"date_created": "2015-07-30T20:00:00Z",6"date_updated": "2015-07-30T20:00:00Z",7"phone_number": "+1987654321",8"friendly_name": "Friendly Name",9"iso_country": "US",10"capabilities": {11"sms_outbound": true,12"voice_inbound": false13},14"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",15"is_reserved": false,16"in_use": 017}
This adds a single number to the Proxy pool. Repeat for each of your Twilio phone numbers
A session is a conversation between two people. This code will create a new session in your Proxy service.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createSession() {11const session = await client.proxy.v112.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.sessions.create({ uniqueName: "MyFirstSession" });1415console.log(session.sid);16}1718createSession();
1{2"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",3"status": "open",4"unique_name": "MyFirstSession",5"date_started": "2015-07-30T20:00:00Z",6"date_ended": "2015-07-30T20:00:00Z",7"date_last_interaction": "2015-07-30T20:00:00Z",8"date_expiry": "2015-07-30T20:00:00Z",9"ttl": 3600,10"mode": "voice-and-message",11"closed_reason": "",12"sid": "KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",13"date_updated": "2015-07-30T20:00:00Z",14"date_created": "2015-07-30T20:00:00Z",15"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",16"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",17"links": {18"interactions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Interactions",19"participants": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants"20}21}
Note the session SID (KCxxxx
) from the response you get.
You can't have a good conversation without participants, so let's add some.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createParticipant() {11const participant = await client.proxy.v112.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.sessions("KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")14.participants.create({15friendlyName: "Alice",16identifier: "+15558675310",17});1819console.log(participant.proxyIdentifier);20}2122createParticipant();
1{2"sid": "KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"session_sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",4"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",5"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",6"identifier": "+15558675310",7"proxy_identifier": "+14155559999",8"proxy_identifier_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",9"friendly_name": "Alice",10"date_deleted": "2015-07-30T20:00:00Z",11"date_updated": "2015-07-30T20:00:00Z",12"date_created": "2015-07-30T20:00:00Z",13"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",14"links": {15"message_interactions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/MessageInteractions"16}17}
Run it again with a second participant (a different phone number for another proxied user, and a different 'Friendly Name').
For each participant, you'll receive a response with the participant's assigned Proxy number, which will come from the pool of numbers you've added. Depending on the capabilities of the phone number, next either send a text message in the conversation or make a voice call.
If your number has text messaging capabilities, you're ready to roll! If you're looking at a voice proxy, skip to the next section.
Let's send a message from one of the assigned Proxy numbers to one of the participants. Execute the following for one of the participants (the participant you'd like to receive this initial message):
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createMessageInteraction() {11const messageInteraction = await client.proxy.v112.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.sessions("KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")14.participants("KPXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")15.messageInteractions.create({ body: "Reply to this message to chat!" });1617console.log(messageInteraction.sid);18}1920createMessageInteraction();
1{2"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",3"data": "{\"body\":\"some message\"}",4"date_created": "2015-07-30T20:00:00Z",5"date_updated": "2015-07-30T20:00:00Z",6"participant_sid": "KPXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",7"inbound_participant_sid": null,8"inbound_resource_sid": null,9"inbound_resource_status": null,10"inbound_resource_type": null,11"inbound_resource_url": null,12"outbound_participant_sid": "KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",13"outbound_resource_sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",14"outbound_resource_status": "sent",15"outbound_resource_type": "Message",16"outbound_resource_url": null,17"sid": "KIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",18"type": "message",19"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants/KPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/MessageInteractions/KIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",20"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",21"session_sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"22}
And with that, the Proxy text conversation can continue!
If your Twilio Phone Numbers are voice capable, you're now ready for a proxied voice conversation. Following the names from the previous steps, get Alice to make a call to her Proxy Identifier number. Twilio's Proxy service will then make a call from Bob's Proxy Number to his real number and connect the two calls.
Now you're talking anonymously!
If voicemail is enabled for your real number, your outgoing voicemail message may reveal your real number to people who call your proxied number.
Review your outgoing voicemail message to ensure that it does not include your real number. Remember that many default voicemail messages begin by stating the number that the person has reached.
You now know how to create text and/or voice conversations between two masked participants. To learn more about how Proxy works check out the guide to Phone Number Management or dive into the REST API reference.