2016-06-19 4 views
1

Twilio의 예 (https://github.com/TwilioDevEd/ipm-quickstart-node)를 기반으로 간단한 채팅 응용 프로그램을 만들려고했습니다. 나는 이것을 깨닫고 빨리 달릴 수있다.Twilio 클라이언트 오류 : Twilio IP 메시징 (AWS Lambda/AWS API 게이트웨이)

나는

사용자가 웹 인터페이스 ( http://localhost:3000)를 통해 메시지를 보낼 때마다
  1. , 그것은 Twilio의은 webhook를 트리거하도록 약간 수정하려는.
  2. 이 웹 훅은 AWS 람다 기능에 매핑되는 AWS API 끝점을 핑 (ping)합니다.
  3. 이 AWS 람다 함수는 채널 Sid 인 을 인증하고 단순히 "무엇을 말합니까?"라고 대답합니다.

필자는 AWS Lambda 및 AWS API Gateway를 올바르게 설정했습니다.

클라이언트 측에
'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 람다 함수를 트리거하려고하면 AWS Cloudfront 로그를 통해 확인하면서 람다 함수가 호출되지 않았습니다.

반면에 PostMan과 같은 도구를 통해이 AWS Lambda 함수에 Ping을 시도하면 AWS Cloudfront 로그는 채널 Sid가 올바른 것이 아니기 때문에 응답이 없어도 함수가 호출되었음을 보여줍니다.

50056 오류를 어떻게 해결합니까? 아니면 Twilio의 IP Messaging Webhook이 AWS API 끝점을 Ping 할 수 없습니까?

감사합니다.

답변

2

내 질문에 답변 : - Twilio webhook을 GET 요청으로 변경하면 작동합니다!

그래서 AWS Lambda가 POST 요청에 신속하게 응답하지 않거나 Twilio의 webhook이 POST 요청에 대해 실제로 빠를 것으로 예상합니다.

관련 문제