简体   繁体   English

twilio 不发送短信 nodejs

[英]twilio isn't sending sms nodejs

I use twilio to send sms after a order is placed, but it isn't sending any sms and also not console logging anything.下订单后,我使用 twilio 发送短信,但它没有发送任何短信,也没有控制台记录任何内容。

Code: npm i twilio代码: npm i twilio

const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require("twilio")(accountSid, authToken);

exports.createOrder = (req, res) => {
  const { orders, status, details } = req.body;

  const order = new Order({
    orders: orders,
    status: status,
    details: details,
  });

  order.save((error, order) => {
    if (error) return res.status(400).json(error);
    if (order) {
      // if (res.status === 201) {
      client.messages
        .create({
          body: "This is the ship that made the Kessel Run in fourteen parsecs?",
          from: "+xxxxxxxxx",
          to: "+xxxxxxxxxx",
        })
        .then((message) => console.log(message.sid));
      // }

      return res.status(201).json({ order });
    }
  });
};

LINK TO DOC (where I took the code): https://www.twilio.com/docs/sms/quickstart/node文档链接(我在其中获取代码): https://www.twilio.com/docs/sms/quickstart/node

Twilio developer evangelist here. Twilio 开发人员布道师在这里。

There is likely an issue in sending your message, but the code you have is dropping errors, so you can't see what is going on.发送您的消息可能存在问题,但您的代码正在丢弃错误,因此您看不到发生了什么。 Try updating it to this:尝试将其更新为:

      client.messages
        .create({
          body: "This is the ship that made the Kessel Run in fourteen parsecs?",
          from: "+xxxxxxxxx",
          to: "+xxxxxxxxxx",
        })
        .then((message) => console.log(message.sid))
        .catch(error => console.error(error));

Once you see what the error is, you will be able to fix it.一旦你看到错误是什么,你就可以修复它。 My guess is that you have either configured your Account Sid and Auth Token incorrectly, or you are using a trial account and trying to send a message to a number you haven't verified yet , or you are trying to send a message to a country that isn't enabled .我的猜测是您要么错误地配置了您的 Account Sid 和 Auth Token,要么您正在使用试用帐户并尝试向尚未验证的号码发送消息,或者您正试图向某个国家/地区发送消息未启用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM