How to handle uber like scenario in twilio - node.js

I have an uber like scenario, where a customer can call a driver, how to handle such call in twilio. My initial attempts were as follows,
client.calls
.create({
url: 'https://handler.twilio.com/twiml/EXXXXXXXXXXXXXXXXXXXXXX',
from: '+18XXXXXXXXX', // customer
to: '+12XXXXXXXXX' // Driver
})
.then(call => console.log(call.sid))
.catch(e => console.log(e))
Here, the url returns the following twiml.
<Response>
<Dial>+12XXXXXXXXX</Dial>
</Response>
I have created a twimlBin(url in client.calls.create() function) which simply dials the driver's number. The problem is that I dont understand how wether the call is made by the client.calls.create() function or the twimlBin. Also no such tutorial is present, to handle such situation.
Thanks in advance

Twilio developer evangelist here.
In the case of a customer calling a driver, your customer would call a Twilio number and that Twilio number would forward onto the driver's number. So, you don't need to create the call using the REST API yourself, the call will be initiated by the customer.
So, you will need a Twilio number for this. Once you have a Twilio number, you will need to set the number's handler for incoming calls. You can point that to the TwiMLBin that you've created as it will do for this first use case. Save the number and call your Twilio number, it will dial you through to the driver's number.
However, you will find that the driver's phone will show the customer's number. For privacy reasons you likely don't want that. This feature is known as masked calling.
To mask the customer's number you can add a callerId attribute to your <Dial>, like this:
<Response>
<Dial callerId="{YOUR_TWILIO_NUMBER}">+12XXXXXXXXX</Dial>
</Response>
Now when your customer calls the driver, the call will be forwarded to the driver and they will see the Twilio number.
This is great for our simple use-case here, but if you want to mask numbers for a number of drivers, then there's a bunch of work to do. Thankfully, masking numbers is such a common scenario, Twilio built a product to handle that for you. Check out Twilio Proxy and the Twilio Proxy quick start for a tutorial on how to use it to mask numbers.

Related

Twilio Rest API / Node Js call status no working

I'm creating a tool that can automatically call someone when I click a button.
So far, I've tested three solutions: The first one was using the rest API call, the second one was using node js SDK that is available in the Twilio console using the function & assets feature, and the last one was using Twilio Studio feature.
All of them are not giving me the satisfaction of creating something that can be used in production.
The main problem is the call status given to the StatusCallback url parameter.
For example:
if you set a timeout value by default or something higher than the duration of the ringing time, it will send you a completed status. The timeout value needs to be smaller than the maximum number of ringtone that your carrier set by default if you want to receive a no-answered status.
If your phone is on "airplane mode" and you make a call to it using Twilio, the statusCallback will be sent to the URL as "completed".
If you make the same phone call and imagine that the user rejects the call by clicking on the red phone instead of the green phone, the statusCallback will send you a completed status.
So it's been a week since I've coded a NodeJS solution using Twilio Functions, making POST requests using Postman, and also creating a flow to test it using Twilio Studio. Every time that I've tried those three solutions, with the three same scenarios described above, I've never been able to obtain a real valuable/informative status that can help me to resend the call until someone answers or, based on the status, send an SMS to the person to inform him that we have tried to call him and that he either was not available or rejected the call.
Has one of you already tested that and maybe succeeded in having anything else than a "completed" status? That is no use in case you need to handle those cases.
Thank you for your help.

nexmo: forward to application and callers number

We have 3 options to connect to get inbound call.
Forward to Phone
Forward to application
Forward to SIP
Forward to Phone: When we call LVN then provided number gets call and callers number is seen in incoming call.
Forward to application: When we call LVN, then it goes to answer URL webhook. From answer url webhook, we provide connect ncco to call to my number. This time I am seeing LVN number in incoming call.
So is there any way in "Forward to application" method, that we will be able to see callers number in incoming call.
Yes you can forward the number of the incoming call by dynamically generating the NCCO when the call comes in and setting the from field in the connect action.
There are some examples in different coding languages available on the Nexmo developer portal and check the NCCO reference on connection actions for exact examples but in a nutshell set the "from field at the same level as the action and endpoint fields in the NCCO response to contain the "to" number that is in the GET parameter of the incoming webhook to your answer_url.
Hopefully that makes sense, good luck :)

How to use Dialogflow Phone gateway and handling it in backend platform like nodejs

