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.