Reputation: 11
The Twilio Passthrough API or Notify service is supposed to allow you to send SMS (or Facebook Messenger, WhatsApp, etc.) messages in bulk with a single API call. However, I'm having difficulty getting the call and Twilio's toBindings attribute to accept an array of values.
$Addresses = array("+19999999999", "+18888888888");
$toBindingAttributes = array();
foreach ($Addresses as $Address) {
array_push($toBindingAttributes, '{"binding_type":"sms","address":"' . $Address . '"}');
}
$notification = $client->notify->services($MyNotifySid)->notifications->create([
"toBinding" => [ $toBindingAttributes ],
"body" => "This is a manual test."
]);
In the above example it is only sending the first SMS. It is not cycling through the array given.
Twilio support sent me this example:
$MyNumbers = array('{"binding_type":"sms", "address":"+1555555555"}', '{"binding_type":"sms", "address":"+14444444444"}');
$notification = $client->notify->services($serviceSid)->notifications->create([
"toBinding" => [$MyNumbers[0],$MyNumbers[1]],
"body" => "Notification Test"
]);
and indeed it works as presented. But what is the point of using an array of values if you have to explicitly declare each and every array key in the attributes? Have even tried with their example:
"toBinding" => [ implode(",", $MyNumbers) ],
and it still will only send the first SMS. What am I missing here?
Upvotes: 0
Views: 1177
Reputation: 180024
You're double-arraying things:
"toBinding" => [ $toBindingAttributes ],
$toBindingAttributes
is already an array, so:
"toBinding" => $toBindingAttributes,
should do the trick.
Upvotes: 2