如何使用 Twilio Notify 向多个收件人发送 SMS 消息? [英] How to Send SMS Messages to Multiple Recipients with Twilio Notify?

查看:40
本文介绍了如何使用 Twilio Notify 向多个收件人发送 SMS 消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Twilio Passthrough API 或通知服务应该允许您通过单个 API 调用批量发送 SMS(或 Facebook Messenger、WhatsApp 等)消息.但是,我很难通过调用和 Twilio 的 toBindings 属性来接受一组值.

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 支持向我发送了这个示例:

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?

推荐答案

你在重复排列:

"toBinding" => [ $toBindingAttributes ],

$toBindingAttributes 已经是一个数组,所以:

"toBinding" => $toBindingAttributes,

应该可以解决问题.

这篇关于如何使用 Twilio Notify 向多个收件人发送 SMS 消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