When my server sends an SMS with the MediaUrl parameter specified, I want to utilize the link location(s) that Twilio assigns to the image(s) to construct img tags with src properties based on media->uri.
Up until today, the following code was working...
$client = new Services_Twilio($twilio_sid, $twilio_token);
$params = array (
"To" => $to,
"From" => $from,
"Body" => $body,
"MediaUrl" => $media,
"StatusCallback" => $twilio_callbackURL
);
$message = $client->account->messages->create($params);
$sid = $message->sid;
$status = $message->status;
$attachments = "";
foreach ($message->media as $media) {
$attachment = $twilio_mediaURL . $media->uri;
$attachments .= "<br><br><a href='" . $attachment . "' target='_blank'><img src='" . $attachment . "' target='_blank'></a>";
}
I'm not sure whether the above shown technique is no longer acceptable, or whether it only worked by fluke. For instance, perhaps the status is always returned in a timely fashion and doesn't wait for any delays in transferring the images from my server to Twilio, and so, under heavy loads, no URL's are assigned until after the status has already been delivered.
- Should the above shown technique work? If not...
- Are there any parameters provided in the callback status that would provide this information? If not...
- What's the best way to retrieve this information after the callback?
- If the URL can only be reliably retrieved after the callback, is there a way in the original creation of the message to pass a parameter that would be returned so the server would know that a MediaUrl been specified for that message? (Obviously, the server could use the SID to fetch the message parameters from its local database, but that wouldn't be as efficient.)
A quick review and update of the items in the original question...
For completeness, here's the entire process from sending, to receiving an immediate update, to receiving a callback update, to requesting more information from Twilio's server:
When the message status changes, Twilio's server contacts my server based on the Callback URL...
For anyone trying this, I'm not saying it's the best way; but, in absence of receiving a response from Twilio, or finding the information in their documentation, this is the best I could come up with.