Twilio number as voicemail - receive forwarding number as callerid - twilio

I am building an application where a user will call our clients personal phonenumber. His voicemail is set one of our Twilio numbers.
Is there a way to find out which client forwarded the call to us?
I am using a TwiML app with our API as webhook.
I successfully receive the calls and see the phonenumber of the caller as 'from' and 'caller' and our 'twilio' number as 'to'.
Since it is a forwarded call I would expect the 'caller' should be the clients number, 'from' the caller and 'to' our twilio number, or at least both 'caller' and 'from' should be the client rather than the original caller. However, both 'from' and 'caller' are always the number of the original caller.

One option is to provision a phone number for each client. That way each client will forward calls into a unique phone number that only they use. If you have 10 clients you will have 10 Twilio phone numbers. Each of those provisioned numbers will use your same TwiML app w/ API as webhook. This is described in this "How to Build a Call Tracking Solution".

Related

Transfer call from SIP trunk to Twiml application

I have a phone number registered in Twilio that I wanted to use for both a Twiml application and an Elastic SIP Trunk (connected to Asterisk). The idea is that inbound calls hit the Twiml app first and then can be forwarded to the Asterisk server if needed, while outbound calls just go via the SIP trunk. (The reason it needs to be a SIP trunk instead of simply using SIP Registration with Programmable Voice is because that is the only way to have E911 support for outbound calls.)
Twilio support told me that it is not possible to use the same number for both.
Because of that limitation, my current plan is to use two Twilio phone numbers. My published phone number will go to the Twiml application, and a second number that I will not give out will go to the SIP Trunk. (Twilio allows number spoofing of other numbers on your account, so I will have the Asterisk server pretend to use my primary number for outbound calls instead of using the second private number.)
In order for this to work, I need to be able to transfer calls from my Twiml app to Asterisk and from Asterisk server back to the Twiml application. The former is easy: just use <Dial> with a SIP URL that points to the trunk. The latter is what I need help with. (I also want to do this in case someone does manage to call the second number - I want them to be redirected to the Twiml app.)
As far as I can tell, the only way for me to transfer calls back into my Twiml application is to forward the call from the Asterisk server back to my public number. The problem is that I think this will look like an outgoing+incoming call and I will get double-billed for these minutes. I'm already paying for another number, and I really don't want to have to pay extra for the minutes too.
Is there a better (or "official") way to transfer a call back to the Twiml app? Or am I wrong about Twilio seeing (and billing) this as two calls?
It is not clear why you cannot use the Twilio number for both a Twiml application and an Elastic SIP Trunk (connected to Asterisk). Did they indicate why?
Just don't assign that particular number to your Elastic SIP Trunk and you should be able to assign it to your TwiML application for inbound calls and use a when you want to forward the the call to your Asterisk PBX.
For outbound calls, you can have you Asterisk PBX send calls with that number as CallerID to your Elastic SIP Trunk Termination URI.
For E911 calls from the Twilio Elastic SIP Trunk, you should have a number associated with your Elastic SIP Trunk, enabled for Emergency Calling, so when 911 calls are placed, the CallerID of that number is used for outbound calls and calls can be returned to that number should the connection get disconnected.
If you did go the second route you mentioned, can you have your Asterisk Server send the call to a Twilio Programmable Voice SIP Domain, maybe have a Dial Plan defined so an Asterisk prefix digit sends calls out this different trunk. Not sure this will work (since mixing Elastic SIP Trunking with Programmable Voice in this manner) but one idea. Your Asterisk server will remain in the call path.

twilio master account make outbound call with subaccount validated number

I need to make outgoing calls from browser and i set capability token with the master account.
Then i make a call request to twilio from browser and return a twiml from my server.
In the twiml, i set the callerId to a subaccount validated outgoing phone number.
When dial to another client, it works fine. But, if dial to a phone number it not work.
From the debugger i saw this error:
it said callerId must be provided for TwilioClient and SIP calls when using Dial.
I dont know why, I need a help.

Twilio Opt-In/Opt-Out API

