使用Twilio Node.js SDK v5.0.1无法发送WhatsApp模板消息求助
使用Twilio Node.js SDK发送WhatsApp模板消息失败问题
我正在使用Twilio的Node.js SDK v5.0.1向客户发送WhatsApp服务更新通知,但始终无法成功发送消息。
已具备的条件
- 已创建并通过WhatsApp审核的Twilio消息模板
- 状态为「在线」的WhatsApp企业ID及号码
模板详情
正文:Hi! Your {{2}} booking has been updated!
示例内容:BMW
按钮:https://[website]/view-booking?bookingId={{1}}
- 类型:
Visit website - 文本:
View booking - 示例内容:
-wn54Cw5WO-G3QFUKHP_6dT6PEfApuiloZNoMdTuMZs%3D
尝试的两种方案
方案一
exports.sendSMS = async (phoneNumber) => { const accountSid = ""; const authToken = ""; const client = new twilio(accountSid, authToken); return await client.messages .create({ contentSid: "[sid]", contentVariables: JSON.stringify({ 1: "BMW", 2: "-wn54Cw5WO-G3QFUKHP_6dT6PEfApuiloZNoMdTuMZs%3D", }), from: "whatsapp:+[number]", to: `whatsapp:+${formatUKPhoneNumber(phoneNumber)}`, }) .then((message) => { console.log(message); return message.sid; }) .catch((e) => { console.log(`error0: ${e}`); }); };
报错信息:error0: Error: A text message body or media urls must be specified.
方案二
exports.sendSMS = async (phoneNumber) => { const accountSid = ""; const authToken = ""; const client = new twilio(accountSid, authToken); return await client.messages .create({ body: "Hi! Your BMW booking has been updated!", from: "whatsapp:+[number]", to: `whatsapp:+${formatUKPhoneNumber(phoneNumber)}`, }) .then((message) => { console.log(message); return message.sid; }) .catch((e) => { console.log(`error0: ${e}`); }); };
问题现象:代码执行无报错,但Twilio日志显示消息发送失败(截图:
)
内容的提问来源于stack exchange,提问作者chumberjosh
相关产品推荐
相关产品推荐

