twilio 不发送短信 nodejs
twilio isn't sending sms nodejs
我在下订单后使用 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 到文档(我获取代码的地方):https://www.twilio.com/docs/sms/quickstart/node
这里是 Twilio 开发人员布道者。
发送消息时可能出现问题,但您的代码正在丢弃错误,因此您看不到发生了什么。尝试将其更新为:
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));
一旦您看到错误是什么,您将能够修复它。我的猜测是您错误地配置了您的帐户 Sid 和身份验证令牌,或者您正在使用试用帐户并尝试向您没有的号码发送消息 verified yet, or you are trying to send a message to a country that isn't enabled.
我在下订单后使用 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 到文档(我获取代码的地方):https://www.twilio.com/docs/sms/quickstart/node
这里是 Twilio 开发人员布道者。
发送消息时可能出现问题,但您的代码正在丢弃错误,因此您看不到发生了什么。尝试将其更新为:
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));
一旦您看到错误是什么,您将能够修复它。我的猜测是您错误地配置了您的帐户 Sid 和身份验证令牌,或者您正在使用试用帐户并尝试向您没有的号码发送消息 verified yet, or you are trying to send a message to a country that isn't enabled.