Twilio WhatsApp消息发送异常:返回403状态码求助
Twilio WhatsApp接口调用返回403 Forbidden问题求助
我正在开发一款应用,通过后端函数处理前端提交的表单数据。此前尝试使用Twilio可编程短信服务,但始终未通过10DLC注册审核,因此转向WhatsApp消息服务。已通过Meta的验证流程获得WhatsApp发送方权限,但调用接口时仍返回403状态码。以下是我的后端代码及返回结果,若需更多信息请告知。
import twilio from "twilio"; import fetch from "node-fetch"; const accountSid = process.env.TWILIO_ACCOUNT_SID; const authToken = process.env.TWILIO_AUTH_TOKEN; const twilioNumber = process.env.TWIL_PHONE_NUMBER; //const client = twilio(accountSid, authToken); const twilioSMS = async (message) => { message.from = "whatsapp:" + twilioNumber; const twilioApiUrl = "https://sendsms-7310.twil.io/sendSMS"; const body = new URLSearchParams({ From: message.from, To: message.to, Body: message.body, MessagingServiceSid: "MG00788be0ae8f5420cb4a7b950bc9f9d5", StatusCallback: "https://status-callback-2523.twil.io/message-status", }); try { const response = await fetch(twilioApiUrl, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "Basic " + Buffer.from(`${accountSid}:${authToken}`).toString("base64"), }, body: body.toString(), }); console.log("Backend: twilioSMS response: ", response); } catch (error) { console.error("Error sending SMS via Twilio:", error); throw error; } }; export default twilioSMS;
返回结果:
Response { size: 0, [Symbol(Body internals)]: { body: PassThrough { _events: [Object], _readableState: [ReadableState], _writableState: [WritableState], allowHalfOpen: true, _maxListeners: undefined, _eventsCount: 3, [Symbol(shapeMode)]: true, [Symbol(kCapture)]: false, [Symbol(kCallback)]: null }, stream: PassThrough { _events: [Object], _readableState: [ReadableState], _writableState: [WritableState], allowHalfOpen: true, _maxListeners: undefined, _eventsCount: 3, [Symbol(shapeMode)]: true, [Symbol(kCapture)]: false, [Symbol(kCallback)]: null }, boundary: null, disturbed: false, error: null }, [Symbol(Response internals)]: { type: 'default', url: 'https://sendsms-7310.twil.io/sendSMS', status: 403, statusText: 'Forbidden', headers: { connection: 'keep-alive', 'content-length': '64', 'content-type': 'text/plain; charset=utf8', date: 'Fri, 12 Jul 2024 22:13:24 GMT' }, counter: 0, highWaterMark: 16384 } }
内容的提问来源于stack exchange,提问作者hectorHumanDev
相关产品推荐
相关产品推荐

