1
votes

Trying to replace my workplace's Twilio implementation with a temporary solution while we move from one platform to another, and I thought Webtask would be a great solution. I was very happy to see that there was a default Twilio template for webtask and thought I could get straight to work but for some reason, I can't get the template to work even with it's default functionality.

I'm worried that I'm not posting what's expected to the webtask. Here's the default code that sits on my webtask:

'use latest';
import twilio from 'twilio';
module.exports = (context, cb) => {
  // POST a json object with at least the following properties.
  const { body, to_number, from_number } = context.data;
  const { TWILIO_SID, TWILIO_AUTH_TOKEN } = context.secrets;
  
  var client = new twilio.RestClient(TWILIO_SID, TWILIO_AUTH_TOKEN);
  client.messages.create({
    body,
    to_number,
    from_number
  }, (err, message) => {
    message = message + " Goodbye World!";
    if (err) return cb(err);
    cb(null, message);
  });
};

And here's what my Postman looks like (with my Twilio phone number and personal phone number supplied to from_number and to_number in the actual code obv). Headers: postman-headers Body: postman-body

I've stored my Auth token and SID in the secrets area. When I make this post, I receive:

{
    "code": 400,
    "error": "Script returned an error.",
    "details": {
        "status": 400,
        "message": "A 'From' phone number is required.",
        "code": 21603,
        "moreInfo": "https://www.twilio.com/docs/errors/21603"
    },
    "message": "A 'From' phone number is required."
}

I've tried several things, like setting the from_number in the code like this const from_number = "+19999999999" except with a real number. Even so, I get the same 400 response (I also tried adding the SID as a username and the Auth Token as a password, as mentioned in this answer -- same result). I really want to get webtask working, if at all possible.

1
May i see the twilio endpoint url ?Sebastian SALAMANCA

1 Answers

1
votes

Twilio developer evangelist here.

When you're making the call to Twilio to send the message you are using the wrong attribute names. Instead of

client.messages.create({
    body,
    to_number,
    from_number
  }, (err, message) => { //... } );

it should be:

client.messages.create({
    body,
    to: to_number,
    from: from_number
  }, (err, message) => { //... } );

Twilio expects the attributes to be called to and from not to_number and from_number.

Let me know if this helps.