How to receive SMS to a twilio number - php

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

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

How to record and store Twilio SMS in MySQL with no additional action?

What I am trying to accomplish is quite simple. I want to store all received SMS messages from a Twilio number in a database. Upon checking Twilio's documentation, their TwiML word should be able to do this, but no attribute relates to this:
https://www.twilio.com/docs/api/twiml/sms
Twilio developer evangelist here.
When your Twilio number gets sent an SMS, your application receives a webhook at the URL you supply in the settings for the number. For each messages, the webhook sends a number of parameters telling you about the message. The documentation for that can be found here: https://www.twilio.com/docs/api/twiml/sms/twilio_request.
You might want to take a look at our PHP Quickstart tutorial which will give you a good idea of how to get the details from the request. You will then just have to pick which attributes you want to store in your database.
Let me know if this helps.

PHP API track Twilio Responses

i'm working on an web app that has a message thread within and each time a new message is sent to a person a SMS is sent to that person, so what we want to do is to include the person's response to that SMS, lets say A sends a message to B, B receives both an email and a SMS, if B responses to A via the phone we need to be able to add that response to the thread. Is there a way to add additional information when you send a message using the API?
The sending SMS code looks like this:
$client = new Services_Twilio($accountSID,$authToken);
$sms = $client->account->messages->sendMessage("TwilioNumber",$toNumber,$message);
So, is there a way in which i could add some type of information to track this SMS thread, so when i get the response to the Request URL i could actually know that this message is being sent from B as a response from the message sent from A.
Thanks in advance.
Twilio evangelist here.
Unfortunately SMS does not have the idea of "meta-data" so there is nothing you can include that would tell you a message is in "response" to another message, but there are some solutions here.
You could create a convention of commands that are included in the actual body of the text message that tell you the message is ins response to a specific thread. But thats not super user friendly.
You're best bet is probably going to using multiple phone numbers and phone number tracking.
For example, when A sends the message to B you'll need to store both of their phone numbers along with the Twilio phone number that is receiving and relaying those messages. This allows you to map the two users together in a "thread" even though they are not directly texting each other.
But what happens when A wants to have seperate thread with both B and C? With a single Twilio phone number how do you know what thread to route their message to? The simplest way to allow this is to have multiple phone numbers. To send a message to B, A sends to 555-555-5555, to send a message to C, A sends to 555-555-6666. In this scenario you might think about buying a pool of numbers that you can draw from and recycle so you don't have to continuously buy new numbers.
Hope that helps.

SMS Forwarding with Twilio

I've been trying to build an app that forwards an sms to a URL
with twilio, i.e, a user sends an sms to a twilio number, the sms gets forwarded to a specified url, can't seems to find the resource on that, any experienced person in that area
to give a hint, plus what is the format of the sms forwarded to the url.
Thanks
Twilio evangelist here.
I'd suggest working through the SMS and MMS Messages Quickstart. It will walk you through the PHP needed to receive a text message:
https://www.twilio.com/docs/quickstart/php/sms
Hope that helps.
At last, I was able to find what I was looking for. Phew!
$_REQUEST['Body'] retrieves the body of the sms message and I can do whatever I like with that.
Twilio rocks!

twilio sms api - is my sms delivered or NOT-delivered to end user?

I use twilio API to send SMS from my php application. When the 'to' number is malformed (invalid area code, invalid digits number etc) twilio works fine, giving me an exception.
My problem is when I try to send to a number that is in good format, however it doesn't exist. It show it as 'sent' and no exception is given. I also tried the callback option:
array('StatusCallback' => 'http://uncurler.heroku.com/v1/<some code >').
Even when i view the report here it shows as 'sent'.
Is there a way to actually know if the message was delivered? Or more importantly if it was NOT delivered? If not, is it possible from some other API?
Twilio evangelist here.
So currently the Status value does not reflect anything beyond our ability to deliver the message to the carrier. It does not reflect any information about whether or not the carrier was able to deliver the message or not.
If the carrier accepts the message from us, we mark the message as Sent.
Hope that helps.

Categories