Associating a Twilio number with a specific Frontline user - twilio

I'm trying to figure out how to associate a specific user with a Twilio number, so that when a call/text comes to that number it only goes to that user's Frontline app/account.
I'm writing the callbacks in Node.js, and I guess that I'm a bit confused to as to how to identify the target number (as the quickstart I'm using is more focused on the customerNumber and relationship with a specific worker).
Thank you.

I believe you should set up Custom Routing for this and, instead of using the customer number (the MessageBinding.Address from the webhook parameters) to do the routing as in the quick start, you can use the number the customer sent the message to, which I think is the MessageBinding.ProxyAddress.
Check out all the parameters that are sent to the onConversationRoute webhook URL. You might also want to test and just log out all the available parameters in order to match to the target number.

The best and the only option I see the Call Forwarding for that purpose and using Twilio's inbuilt TwiML Bins.
Complete info:
https://support.twilio.com/hc/en-us/articles/223179908-Setting-Up-Call-Forwarding

Related

How to Create Twilio Conference Before Calling Anyone?

I'm looking for a way to generate a Conference resource within the Twilio system before adding anyone to that conference.
The official recommended way to start a Conference is by returning TwilXML in response to a Twilio callback. This can either be done in response to someone calling a Twilio number or, in a somewhat indirect way, by making a call and returning TwilXML which will connect the person to a conference once they pick up. All of the APIs to modify conferences use the ConferenceSID as the handle to decide what conference to change. The problem with both of these methods is that they do not give you the ConferenceSID until you receive a callback.
Unfortunately callbacks do not contain any identifying information about who generated them. They do have a ConferenceSID (identifying the conference), and a CallSID (uniquely identifying the call connecting the caller to the conference). When you get your first callback, there appears to be no way to be able to match either of those identifiers. If you start multiple conferences and get two callbacks with different ConferenceSIDs and different CallSIDs, it is inconvenient to tell which conference is generating which callback.
That's why it would be easiest to create a conference resource and then use the versatile add participant call. This would simplify the entire backend flow for using conferences by starting with the ConferenceSID and going from there.
P.s. To head off other suggestions - there are ways around this. You can specify different callback URLs for different conferences. You can specify different friendlyNames for different participants which you can match in your backend. It's totally possible to work with, but I would like something cleaner, which would require making conferences before anyone is called.
Twilio developer evangelist here.
There is no way to create a conference resource from the API. You can only do so by directing a caller there with the <Dial><Conference> TwiML.
Further, I don't quite understand when you say "When you get your first callback, there appears to be no way to be able to match either of those identifiers." What are you trying to match? You could use the CallSid to look up the From number of the caller joining the conference. You also receive the FriendlyName in the callback, which is the name you set in the TwiML <Conference>Friendly Name</Conference> which you could choose to help determine which conference is which.
Does that help at all?

For voice tasks in Twilio Flex, how do I get the current conference ConferenceSid?

I can see that for all the voice interactions, behind the scenes flex is using its voice API to create a conference between caller and worker. How do I obtain the created ConferenceSid after the task has been selected and reserved?
What I would like to do is simply Get the value upon connecting.
I can see a very long and not so pretty way of getting it, which is by running a twilio function that iterates over every conference, making additional requests to see the participants. But that seems way to complex to me.
I can see in the logs that the conference friendly is being printed
ConferencesState handleConferenceUpdate WT5d0800a3ce8724fd55cf89841c48XXX
Is there anyone who can help here?
UPDATE:
#philnash below answered the question exactly.
Twilio developer evangelist here.
There seems like a couple of ways to get hold of the Conference SID in a Flex interaction.
First, the task that your worker accepts has a number of attributes that are set by Flex and relevant for the type of task it is. For a voice call, you will find a conference key, which has an object including the sid as well as entries for the participants.
Secondly, I found that the <TaskCanvas> component in the UI is passed a context that includes a conference object. That object then has a source property which expands to an object with a conferenceSid property, as well as other properties, including a participants list.
Does that point you in the right direction?

What are the way i can keep track of min/call by each of customer

Our usecase in simplified manner:
1) Custom come to our website
2) he see a list of phone numbers
3) he click on a phone number to call.
For above i am reading
https://www.twilio.com/docs/quickstart/java/client/outgoing-calls
Our plan is to give this call functionality as a added feature where we will charge end customer what twilio charges us.
Now i need to keep trace of number of call/min each of our customer used. so that i can charge him for the same.
What are the way i can keep track of min/call by each of our customer?
Edit:
Is there any api/webhock that can be used to keep track of when a particular call started and ended so that we can save the duration of call and charge for the same.
Twilio developer evangelist here.
Good news! There are a couple of ways for you to find out this information.
Firstly, you can set a StatusCallback URL that receives webhook information about calls. You can either set this on the level of the number, using the phone numbers section of the Twilio portal. Or you can set a StatusCallback parameter when you create calls using the REST API. Or you can set a StatusCallback attribute when creating calls using the <Number> noun in TwiML.
Either way you set the callback, you will get a webhook back to the URL you set when the call is over. That webhook will include a CallDuration parameter with the duration of the call in seconds.
For more accurate price reporting, you can actually query the REST API. Call instance resources have a Price property. The only drawback here is that the Price property may not immediately be available. So you may need to schedule jobs to check for the price after a call is complete.
Let me know if this helps at all.

Restricting callerID choices in Twilio

I have a very simple Twilio setup for my company as our phone system. I've one specific problem: at the moment, anyone can use any of the numbers that have been associated with the company on the site for calling out. So Bob might accidentally use Alice's number, and that's unfortunate.
How do I change that? I would like to be able to set it so that each non-administrator user can only use one phone number for calling out, specifically the number associated with their user or device.
You could use subaccounts:
http://www.twilio.com/docs/api/rest/subaccounts
Alternatively, enforce the extra Caller ID logic in your own application and refuse calls if they don't match the correct params.

Recommended Structure for Twilio Rails project?

What is the best structure for this Twilio project?
Phone numbers are POSTed and stored to be dialed at a later time (to be triggered by cron)
I have a controller to accept incoming POST requests and add the numbers to the database.
I also have a rake task (called via CRON) that pulls all the numbers that need to be dialed.
Where should I place the method for making the actual call? Right now I have it in a controller, would it be better to have it as a module or a plugin?
I use a controller to handle the twilio api calls, but my model contains the methods to actually send the calls.
If someone feels like they need an example, I'd suggest you check out the Twilio tutorials. Full disclosure: I work for Twilio.
In the automated survey Rails example, we demonstrate a call flow using <Say>, <Record>, and <Gather> TwiML verbs. And we show you how to maintain conversation state in a database that spans multiple webhook requests.
Hopefully seeing how we've structured our app will help you get started on your own.
I would put it in a model or a lib.
Could it be part of the model that the number is stored in? A Number#dial method perhaps?

Resources