The following code works perfectly...
$message = $client->account->sms_messages->create($twilio_number, $to, $body, array("StatusCallback" => "http://etc...));
...for text messages within the 160 character limit. The SMS is sent, and my server is contacted at the callback URL when the status changes.
However, this method doesn't facilitate concatenated messages or MMS. For those, the Twilio documentation gives an example of sendMessage. This code works...
$message = $client->account->messages->sendMessage($from, $to, $body, $mediaURL);
...but the fourth call parameter, formerly used for the StatusCallBack URL, is replaced by the Media URL.
The Twilio documentation page has an "Optional Parameters" section, in which StatusCallback is listed and explained, but there's no example of how to include it when using the sendMessage method shown above and in their sample code.
Is it possible to specify a callback using the sendMessage method, and if so, how is it done?
Twilio developer evangelist here.
You're right, the documentation does not show you how to use optional parameters with the sendMessage
method. You can actually pass a 5th argument to the method with an array of options, like so:
$message = $client->account->messages->sendMessage($from, $to, $body, $mediaURL, array("StatusCallback" => "http://example.com/callback"));
If you have no media to add to the message, this would look like:
$message = $client->account->messages->sendMessage($from, $to, $body, null, array("StatusCallback" => "http://example.com/callback"));
You can also use the create
method with an array of options, which might be neater:
$message = $client->account->messages->create(array(
"To" => $to,
"From" => $from,
"Body" => $body,
"StatusCallback" => "http://example.com/callback"
));
Hope this helps.