I was trying to make a simple Chat app based on Twilio's example ( https://github.com/TwilioDevEd/ipm-quickstart-node). I am able to get this up and running quickly.
I want to modify a bit such that
- whenever a user sends a message via the web interface (
http://localhost:3000), it triggers Twilio's webhook. - This webhook PINGs a AWS API endpoint which is mapped to an AWS Lambda function.
- This AWS Lambda function receives the Channel Sid, authenticates, and simply replies "what say you ?"
I have set up my AWS Lambda and AWS API Gateway correctly.
Here's a sample of my Lambda code:
'use strict';
var TWILIO = require('twilio');
var AccessToken = require('twilio').AccessToken;
var IpMessagingGrant = AccessToken.IpMessagingGrant;
var http = require("http");
module.exports.handler = function(event, context, cb) {
var accountSid = 'TWILIO-ACCOUNT-SID';
var authToken = 'TWILIO-AUTH-TOKEN';
var IpMessagingClient = TWILIO.IpMessagingClient;
var client = new TWILIO.IpMessagingClient(accountSid, authToken);
var service = client.services('TWILIO-SERVICE-SID');
service.channels(event.ChannelSid).messages.create({
body: 'what say you ?',
from: FROM
}).then(function(response) {
console.log("this is success");
console.log(response);
//return context.done();
return context.succeed(response);
//return cb(null, response);
}).fail(function(error) {
console.log("this is failure");
console.log(error);
//return context.done();
return context.fail(JSON.parse(error.errorMessage));
//return cb(null, error);
});
};
On the client side, Twilio gives me a 50056 error ( https://www.twilio.com/docs/api/errors/50056 ) which says "Webhook cancelled processing of command". According to the docs, it is possible that my function is not returning a HTTP 200 status, which doesn't make sense as I do receive a 200 status code when i try to ping it using PostMan.
Checking through the AWS Cloudfront logs, the Lambda function was not even called should I attempt to trigger the AWS Lambda function via the web interface chat.
On the other hand, if I try to PING this AWS Lambda function via tools such as PostMan, AWS Cloudfront logs shows that the function was called, albeit no replies will be made since the Channel Sid is not the correct one.
How do i solve the 50056 error? Or is it possible that Twilio's IP Messaging webhooks don't allow PINGing AWS API endpoints ?
Thanks!