I am working on an Opt-In /Opt-Out api that integrates with Twilio. The way our Opt-In/Opt-Out works is each company (our customer) signs up for one or more Twilio phone numbers and their customers can opt-in/opt-out into these numbers.
When Twilio receives these opt-in/opt-outs we want Twilio to call us into a webhook URL.
So my question is: how do we register these callback URLs? Do these have to be defined at the time when each company signs up for a phone number? If so whats the API end point for that?
These numbers can be added by different companies at any time. Please advise how to do that. We already have URLs defined for sending and receiving SMS messages with Twilio. In this case we first send the message to Twilio and we specify a callback url in that. Can the Opt-In/Opt-outs work with these already registered end points?
All the phone numbers these companies sing up for are created as a subaccount under us. So is that fine with Twilio and can Twilio call us back on the already registered end points (URLs).
If you have any documentation on how to set up an Opt-In/Opt-Out,please include that. I couldn't find one anywhere. The API method we use for creating subaccounts when companies sign up for a phone number is CreateSubAccount and there is no parameter to specify an call back endpoint URL. I tried contacting their support but they haven't gotten back to us yet.
Twilio developer evangelist here.
I'm not sure exactly what you mean when you say "When Twilio receives these opt-in/opt-outs" as the only thing you will get webhooks for is when a number receives an incoming SMS (or phone call, but we're talking SMS right now).
You can set a different SMS webhook URL per each phone number using the API when you buy the phone number. As part of the POST request to the Incoming Phone Numbers resource you can add the optional parameters SmsUrl and SmsMethod.
Once you have purchased the number, you can also update the webhook URLs for it, by POSTing or PUTing to the instance resource, using the same parameters.
Let me know if this helps at all.

A SIP provider with PSTN number and extension range for DID

I have a Twilio account with USA PSTN number like +11234567890. In my company all users have an internal SIP 4-digit number like 2001, 2002 etc.
Is somewhere a USA SIP provider which allows anyone USA client to call my number +11234567890 with extension directly, like +11234567890XXXX, and pass this full number into my PBX via SIP trunk call? With that number I can bridge a caller and callee directly (Direct Inward Call, DID), bypassing voice menu.
A Twilio techsupport says that i must buy another PSTN number, and they don't allowing such extensions. So, buying a external number per every user looks silly.
Is somewhere a USA SIP provider which allows anyone USA client to call my number +11234567890 with extension directly, like +11234567890XXXX, and pass this full number into my PBX via SIP trunk call?
No. This is impossible -- phone numbers in the US (as well as Canada and some countries in the Caribbean) must confirm to the North American Numbering Plan, which mandates that phone numbers be nine digits long. The US telephone network does not permit longer numbers to be dialed, no more than an IPv4 network would permit a five-octet IP address to be used.
Some devices will allow extra digits to be entered, e.g. to allow novelty "phonewords" to be dialed, but the extra digits are discarded. They are not sent to the phone network.
As George mentions in the comment , that is not the most intuitive way of dialing for the end users. You could achieve something similar with your Twilio number by using inbound PSTN or SIP call to invoke your application which can ask for extension and respond using the <Sip> noun of the <Dial> verb, to establish a call with your SIP endpoint.
A possible flow to achieve what you require is mentioned below :
Create a rest endpoint that does the following
Asks caller to enter extension number by <Say>-ing a message
Uses TwiML to <Gather> extension number from caller
<Dial> this extension on your sip infrastructure
Point your Twilio Number to above endpoint.
3 . Dont forget to whitelist Twilio's SIP address and media ports in your infrastructure
Sample TwiML to dial to your sip infrastructure is mentioned below (if extension is can be dialed directly as endpoint , do a direct sip to the extension , else pass extension as a header to your pbx and have pbx dial the extension)
<Response>
<Dial>
<Sip>
sip:stan#example.com?extensionNumber=2001&customeheader=xyz
</Sip>
</Dial>
</Response>

How to differentiate clients if we are using 1 number for multiple clients to send SMS to users using Twilio?

I am trying to integrate twilio API to my java code. I have come across a scenario, I have clients A and B. I have send them SMS using twilio and receive the reply back. I am not sure how do I differentiate between the two replies that I would get from the user to my single twilio number.
Twilio developer evangelist here.
You can either work this out by recording which numbers client A has sent messages to and when you get responses from them assign them to client A and then the same for client B.
Or you could buy one more Twilio number and assign one to client A and the other to client B and split things out based on the incoming Twilio number.

Resources