12

Hello,
I am trying to learn Twilio API.
When I [send SMS through php][1] script.. twilio returns a response object with status = 'queued'. Now I want to get notified when the status changes to 'sent'. Is this possible with Twilio??? and if yes then could any body advise me on how to implement his.

And how to add 'StatusCallback' url

$sms = $client->account->sms_messages->create(
            // the number we are sending from, must be a valid Twilio number
            "000-000-0000", 

            // the number we are sending to - Any phone number
            "0000000000",

            // the sms body
            "Hey Friend, Monkey Party at 6PM. Bring Bananas!"
        );
Megan Speir
  • 3,745
  • 1
  • 15
  • 25
Frank
  • 2,285
  • 7
  • 43
  • 68

1 Answers1

19

You're on the right track looking to the StatusCallback. When using the Twilio PHP Library any optional parameters can be set using an array as the last argument.

<?php
$sms = $client->account->sms_messages->create(
  "1235551234", 
  "1235554321",
  "Hey Friend, Monkey Party at 6PM. Bring Bananas!",
  array('StatusCallback' => 'http://example.com/sms/status.php')
);

When the message is sent (or if it fails) the data will be passed to the StatusCallback url.

Tim Lytle
  • 17,549
  • 10
  • 60
  • 91
  • 1
    @Tim Lytle , Can you say what are the StatusCallback URL result ? – Elby Oct 30 '13 at 07:36
  • 1
    @Elby Documented here: https://www.twilio.com/docs/api/rest/making-calls#status-callback-parameter – Tim Lytle Oct 31 '13 at 12:34
  • 1
    Can anyone tell me what the data looks like? Is it in the post parameters? Is it JSON or XML? What does the post look like so I can get the data points in my WEB API service? – EJC Oct 16 '15 at 16:51
  • @EJC It's HTTP params, you can set the method using `StatusCallbackMethod`. – Tim Lytle Jun 13 '16 at 13:53
  • @TimLytle can you tell what are the params in case of failed/undelivered state? I cannot emulate a fail case with a trial account. In case of success I get `SmsSid`, `SmsStatus`, `MessageStatus`, `To`, `MessageSid`, `AccountSid`, `From`, `ApiVersion`. I am more interested in something like errorMessage or errorDescription. I have read the docs they have mentioned just about errorCode which is a numeric code. Not of much help. – Vikas Prasad Jan 04 '17 at 10:39