错误:Twilio 找不到具有指定发件人地址的频道

问题描述:

我将 twilio 用于 whatsapp API,但现在的问题是我不断收到此错误

Im using twilio for whatsapp API, but the problem right now is that i keep getting this error

错误:Twilio 找不到具有指定发件人地址的频道

Error: Twilio could not find a Channel with the specified From address

这是代码

const express = require('express')
const accountSid = '-'
const authToken = '-'
const client = require('twilio')(accountSid, authToken)
const request = require('request')

const app = express()


app.get('/test', (req, res, next) => {
    client.messages
      .create({
        body: 'Hello there!',
        from: 'whatsapp:+14155238886',
        to: 'whatsapp:+myNumber'
      })
      .then(message => console.log(message.sid))
      .done()

      res.json('Done')
})

app.listen(3030, (err) => {
    if (err) {
        console.log(err)
    } else {
        console.log('Connected to the port 3030')
    }
})

沙盒图片

我该怎么办?

出现此错误的原因有 3 个.

This error occurs due to 1 of 3 reasons.

  • 您的消息传递 API 请求中的 From 地址不正确.要使用 WhatsApp 发送消息,From 地址应该是 whatsapp:.这可以在 Twilio 的沙箱页面上找到.

  • The From address in your Messaging API request is incorrect. To send messages using WhatsApp, the From address should be whatsapp:<sandbox phone number>. This can be found on the sandbox page in Twilio.

您正在尝试从没有激活沙箱的帐户发送消息.

You are trying to send a message from an account that does not have an activated sandbox.

您正在使用您的测试帐户 SID 和 TOKEN.无论出于何种原因,在使用 WhatsApp 沙盒进行测试时,Twilio 都需要您的生产帐户 SID 和令牌.

You are using your test Account SID and TOKEN. For whatever reason, Twilio needs your Production Account SID and TOKEN when using the WhatsApp sandbox for testing.