Tim
Tim

Reputation: 273

Obtain SID immediately after sending text message or voice message

I am transition to ver 5 of the twilio library.

I am successfully sending text messages with:

/* attempt to send the message */
$twilio_client->messages->create(
    "+1".$recipient,
    array (
        'From' => "+1".$org,
        'Body' => $txtmsg,
        'StatusCallback' => CALLBACK_LINK
        )
    );

I am successfully sending voice calls with:

$client->calls->create(
    "1".$recipient, "1"+$org
    array (
        'Url' => MSG_XML,
        'StatusCallback' => CALLBACK_LINK,
        "StatusCallbackEvent" => array(
            "initiated", "ringing", "answered", "completed", "failed"
        )
    )
);

In both cases how do I immediately obtain the message SID following the call? I need the SID prior to any callback url being called by Twilio.

Upvotes: 0

Views: 54

Answers (1)

rhysnhall
rhysnhall

Reputation: 56

You can get the response as such:

$msg = $twilio_client->messages->create(
   "+1".$recipient,
   array (
      'From' => "+1".$org,
      'Body' => $txtmsg,
      'StatusCallback' => CALLBACK_LINK
   )
);
echo $msg->sid;

Upvotes: 2

Related Questions