Node.js 使用Twillio';将动态内容传递到批通知正文中;s通知API

Node.js 使用Twillio';将动态内容传递到批通知正文中;s通知API,node.js,twilio,twilio-api,notify,Node.js,Twilio,Twilio Api,Notify,我正在利用Twillio的NotifyAPI向用户发送批通知。这一部分在Node.js中非常简单: async function sendPaymentScheduledMessage(numbers) { const bindings = numbers.map(number => { return JSON.stringify({ binding_type: 'sms', address: number }); }); return await s

我正在利用Twillio的NotifyAPI向用户发送批通知。这一部分在Node.js中非常简单:

async function sendPaymentScheduledMessage(numbers) {
    const bindings = numbers.map(number => {
      return JSON.stringify({ binding_type: 'sms', address: number });
    });

    return await service.notifications.create({
      body: `The payment of your balance is scheduled for this Friday.`,
      toBinding: bindings,
    });
  }
现在,我想将特定于用户的内容(名字、金额、账号等)传递到这些消息中。API文档提到了传递数据对象的可能性,但(在我看来)不清楚如何准确实现。我想这将是类似于:

async function sendPaymentScheduledMessage(users) {
    const bindings = users.map(user => {
      return JSON.stringify({ binding_type: 'sms',
                              address: user.number, 
                              data: { 'name': user.name 
                                      'amount': user.amount
                                    }
                            });
      });

    return await service.notifications.create({
      body: `Dear *name*, payment of *amount* is scheduled for this Friday.`,
      toBinding: bindings,
    });
  }
但到目前为止,我还没有找到正确的结构。如果有人做到了这一点,我将不胜感激。

属性仅包含
绑定类型
地址

为通知有效负载的自定义键值对保留。这适用于FCM、GCM和APN,但不适用于SMS

如果要自定义正文文本,只需使用常规JavaScript字符串插值,例如:

return wait service.notifications.create({
正文:`亲爱的${name},定于本周五支付${amount},
绑定:绑定,
});

如果您需要为每个用户自定义此选项,则需要多次呼叫
服务.通知.创建

谢谢您的回答。这就是我一直试图避免的,为每个用户分别调用该方法。在这种情况下,我认为使用service.notifications和bindings没有任何价值,因为基本的Twillio client.messages.create就足够了。但是我一次只能打几百个电话。这里是Twilio developer evangelist,我只是想确认Notify API不支持每条消息的自定义正文文本,如果您要发送数百条个性化消息,那么您需要对每条消息发出一个请求。请务必注意,尤其是在JavaScript中执行此操作时,并发API请求的数量限制为100个,因此您可能希望使用排队机制来控制该并发性,并且根据消息的数量,您可能需要一个后台队列。