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

吃可爱长大的小学妹 提交于 2019-12-12 14:03:51

问题


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

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

Here's the code

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')
    }
})

Sandbox picture

What should I do?


回答1:


This error occurs due to 1 of 3 reasons.

  • 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.

  • 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.




回答2:


Not sure if it still relevant but I'm currently testing out the Twilio whatsapp API in their sandbox (with a trail account) and I haven't added/bought any phone numbers so far.

What i noticed is that when you send a test messages from their console page and you look closely to the curl request (what is send to the API) on the console page they are always using the production clientid token combination.

While i was implementing the Client i assumed that i should use the test clientid token combination (because of common sense :)) but after inspecting the curl request i switched to the production clientid and token and I was able to send test messages to my own sandbox. (Using the sandbox 'from' phonenumber provided on the same page and only to my own private phonenumber which has been added to the sandbox)

Hope it helps :)



来源:https://stackoverflow.com/questions/51941133/error-twilio-could-not-find-a-channel-with-the-specified-from-address

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!