How do I forward a Twilio number to a VoIP phone? - twilio

Twilio noob + VoIP noob here, so brace yourself for a double-dumb question.
I have a local Twilio number that currently points to a text-to-speech voicemail greeting. I get a lot of hang-ups (empty voicemail messages), so I would prefer to start routing my incoming calls to a VoIP phone during business hours.
I only have one question about this so far: HOW?

Forwarding voice calls from a Twilio number to a VoIP client.
Example with Zoiper VoIP client (https://www.zoiper.com/).
Twilio configuration
Step 1 - Configure credentials
Log on to your Twilio console (Master Account or switch to a Subaccount), then go to: Programmable Voice >> SIP Domains >> Credential Lists https://www.twilio.com/console/voice/sip/cls
Click on "Create new Credential List"
Remember the username and password, you will need it for Zoiper VoIP client configuration.
Step 2 - Configure SIP domain
Once you've created a credential list, go to Voice SIP Domains https://www.twilio.com/console/voice/sip/endpoints
Click on "Create new SIP Domain"
Enter values for:
FRIENDLY NAME: "My SIP Domain"
SIP URI: "something" (the 'something' has to be some unique name) you will need this something when you configure Zoiper.
then for CREDENTIAL LISTS select "My List" (the one you created on 'Credential Lists'.
also for SIP Registration section, down the page, select ENABLED and again for CREDENTIAL LISTS select "My List"
Don't forget to "Save"
Step 3 - Configure a TwiML Bin
Next, you need to create a TwiML Bin, go to https://www.twilio.com/console/runtime/twiml-bins and let's call it "SipBin" with the folowing code:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Sip>
alex#something.sip.us1.twilio.com
</Sip>
</Dial>
</Response>
Note the alex#something part is alex from when we created the credential list and something from when we created the SIP domain.
Save this bin.
Step 4 - Configure Twilio phone number
Next configure the Twilio phone number, as when a voice call comes in to run the TwiML from the bin. https://www.twilio.com/console/phone-numbers/incoming
Save the phone number configuration. Next, let's configure Zoiper.
Zoiper configuration
Download and install the Zoiper VoIP client app on your smartphone (https://www.zoiper.com/).
Launch the app, click on the "hamburger" menu at top left then go to Settings then to Accounts.
Select the "SIP" tab, then click on the "+" (plus) sign to add an account. It will ask you for a "Username/Login" and a "Password".
Enter the ones you used when you created the credential list at Twilio.
Click the "Login" button, it will take you to next page to enter "hostname or provider".
Enter something.sip.us1.twilio.com, replace something with your name choice when you configured the SIP URI at Twilio.
Click "Next", it will take you to a page regarding "provider/PBX authentication or outbound proxy".
Do not check the box, click "Skip".
On the next page, wait until Zoiper connects to Twilio, it will automatically find "SIP TLS" , it will go green.
You can now click "Finish".
You're done, call your Twilio number and Zoiper will ring.
Update: Outgoing Calls Configuration (only needed at Twilio)
Step 1
To make outgoing calls work you will need to create a second Twilio Bin, let's call it SipBinOut with the folowing code:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="+13335557777">{{#e164}}{{To}}{{/e164}}</Dial>
</Response>
replace +13335557777 with your Twilio number.
After you save the bin, retain (copy) the bin's URL from the Properties section at the top (see picture below).
Step 2
Go to the Sip Domain Configuration page for your SIP Domain (the one where you entered the FRIENDLY NAME and the SIP URI).
In the section for Voice Configuration configure the REQUEST URL, paste the SipBinOut URL from the previous step (keep the method HTTP POST).
Save with the button at the bottom.

Related

How make a direct phone call to exist between two customers using Twilio API

I have this idea where I need to connect customer A (who is hiring) with customer B (who is to be hired) via a direct phone call with just a push of a button, and customer B (who is to be hired) don't want anyone to just have access to his personal phone number (to avoid spam calls).
Well, to make this work I found out that Twilio can handle programmable voice calls which I implemented using ASP.NET Core but that's not exactly what i wanted because customer A (who is hiring) is not allowed to speak directly with customer B (who is to be hired) while the TwiML is at work.
Using Twilio, is there a way for these two customers to communicate via direct calls while hiding the phone number of customer B (who is to be hired) from customer A (who is hiring)? To throw more light to this, on behalf of customer A I want to place a call to customer B's phone number using Twilio's phone number. Any help will be appreciated, thank you.
Twilio developer evangelist here.
You absolutely can connect two customers via a direct call while hiding customer B's number.
I'll give you the very basics first, then suggest some ways to make it more scalable.
To create a number that A can call that will connect A to B you need to buy that number from Twilio and configure it so that when a call comes in to A it returns TwiML that connects to B. For this initial example, you could use a TwiML Bin or some static TwiML that you host. The TwiML needs to use <Dial> and <Number>, like this:
<Response>
<Dial callerID="YOUR_TWILIO_NUMBER">
<Number>Customer B's phone number</Number>
</Dial>
</Response>
Now, when A calls the number they will get connected to B. And if you set the callerId to your Twilio number it will also appear to B to come from your Twilio number, keeping their phone number private too.
Using hard-coded TwiML like this doesn't scale though. You have a few options to improve this.
First, you could have A initiate the call from your application, by clicking a button. That button could trigger a call to A using the REST API and pass it the TwiML above so that when A answers the phone
it then dials B. Like:
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
string twilioNumber = Environment.GetEnvironmentVariable("TWILIO_NUMBER");
TwilioClient.Init(accountSid, authToken);
var call = CallResource.Create(
twiml: new Twilio.Types.Twiml($"<Response><Dial callerId='{twilioNumber}'><Number>CUSTOMER_B_NUMBER</Number></Dial></Response>"),
to: new Twilio.Types.PhoneNumber(CUSTOMER_A_NUMBER),
from: new Twilio.Types.PhoneNumber(twilioNumber)
);
Console.WriteLine(call.Sid);
}
}
Another alternative is to let A call directly from within your application using Twilio Client to make the phone calls from your browser.
To dig a bit deeper, you can also use Twilio Proxy to create a session between the two customers and your Twilio number, creating a connection that would allow either of A or B to call the Twilio number and get connected to the other for the duration of the session. Under the hood Proxy works to automate the delivery of the TwiML described above whilst also maintaining the session between the users until it is done with and the number can be reused by customer A to connect to a new customer. Check out the Proxy quickstart to get a better idea how it works.
Using one of Twilio Proxy or Twilio Client is probably the best for your application, but it depends on the interface you want to provide for your users.

Make voice call using Twilio Client JS, a subaccount and access token

I am trying to make a voice call from a subaccount and keep getting the error:
callerId must be provided for TwilioClient and SIP calls when using Dial
I have verified my application SID, Account SID, api key SID and secret and all match up. The body of the response logged in the Twilio debugger is:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial answerOnBridge="true" callerId="PHONE NUMBER OF PARENT ACCOUNT">
<Number>THE PHONE NUMBER IM TRYING TO CALL (A REAL PHONE)</Number>
</Dial>
</Response>
I cant find anywhere in the docs that show this with the JS library. I have tried setting the From field in the options for Device.connect with no luck.
Do i have to specify anything for the voice grants?
Another odd thing, everything works if I dial from the parent account's number, but When i go and look at the parent account, it doesnt have voice enabled.

Link physical ip phone with Twilio via SIP

I'm attempting to run a physical ip phone with Twillio via SIP and I'm missing something as the connection is not being made. Here is what I've done.
I setup a phone on twilio with incoming voice "A Call Comes In" set to this TwiMLBin:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial answerOnBridge="true">
<Sip>
{{To}}#hcs.sip.twilio.com
</Sip>
</Dial>
</Response>
Then in Programmable SIP Domains I have setup the SIP URI
hcs.sip.twilio.com
I have also set:
Voice Authentication with a credential list of username and password.
Call Control Configuration:
A Call Comes in WebHook to http://demo.twilio.com/welcome/voice HTTP GET
SIP Registration:
Enabled Credential lists: HCS Usr
Then in the phone I have the following settings. Excuse the imgs. Note the myusrid, I actually use an idea, I replaced it just for security reasons.
enter image description here
When I dial the number it says the number has been disconnected.
Any idea what I'm doing wrong?
Make sure your SIP Username (username in credential list) is in E.164 format. So + and then country code. Register using this username.
For example:
+13055551212
Also, check the Debugger in console, to see the errors.

Sip register user in twilio

I'm currently getting the following error:
Your TwiML tried to Dial a Twilio SIP Registered User that is not currently registered
Apparently my SIP Registered user is not being recongized.
In SIP Domains I've created a sip uri
myexample.sip.twilio.com
I then create a credentials list with my username
Example Usr
+13105551212
password
In sip registration I have enabled it with
SIP Registration Authentication using Example Usr
I then have this twiml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial answerOnBridge="true">
<Sip>
{{To}}#myexample.sip.us1.twilio.com
</Sip>
</Dial>
</Response>
I have also tried {{To}}#myexample.siptwilio.com and
+13105551212#myexample.sip.us1.twilio.com
When I dial the number associated with this I get the error mentioned above.
Error - 32009
Dialing SIP Endpoint failure - User not registered
The error also says:
Prior to dialing, you can verify that your SIP Endpoint has successfully registered in the Console "Registered SIP Endpoints" tab found on the SIP Domains page.
When I go to the page "Registered SIP Endpoints" There is nothing on this page, no users listed.
Am I missing a step to register the sip end point? Any idea what I"m doing wrong?
From your previous screenshot, change outgoing call without registration to no. Most likely your SIP Softphone is not registering.

Custom forwarding solution with twilio

I'm new to twilio and I'm struggling with one task. I want to do the following
User A calls a twilio number
User A is asked to type in a specific ID which he got assigned already beforehand by mail
Twilio requests the URL www.mycompany.com/api/twilio/get_recipient_number.php?id=[here the typed in ID] to get the phone number of the recipient
Twilio forwards the caller to the phone number which was provided by the script
Is it possible to do this with twilio? What would be the best way?
Twilio employee here.
Yes, this is possible with Twilio. However you have to do step 3 slightly differently.
Allow me to explain the process step by step:
User A calls your Twilio phone number.
The phone number requests some TwiML that uses the < Gather > tag to gather the digits User A types. You will want to use some TwiML similar to this:
<Response>
<Gather action="/route_after_input.php" finishOnKey="*">
Please enter your 4 digit code and press enter
</Gather>
</Response>
The action url will be called once the * key is pressed. At this URL (do change it from the example above to suit your needs) you can then get the digits type in by inspecting the incoming Twilio request parameter called "Digits"
Use your own code to route the call correctly and return the correct TwiML response.

Resources