AWS API Gateway 및 AWS Lambda에서 Facebook Bot 만들기
18524 단어 람다GClueAPIGatewayFacebookfabo
사전 준비
AWS API Gateway 및 AWS Lambda에서 HelloWorld 만들기
ぃ tp // 코 m / 아키라 사사키 / ms / b9 8 8 0330818 3b71d
Facebook 앱 만들기




Reload를 누릅니다.


Facebook 페이지 만들기






AWS Lambda 생성

메시지 수신을 위한 스크립트
FacebookBotCallbackexports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
}











Cloud Watch에서 로그 확인






Validation용 Script
FacebookBotValidationvar validationToken = "ValidationToken";
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
if (!event["hub.verify_token"] || !event["hub.challenge"]) {
context.fail("invalid parameter");
return;
}
if (event["hub.verify_token"] === validationToken) {
context.done(null, Number(event["hub.challenge"]));
} else {
context.fail("validation failed");
}
};






AWS API Gateway



수신을 위한 POST 메소드 작성




Curl로 호출해 본다.
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POd '{"key1":"test1","key2":"test2","key3":"test3"}' https://#####.execute-api.ap-northeast-1.amazonaws.com/botcallback/botcallback
Cloud Watch에서 로그 확인





Validation용 GET 메서드 만들기












Reload를 누릅니다.


Facebook 페이지 만들기






AWS Lambda 생성

메시지 수신을 위한 스크립트
FacebookBotCallbackexports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
}











Cloud Watch에서 로그 확인






Validation용 Script
FacebookBotValidationvar validationToken = "ValidationToken";
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
if (!event["hub.verify_token"] || !event["hub.challenge"]) {
context.fail("invalid parameter");
return;
}
if (event["hub.verify_token"] === validationToken) {
context.done(null, Number(event["hub.challenge"]));
} else {
context.fail("validation failed");
}
};






AWS API Gateway



수신을 위한 POST 메소드 작성




Curl로 호출해 본다.
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POd '{"key1":"test1","key2":"test2","key3":"test3"}' https://#####.execute-api.ap-northeast-1.amazonaws.com/botcallback/botcallback
Cloud Watch에서 로그 확인





Validation용 GET 메서드 만들기









메시지 수신을 위한 스크립트
FacebookBotCallback
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
}











Cloud Watch에서 로그 확인






Validation용 Script
FacebookBotValidation
var validationToken = "ValidationToken";
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
if (!event["hub.verify_token"] || !event["hub.challenge"]) {
context.fail("invalid parameter");
return;
}
if (event["hub.verify_token"] === validationToken) {
context.done(null, Number(event["hub.challenge"]));
} else {
context.fail("validation failed");
}
};






AWS API Gateway



수신을 위한 POST 메소드 작성




Curl로 호출해 본다.
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POd '{"key1":"test1","key2":"test2","key3":"test3"}' https://#####.execute-api.ap-northeast-1.amazonaws.com/botcallback/botcallback
Cloud Watch에서 로그 확인





Validation용 GET 메서드 만들기








curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POd '{"key1":"test1","key2":"test2","key3":"test3"}' https://#####.execute-api.ap-northeast-1.amazonaws.com/botcallback/botcallback
추가.




application/json
{
"hub.verify_token": "$input.params('hub.verify_token')",
"hub.challenge": "$input.params('hub.challenge')"
}
Facebook과 AWS API Gateway 연동



curl -ik -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=토큰"
명령 행에서 실행.



만든 페이지에 메시지 쓰기
작성한 페이지의 메시지 작성
Cloud Watch에서 로그 확인




메시지가 로그에 올 때 성공!
귀환 보트 프로그램 작성
Reference
이 문제에 관하여(AWS API Gateway 및 AWS Lambda에서 Facebook Bot 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/akira-sasaki/items/961cb7a1aa7386764863
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
작성한 페이지의 메시지 작성
Cloud Watch에서 로그 확인




메시지가 로그에 올 때 성공!
귀환 보트 프로그램 작성
Reference
이 문제에 관하여(AWS API Gateway 및 AWS Lambda에서 Facebook Bot 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/akira-sasaki/items/961cb7a1aa7386764863
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(AWS API Gateway 및 AWS Lambda에서 Facebook Bot 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/akira-sasaki/items/961cb7a1aa7386764863텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)