You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 22:40:04