第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Twilio - 如何通過每個(gè)電話號(hào)碼發(fā)送不同正文的批量短信?

Twilio - 如何通過每個(gè)電話號(hào)碼發(fā)送不同正文的批量短信?

眼眸繁星 2021-11-18 21:11:52
我平均有 100 - 1500 個(gè)電話號(hào)碼要向其發(fā)送短信。我想在正文中包含與每個(gè)電話號(hào)碼相關(guān)聯(lián)的人名。我如何才能使用 Twilio 做到這一點(diǎn)?client.notify.services(notifyServiceSid).notifications.create({toBinding: JSON.stringify({  binding_type: 'sms', address: process.env.NUMBER_ONE,  binding_type: 'sms', address: process.env.NUMBER_TWO}),body: 'This should work!' //I want to dynamically change this per number.}).then(notification => console.log(notification.sid)).catch(error => console.log(error));
查看完整描述

1 回答

?
富國(guó)滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

有很多方法可以做到。


一個(gè)例子:


文件: broadcast.js


require('dotenv').config();


const twilio = require('twilio')(

  process.env.TWILIO_ACCOUNT_SID,

  process.env.TWILIO_AUTH_TOKEN

);

const template = "Hello {name}, test message";


(async () { 

  const records = [

    {number: "+1234567890", name: "Someone Someonesky"},

    {number: "+1234567891", name: "NotSomeone Someonesky"},

    ...

  ];


  const chunkSize = 99; // let's not overflow concurrency limit: 100

  for (let i = 0, j = records.length; i < j; i += chunkSize) {

    await Promise.all(

      records

        .slice(i, i + chunkSize)

        .map(

          record => {

            const {number, name} = record;


            // copying template to variable

            const body = template.toString();


            // replacing placeholder {name} in template 

            // with name value from object 

            body = body.replace(/\{name\}/g, name);


            return twillio.messages.create({

              to: number,

              from: process.env.TWILIO_NUMBER,

              body

            });

          }

        )

    );

  }

})();

文件: .env


TWILIO_ACCOUNT_SID=some-sid

TWILIO_AUTH_TOKEN=some-token 

TWILIO_NUMBER=+3333333

安裝依賴:


npm i --save twilio

npm i --save dotenv

跑:


node broadcast.js


查看完整回答
反對(duì) 回復(fù) 2021-11-18
  • 1 回答
  • 0 關(guān)注
  • 228 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)