Twilio's receive sms and send a call.. - php

I am trying to do this but it is not working....I was trying to text to my sandbox sms at Twilio so once twilio receive's that sms it would execute a script that should dial a number. This is not working as I get no error so I am assuming the only place where the Dial verb works is in the phone section of Twilio and not the sms part. Any help?
I want the sms to be a trigger that starts up a script which uses Twilio's dial verb to call people and give a message then hang.

The <Dial> verb is a top level one, so it should be a child of <Response>, i.e., not <Sms>. That said, Twilio's documentation strongly implies putting <Dial> in the <Response> for an SMS callback won't work; <Dial> is supposed to connect a current caller to another party. So, if this isn't working, you'll hit their REST API to initiate the call; you can POST the TwiML script with the message to speak and the instruction to then hang up.
Note this contradicts my first reply to your comment on your other Twilio question, my apologies for that.

Related

Twilio Logs on Console for Error 21614

I have successfully attempted sending SMS to a phone number using Twilio REST API in PHP. Currently I am using a trial account. I can see logs on Twilio console too. When I attempt to send SMS to an invalid number, Twilio REST API gives me error:
Error 21614 - 'To' number is not a valid mobile number.
I can't view this error in Twilio Programmable SMS logs or Debugger Logs. So when I submit a bulk of numbers to Twilio, how can I find at the end, that which numbers failed to receive the SMSs because of error 21614, on Twilio Console? Currenty, I do not want to log it through my PHP code.
Thank you.
EDIT
If you want to go through the console you can see this link as you do not want to manage it via php
For managing at your end with StatusCallback
You need to use optional parameter StatusCallback and specify a callback URL where Twilio will POST each time your message status changes to one of the following:
queued,
failed,
sent,
delivered,
or undelivered.
Twilio will POST the MessageSid along with the other standard request parameters as well as MessageStatus and ErrorCode. If this parameter passed in addition to a MessagingServiceSid, Twilio will override the Status Callback URL of the Messaging Service. URLs must contain a valid hostname (underscores are not allowed). You can learn more about it here
you can add your php code there to keep track of every new message and keep updating the logs for that message.
Hope that helps

Trying to figure out a how call works in twilio

As subject says I am reading api docs for twilio but even after brainstorming for 2 hours I am still unable to figure out exactly how can I receive a call from twilio on my web application and answer the call with my own voice like we do in a real phone.
I know how to respond a call when someone call your twilio number but that's only text to speech conversion like their "Hello Monkey" example application but nothing so far about answering a call using their API.
Can anyone please explain how can we do that? Not everything, just main concept and few references if possible
I am using Laravel so would be good if it's in php
Twilio evangelist here.
I would suggest working through the Twilio Client for JavaScript Quickstart. This will walk you through both the server and client side code needed to build a phone in your browser, showing you how to both make outbound calls from the browser to a PSTN phone as well as receive incoming PSTN calls in the browser.
The magic that you are looking for in either of those cases is the <Dial> verb. When an incoming PSTN call comes into Twilio, you can use the Dial verb to tell Twilio to dial and bridge that call with a Client instance:
<Dial>
<Client>jenny</Client>
</Dial>
When and instance of client make an outbound call and wants to connect to a PSTN phone number you again us the Dial verb:
<Dial>
<Number>+15555555555</Number>
</Dial>
The quickstart shows in more detail how this works.
Hope that helps.
You tried the Twilio PHP lib? As for Laravel... Incoming call? No problem!
Please try to use Google before asking questions! I think one important trait to any programmer is the ability to organize the idea of "what you want", and then google each step to get it that you want...

Twilio Caller ID set for outgoing Calls

