I would like to make my client to check whether end client is received text or not and what reply he/she has sent? I always going through twilio to see whether client received sms or not? Is there any way to check it from twilio?
-
Am using php language, i would like to read all the messages from twilio using php with out going to twilio always. – Rajeev Uppala Jan 02 '18 at 13:16
-
Hey, happy to help you out with this. What have you tried so far? Post some code and I'll help you out. Cheers – Marcos Placona Jan 02 '18 at 17:26
-
Hello Marcos, I didn't find any kind of api/function to read messages from twilio, i have been looking for an API method which twilio provides us to read messages which we sent/received to/from the user with his/her phone number. Thank you for your response. – Rajeev Uppala Jan 03 '18 at 05:58
-
Have a look at this for starters, and then come back if you're stuck on something. https://www.twilio.com/docs/api/messaging/message – Marcos Placona Jan 03 '18 at 10:46
2 Answers
Twilio developer evangelist here.
You can get both incoming messages to your Twilio numbers and reports on the status of messages after you send them from Twilio using webhooks.
When you send a message you can include a StatusCallback
parameter. The parameter should be a URL in your application.
$client->messages
->create(
$to,
array(
"from" => $from,
"body" => "Let's grab lunch at Milliways tomorrow!",
"statusCallback" => "https://example.com/messageStatus"
)
);
Twilio will send a POST request to the statusCallback
URL each time your message status changes to one of the following: queued, failed, sent, delivered, or undelivered. It will include the original message's SID, so you can tie these webhooks back to the message you sent.
Similarly, you can get these webhook notifications for incoming messages to your Twilio numbers. For this you need to set up the incoming webhook URL to the number in your Twilio console. Set it to a URL in your application and you will receive a webhook when someone sends a message to your Twilio number. Check out this quickstart guide on receiving messages to your Twilio number with PHP.
Let me know if that helps at all.
[edit]
Thanks for the comment where you made it clear that this is after the fact, not at the time of sending.
In this case, you can absolutely list the messages by the phone number that sent them. A message resource includes a Status
attribute that lists the current message state in the Twilio system, anything from "accepted" and "queued" to "sending", "sent", "delivered", "undelivered" and "failed". You can see more about these statuses in the documentation.
To get the list of messages sent from a number you can use the following code:
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);
// Loop over the list of messages and echo a property for each one
foreach ($client->messages->read(array("from" => $FROM_NUMBER) as $message) {
echo $message->status . " - " . $message->to . " = " . $message->body;
}

- 70,667
- 10
- 60
- 88
-
Thank you phinash for your reply, unfortunately this is not the answer am expecting, I already using this in my application. I have total 1500+ twilio numbers and 9 million clients. We are not saving all the status back to our application. When some one wants to check with their phone number, is there any way to get messages list from twilio? I want to make it automatic thus i will not go to twilio to search always. Thank you in advance. – Rajeev Uppala Jan 10 '18 at 04:50
-
Hey Rajeev, of course, thanks for the explanation. Please check out my edit in the answer above. – philnash Jan 10 '18 at 04:58
-
Hey Philnash, Thank you for your answer, as your new edit we can get all the messages sent from that number. In this case also i may get lakhs of messages as one of my client has 15 lakh users with them. This is why i need a way to fetch messages between two numbers or based on receiver number, so i can filter them easily. – Rajeev Uppala Feb 09 '18 at 09:37
-
You can filter messages by the number the message was sent to or from or both. In my example I’m filtering with the `array(“from” => $FROM_NUMBER)`. Does that help? – philnash Feb 09 '18 at 20:17
-
philnash, no I have about 10 lakh customers for one number, if I keep filtering with from number then i might get all these, still I have to do lot of work. – Rajeev Uppala Mar 06 '18 at 09:42
-
You can filter with both `to` and `from` with an array like `array("from" => $FROM_NUMBER, "to" => $TO_NUMBER)`. Does that help? – philnash Mar 06 '18 at 12:32
-
-
philnash, it worked for me. Sorry for late response. After a very long break i logged into this. – Rajeev Uppala Aug 09 '18 at 07:58
You can pull data for specific messages https://www.twilio.com/docs/api/messaging/message#delivery-related-errors or you can simply pull all the logs

- 352
- 1
- 8