I'm trying to understand phone gateway implementation in dialogflow but dont see much of documentation for how to handle in backend code using nodejs or any third party apps like twilio,viber etc.
My doubt is whether is it available for now or not and is their any documents regarding phone gateway which can be done through google mini device for voice calling?
Please correct me if I'm wrong about what I understand.
Dialogflow phone gateway is a great feature provided by Dialogflow. It is simple to activate. Just follow the instructions in the Integrations tab.
All your intents and webhook will just work fine as they do in the bot. But the response type is little different from other platforms. So check that once before building responses.
It only supports speech response that is returned to the user in the phone call.
as per Google documentation, it uses the V2Beta1 version of the API. It means you have all the normal fields of the V2 API inside the body and parameters of the webhook call (+1 "MlEnabled" field, but not important for the telefony gateway). See more here https://dialogflow.com/docs/reference/v2-beta-v2-migration-guide-api . I have also been searching for extra fields like the phone number who is calling (to use it in backend tasks like CRM lookup), but this is not there yet (I analysed the JSON response, there is nothing so far).
Some tip to integrate with Twilio (my use case too) : you can perfectly route the twilio call to a simple Twilio callflow (like checking for opening hours) then to the incoming DialogFlow number (as you would do with the black number of an IVR provider) and transfer the Dialogflow call to another incoming phone numbers (controlled by Twilio) where you do the rest of the callflow (typically the skill based routing).
Example : after the call, Twilio checks for opening hours > OK > forward to Dialogflow phone nbr for intent recognition > identify intent nbr1 > route to phone nbr1 of Twilio which is connected to a routing/queue to agent group nbr1 (idem for intents nbr2, 3, 4 ...).
In this example, some useful fields are missing in the JSON like the phone nbr of the caller(CLI), the phone number dialed, eventually some UUI ISDN field, ... that you would like to use for a CRM lookup and CTI popup. Let's keep an eye on it and maybe Google will add it in V2beta2 ...?

How to verify an account using SMS or Call

I am working on an eCommerce website but our client told us to add functionalists like they want to verify an user account by sms or by call.
I don't know how to do this and how many of websites and apps do this.
Do they use any third party services or can we implement it by our won?
If we have to use this service please tell me the name and how much it costs and how to setup?
If there is any alternative please tell em that also.
Moreover I want to use this services for testing also.
Any help would be appreciated.
Some websites/apps build it themselves with SMS / Voice APIs...
Others use a Verification specific API...
With SMS / Voice APIs
You'll need to generate a code
Send it via the channel you use primarily
Set some kind of time delay job (queue, worker, whatever)
Send a fallback message should you get no response from the user
With an SMS API, that likely varies per country,there is a solution that allows you to go globally with an API call for a flat fee of 10 cents per verification, NOT per attempt (unsuccessful attempts will not be charged towards your account)
Nexmo’s Verify API
Make a call to https://api.nexmo.com/verify/json (or /xml)
Add parameters: api_key, api_secret, verified number, brand
Optional parameters: language, length
Take a look at the Nexmo's Verify documentation here!
Verification code should arrive to your phone as an SMS. If you wait a while, you'll also get a phone call, and the code will be read to you. The timing and channels used depends on the type of number, the country, and the carrier.
Reasons to implement Nexmo's Verify
Landline & Mobile Verification
Failover & Retry Sequences
Simplicity.. Just make one API call
Other alternatives: Enterprises (sign a heavy/clunky contract)
Full disclosure, I work at Nexmo

How can you verify an incoming Twilio sms?

I basically am trying to allow users to post to their blog using a text message. I have a phone number stored for each user, and since twilio sends that information in the post request they hand to my page, I can do a reverse lookup to see which blog to post it to. The question now arises, how can I be sure that the user sent the text? Can't anyone just send post information with someone else's phone number?
I have a couple thoughts about this:
1. Twilio sends your account number in the post, which I suppose isnt known to malicious users.
2. I could respond with an SMS containing a randomly generated code, and have the user send that back. This would effectively triple the SMSs needes do I would prefer the first.
Is number one "safe enough"? Or should I bite the bullet and make a response system as in number two?
You can verify that requests are coming from Twilio. We attach an X-Twilio-Signature header to each request which is signed with your Auth Token (which should be known only by you). Each of the Twilio helper libraries has a function to help determine if the request was made by Twilio or not.
Please see our documentation on validating requests: http://www.twilio.com/docs/security#validating-requests
or our helper library functions for validating Twilio requests: http://readthedocs.org/docs/twilio-php/en/latest/usage/validation.html#validate-incoming-requests, for example.

Resources