In my web application I have used Twilio api for making calls,
params = {"PhoneNumber": 'xxxx123'};
params = {"callerId": 'aaaa987'};
params["PhoneNumber"] = 'xxxx123';
params["callerId"] = 'aaaa987';
Twilio.Device.connect(params);
But in receiver phone/twilio call logs did not get from number aaaa987, it is some other number like xyz567 every time.
How can I set from number for Twilio outgoing calls ?
Twilio evangelist here.
So to make sure I understand your question:
You want to use the Twilio Client for JavaScript to make a phone call from a browser to a regular PSTN phone
You want to have the Client pass parameters to Twilio to set the phone number and caller ID of the call to the PSTN phone
Assuming I understand your question correctly, it looks like you are on the right track, passing an array of values into the Connect function. Now, what Twilio will do with that array is we will take each item in the array and convert it into a parameter that we send with the HTTP request we make to the Voice Request URL you have configured for your TwiML app.
Based on the tags you set for your question, it looks like you are using PHP? If that's correct then you would just set the Voice URL to a PHP page that you have hosted on the internet.
That PHP page can use the $_REQUEST object to access the HTTP parameters Twilio is including in its request and use them to dynamically generate TwiML. In your case since you want to have Twilio dial out to another phone number, you are going to need to generate TwiML containing the <Dial> verb.
Here is a sample that shows how you can use the Twilio PHP Helper library to generate TwiML:
$response = new Services_Twilio_Twiml();
$response->dial($_REQUEST['PhoneNumber'], array(
'callerId' => $_REQUEST['callerId']
));
print $response;
In this case I am grabbing the PhoneNumber and callerId parameters from the HTTP request made by Twilio and injecting them into the dial method. This would result in the helper library generating some TwiML that looks like this:
<Response>
<Dial callerId="aaaa987">xxxx123</Dial>
</Response>
Your PHP page returns the generated TwiML to Twilio in response to Twilios HTTP request. Twilio then executes the TwiML making cool things happen, like a phone call to the number you've specified.
If you want a bit more of a step-by-step walk-through for Twilio Client for JavaScript, I'd suggest talking a look at the Twilio Client for JavaScript Quickstart. Its available in PHP and will take you through using Client for both inbound and outbound phone calls, including setting up a server side application in PHP to generate and return TwiML and also passing parameters into that PHP file.
Hope that helps.

How to receive SMS to a twilio number

I have created a free account in twilio for sending SMS through my website. After my registration I got a twilio number like XXX-XXX-XXXX. I am able to send message to mobile numbers but I don't know how to use this twilio number for receiving SMS. Please help me out on this.
Twilio evangelist here.
The way Twilio notifies you of both incoming SMS message and incoming voice phone calls is by using something called a webhook. This is basically an HTTP request that Twilio makes to a URL that you tell us about. Normally this URL is a web app that you've created and published to a public website.
http://en.wikipedia.org/wiki/Webhook
In your Twilio dashboard, click on the Numbers tab and you will see your trial number.
https://www.twilio.com/user/account/phone-numbers/incoming
Click the phone number and you will see two input fields, one for a Voice URL and one for a SMS url. Just put your URL's there and click the save button.
Now if you send a text message to your number, Twilio will make an HTTP request to the URL you've told us about. You can think of this like a standard Form submit. Twilio will send along parameters like the number the SMS is coming from and the body of the message. The full list of parameters we send to the SMS url is here:
https://www.twilio.com/docs/api/twiml/sms/twilio_request
Your app can grab those parameters and use them however it wants. Your app can also return TwiML instructions to us that tell us to respond to the SMS.
https://www.twilio.com/docs/api/twiml/sms/your_response
You might want to check out our quickstarts for examples of how to receive a text message and and howtos for lots more examples of both sending and receiving SMS messages.
https://www.twilio.com/docs/quickstart/php/sms/hello-monkey
https://www.twilio.com/docs/howto
Hope that helps.
Devin

Twilio sms question

Uptill now I have been using Twilio for phone calls. Now I want to be able to have a network monitoring tool that texts when there is a problem to a number. I would like to make it so that when twilio receives the text it will execute the script that I have put into its URL...I really don't know how to get started with sms it seems very hard and complicated as compared to phone calls...Any help on the sms is greatly appreciated to get me started.
If you've already figured Twilio voice calls, you'll find SMS easier once you figure out what they're doing. Which is essentially:
Carrier delivers an SMS to Twilio for a number you're renting from them.
Twilio makes an HTTP POST or GET (you choose) to the URL you setup in their web admin. The content of the text message will be a parameter in there.
You do whatever you want with the POST or GET, returning a TwiML if you want an SMS reply sent or nothing if not.
Note, Twilio can't execute a script for you, unless it's TwiML, in which case you're just returning TwiML as the response to the HTTP call from #3. So if you want to do something in response to an SMS, you'll need build that something into the logic that handles the URL you've given Twilio. If you're still lost a bit, tell us about how you're trying to do this, e.g., you've a Rails app, a PHP website, or just a Bash script you want to run and nothing else yet...
Why not avoid Twilio and have your network monitoring tool execute the script itself?

Categories