【问题标题】:Sending Mass Text with Twilio API使用 Twilio API 发送大量文本
【发布时间】:2019-10-11 17:10:32
【问题描述】:

我正在尝试通过完全按照此视频设置群发文本:https://www.youtube.com/watch?v=EMOYY58jyKk

尝试运行时收到此错误:

SyntaxError: Unexpected token :
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/Users/wesleymoore/Downloads/Twilio Passthrough 
Friday/node_modules/node-env-run/dist/bin/node-env-run.js:21:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! passthrough@1.0.0 start: `nodenv .`
npm ERR! Exit status 1

我已经设法使用更简单的代码来发送一封电子邮件,但我需要发送大量电子邮件。我的日志中没有收到任何内容,所以我不确定问题可能是什么。任何帮助将不胜感激。或者如果可能的话,我可以使用此代码添加额外的数字,因为它似乎有效:

var accountSid = '------------'; // Your Account SID from 
www.twilio.com/console
var authToken = '---------------';   // Your Auth Token from 
www.twilio.com/console

var twilio = require('twilio');
var client = new twilio(accountSid, authToken);

client.messages.create({
body: 'Hello from Node',
to: '+1usnumber',  // Text this number
from: '+1usnumber' // From a valid Twilio number
})
.then((message) => console.log(message.sid));

【问题讨论】:

  • 你能分享你正在运行的导致该错误的代码吗?

标签: node.js twilio sms


【解决方案1】:

要发送批量消息,您需要一个收件人数组,然后循环遍历该数组,每次使用不同的号码调用您的函数。如 twilio 文档中所示 https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-node-js?code-sample=code-send-an-sms-using-the-programmable-sms-api&code-language=Node.js&code-sdk-version=3.x#send-a-message-to-multiple-recipients

这是来自文档的 sn-p:

var numbersToMessage = ["+15558675310", "+14158141829", "+15017122661"]

numbersToMessage.forEach(function(number){
  var message = client.messages.create({
    body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
    from: '+16468635472',
    to: number
  })
  .then(message =>  console.log(message.status))
  .done();
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    相关资源
    最近更新 更多