Twilio客户端错误:使用AWS Lambda / AWS API网关进行Twilio IP消息传递

我试图做一个简单的聊天应用程序基于Twilio的例子( https://github.com/TwilioDevEd/ipm-quickstart-node )。 我能够快速启动并运行。

我想修改一下

  1. 无论何时用户通过Web界面( http://localhost:3000 )发送消息,都会触发Twilio的webhook。
  2. 这个webhook PING一个映射到AWS Lambda函数的AWS API端点。
  3. 此AWS Lambda函数接收Channel Sid,进行身份validation,并简单回复“您说了什么?

我已经正确设置了AWS Lambda和AWS API网关。

以下是我的Lambda代码示例:

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

在客户端,Twilio给我一个50056错误( https://www.twilio.com/docs/api/errors/50056 ),里面写着“Webhook取消命令的处理”。 根据文档,有可能我的函数没有返回HTTP 200状态,这是没有意义的,因为当我尝试使用PostMan进行ping时,我收到200状态码。

如果通过AWS Cloudfront日志进行检查,则应该尝试通过Web界面聊天来触发AWS Lambdafunction,甚至不会调用Lambda函数。

另一方面,如果我尝试通过诸如PostMan之类的工具对此AWS Lambda函数进行PING,则AWS Cloudfront日志会显示该函数已被调用,尽pipe由于Channel Sid不是正确的,所以不会进行回复。

我如何解决50056错误? 或者Twilio的IP消息系统webhooks可能不允许PINGing AWS API端点?

谢谢!

回答我自己的问题: – 如果我更改Twilio webhook GET请求,它的工作原理!

所以我怀疑AWS Lambda对POST请求没有很快的反应,或者Twilio的webhook也希望POST请求真的很快。