AWS API Gateway 및 AWS Lambda에서 Facebook Bot 만들기
18524 단어 람다GClueAPIGatewayFacebookfabo
사전 준비
AWS API Gateway 및 AWS Lambda에서 HelloWorld 만들기
ぃ tp // 코 m / 아키라 사사키 / ms / b9 8 8 0330818 3b71d
Facebook 앱 만들기
![](https://s1.md5.ltd/image/6539af4ee73bd00490882eb7c91ef0c6.png)
![](https://s1.md5.ltd/image/94fd9232338821735365f085b0f5ac4c.png)
![](https://s1.md5.ltd/image/539751f435d06dd93fa9c1131bf2fe35.png)
![](https://s1.md5.ltd/image/956a8fb9908f9240514aa7c72f48b40a.png)
Reload를 누릅니다.
![](https://s1.md5.ltd/image/405d40d5461ce821add4f5e007a4d543.png)
![](https://s1.md5.ltd/image/2c16484c90a73f311bbd10cd5b7213df.png)
Facebook 페이지 만들기
![](https://s1.md5.ltd/image/ecef2e346d3da7743641b5c1bd944148.png)
![](https://s1.md5.ltd/image/eb6e5264d44a42bb9422c40505f887f7.png)
![](https://s1.md5.ltd/image/4c447f243ce5c8b45c4bc180dd35ad4b.png)
![](https://s1.md5.ltd/image/494aca1dc449f77bedabb296761b6911.png)
![](https://s1.md5.ltd/image/fbe3637ba92436cdc62fce4a1e481ca6.png)
![](https://s1.md5.ltd/image/91c210ebb8a339701cf3384c039aba68.png)
AWS Lambda 생성
![](https://s1.md5.ltd/image/9495787645bb827750ae2994bb9d9c5c.png)
메시지 수신을 위한 스크립트
FacebookBotCallbackexports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
}
![](https://s1.md5.ltd/image/3de9668f736d5d6d91545149e08b7d5a.png)
![](https://s1.md5.ltd/image/6abe1d9a22ed3d5a5eccbabb7c5318ac.png)
![](https://s1.md5.ltd/image/2f6dddbb14b2629f4a7731e6019aa76e.png)
![](https://s1.md5.ltd/image/324ba94b7aebd2ad5e8d6c3a829aeb1f.png)
![](https://s1.md5.ltd/image/1e1fad80b47b7520fa53a26df1959e6d.png)
![](https://s1.md5.ltd/image/a31dfeef60cb3d9d0fa11f6ad0af48f8.png)
![](https://s1.md5.ltd/image/12dc30d78318c35ca550fc9e6c3d33e3.png)
![](https://s1.md5.ltd/image/5da1efc358fc42ab4cad69fab103b369.png)
![](https://s1.md5.ltd/image/040d8221eb6a18ff60e62b87b89493af.png)
![](https://s1.md5.ltd/image/38be9c9b70d7b3d146a8be108890125b.png)
![](https://s1.md5.ltd/image/9d58d4cd5cf860be7744b7b2be467895.png)
Cloud Watch에서 로그 확인
![](https://s1.md5.ltd/image/17e8127eef41863ddc09bd399167d7f2.png)
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
![](https://s1.md5.ltd/image/3bacdd5fed556f766dd027a51f41e510.png)
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");
}
};
![](https://s1.md5.ltd/image/becfb06b442e70f1674d6d8163a8bafc.png)
![](https://s1.md5.ltd/image/6abe1d9a22ed3d5a5eccbabb7c5318ac.png)
![](https://s1.md5.ltd/image/ef80966038532b7f44dcb37772a3dfa5.png)
![](https://s1.md5.ltd/image/cfde6711c9cb9c78c8f0da57b527d844.png)
![](https://s1.md5.ltd/image/7f76700f5a427d13b6534ae53720e5ec.png)
![](https://s1.md5.ltd/image/418f60fde84879f2a59303c2d87a8b47.png)
AWS API Gateway
![](https://s1.md5.ltd/image/de5c8d01ba6aab072d043185e613ec0e.png)
![](https://s1.md5.ltd/image/45f542da3fb59600e3770883a47343fc.png)
![](https://s1.md5.ltd/image/a13ab7145fb430696753fc56ed2402a3.png)
수신을 위한 POST 메소드 작성
![](https://s1.md5.ltd/image/2e47cd7d71a120ea2139632c2c9fe823.png)
![](https://s1.md5.ltd/image/f2809b2385f85fca5441714a49d14702.png)
![](https://s1.md5.ltd/image/f7b2a369f91258be9d819ee5a716bb5d.png)
![](https://s1.md5.ltd/image/0f3abfeaa41180e9ff7bf4cac5908312.png)
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에서 로그 확인
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
![](https://s1.md5.ltd/image/8854f65ac6cc33136964bee9def80b69.png)
Validation용 GET 메서드 만들기
![](https://s1.md5.ltd/image/ec761fa0341704b83e16efec42bb5d3d.png)
![](https://s1.md5.ltd/image/535e06cf738f2b55793425284773d62e.png)
![](https://s1.md5.ltd/image/cf1c616615aec0b9268fc7913f6c37d6.png)
![](https://s1.md5.ltd/image/e19042550fb6ac5a575aec88abcfd3b4.png)
![](https://s1.md5.ltd/image/0c94064c1a63767b6d592ea8528e9764.png)
![](https://s1.md5.ltd/image/042a78e9c0d030643221cb0b29b6a884.png)
![](https://s1.md5.ltd/image/d2b935332b71c75a1d08304bc789325b.png)
![](https://s1.md5.ltd/image/c5c6c514cf1442a0fe1ed33eabd2b6e2.png)
![](https://s1.md5.ltd/image/6539af4ee73bd00490882eb7c91ef0c6.png)
![](https://s1.md5.ltd/image/94fd9232338821735365f085b0f5ac4c.png)
![](https://s1.md5.ltd/image/539751f435d06dd93fa9c1131bf2fe35.png)
![](https://s1.md5.ltd/image/956a8fb9908f9240514aa7c72f48b40a.png)
Reload를 누릅니다.
![](https://s1.md5.ltd/image/405d40d5461ce821add4f5e007a4d543.png)
![](https://s1.md5.ltd/image/2c16484c90a73f311bbd10cd5b7213df.png)
Facebook 페이지 만들기
![](https://s1.md5.ltd/image/ecef2e346d3da7743641b5c1bd944148.png)
![](https://s1.md5.ltd/image/eb6e5264d44a42bb9422c40505f887f7.png)
![](https://s1.md5.ltd/image/4c447f243ce5c8b45c4bc180dd35ad4b.png)
![](https://s1.md5.ltd/image/494aca1dc449f77bedabb296761b6911.png)
![](https://s1.md5.ltd/image/fbe3637ba92436cdc62fce4a1e481ca6.png)
![](https://s1.md5.ltd/image/91c210ebb8a339701cf3384c039aba68.png)
AWS Lambda 생성
![](https://s1.md5.ltd/image/9495787645bb827750ae2994bb9d9c5c.png)
메시지 수신을 위한 스크립트
FacebookBotCallbackexports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
}
![](https://s1.md5.ltd/image/3de9668f736d5d6d91545149e08b7d5a.png)
![](https://s1.md5.ltd/image/6abe1d9a22ed3d5a5eccbabb7c5318ac.png)
![](https://s1.md5.ltd/image/2f6dddbb14b2629f4a7731e6019aa76e.png)
![](https://s1.md5.ltd/image/324ba94b7aebd2ad5e8d6c3a829aeb1f.png)
![](https://s1.md5.ltd/image/1e1fad80b47b7520fa53a26df1959e6d.png)
![](https://s1.md5.ltd/image/a31dfeef60cb3d9d0fa11f6ad0af48f8.png)
![](https://s1.md5.ltd/image/12dc30d78318c35ca550fc9e6c3d33e3.png)
![](https://s1.md5.ltd/image/5da1efc358fc42ab4cad69fab103b369.png)
![](https://s1.md5.ltd/image/040d8221eb6a18ff60e62b87b89493af.png)
![](https://s1.md5.ltd/image/38be9c9b70d7b3d146a8be108890125b.png)
![](https://s1.md5.ltd/image/9d58d4cd5cf860be7744b7b2be467895.png)
Cloud Watch에서 로그 확인
![](https://s1.md5.ltd/image/17e8127eef41863ddc09bd399167d7f2.png)
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
![](https://s1.md5.ltd/image/3bacdd5fed556f766dd027a51f41e510.png)
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");
}
};
![](https://s1.md5.ltd/image/becfb06b442e70f1674d6d8163a8bafc.png)
![](https://s1.md5.ltd/image/6abe1d9a22ed3d5a5eccbabb7c5318ac.png)
![](https://s1.md5.ltd/image/ef80966038532b7f44dcb37772a3dfa5.png)
![](https://s1.md5.ltd/image/cfde6711c9cb9c78c8f0da57b527d844.png)
![](https://s1.md5.ltd/image/7f76700f5a427d13b6534ae53720e5ec.png)
![](https://s1.md5.ltd/image/418f60fde84879f2a59303c2d87a8b47.png)
AWS API Gateway
![](https://s1.md5.ltd/image/de5c8d01ba6aab072d043185e613ec0e.png)
![](https://s1.md5.ltd/image/45f542da3fb59600e3770883a47343fc.png)
![](https://s1.md5.ltd/image/a13ab7145fb430696753fc56ed2402a3.png)
수신을 위한 POST 메소드 작성
![](https://s1.md5.ltd/image/2e47cd7d71a120ea2139632c2c9fe823.png)
![](https://s1.md5.ltd/image/f2809b2385f85fca5441714a49d14702.png)
![](https://s1.md5.ltd/image/f7b2a369f91258be9d819ee5a716bb5d.png)
![](https://s1.md5.ltd/image/0f3abfeaa41180e9ff7bf4cac5908312.png)
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에서 로그 확인
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
![](https://s1.md5.ltd/image/8854f65ac6cc33136964bee9def80b69.png)
Validation용 GET 메서드 만들기
![](https://s1.md5.ltd/image/ec761fa0341704b83e16efec42bb5d3d.png)
![](https://s1.md5.ltd/image/535e06cf738f2b55793425284773d62e.png)
![](https://s1.md5.ltd/image/cf1c616615aec0b9268fc7913f6c37d6.png)
![](https://s1.md5.ltd/image/e19042550fb6ac5a575aec88abcfd3b4.png)
![](https://s1.md5.ltd/image/0c94064c1a63767b6d592ea8528e9764.png)
![](https://s1.md5.ltd/image/042a78e9c0d030643221cb0b29b6a884.png)
![](https://s1.md5.ltd/image/d2b935332b71c75a1d08304bc789325b.png)
![](https://s1.md5.ltd/image/c5c6c514cf1442a0fe1ed33eabd2b6e2.png)
![](https://s1.md5.ltd/image/9495787645bb827750ae2994bb9d9c5c.png)
메시지 수신을 위한 스크립트
FacebookBotCallback
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
}
![](https://s1.md5.ltd/image/3de9668f736d5d6d91545149e08b7d5a.png)
![](https://s1.md5.ltd/image/6abe1d9a22ed3d5a5eccbabb7c5318ac.png)
![](https://s1.md5.ltd/image/2f6dddbb14b2629f4a7731e6019aa76e.png)
![](https://s1.md5.ltd/image/324ba94b7aebd2ad5e8d6c3a829aeb1f.png)
![](https://s1.md5.ltd/image/1e1fad80b47b7520fa53a26df1959e6d.png)
![](https://s1.md5.ltd/image/a31dfeef60cb3d9d0fa11f6ad0af48f8.png)
![](https://s1.md5.ltd/image/12dc30d78318c35ca550fc9e6c3d33e3.png)
![](https://s1.md5.ltd/image/5da1efc358fc42ab4cad69fab103b369.png)
![](https://s1.md5.ltd/image/040d8221eb6a18ff60e62b87b89493af.png)
![](https://s1.md5.ltd/image/38be9c9b70d7b3d146a8be108890125b.png)
![](https://s1.md5.ltd/image/9d58d4cd5cf860be7744b7b2be467895.png)
Cloud Watch에서 로그 확인
![](https://s1.md5.ltd/image/17e8127eef41863ddc09bd399167d7f2.png)
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
![](https://s1.md5.ltd/image/3bacdd5fed556f766dd027a51f41e510.png)
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");
}
};
![](https://s1.md5.ltd/image/becfb06b442e70f1674d6d8163a8bafc.png)
![](https://s1.md5.ltd/image/6abe1d9a22ed3d5a5eccbabb7c5318ac.png)
![](https://s1.md5.ltd/image/ef80966038532b7f44dcb37772a3dfa5.png)
![](https://s1.md5.ltd/image/cfde6711c9cb9c78c8f0da57b527d844.png)
![](https://s1.md5.ltd/image/7f76700f5a427d13b6534ae53720e5ec.png)
![](https://s1.md5.ltd/image/418f60fde84879f2a59303c2d87a8b47.png)
AWS API Gateway
![](https://s1.md5.ltd/image/de5c8d01ba6aab072d043185e613ec0e.png)
![](https://s1.md5.ltd/image/45f542da3fb59600e3770883a47343fc.png)
![](https://s1.md5.ltd/image/a13ab7145fb430696753fc56ed2402a3.png)
수신을 위한 POST 메소드 작성
![](https://s1.md5.ltd/image/2e47cd7d71a120ea2139632c2c9fe823.png)
![](https://s1.md5.ltd/image/f2809b2385f85fca5441714a49d14702.png)
![](https://s1.md5.ltd/image/f7b2a369f91258be9d819ee5a716bb5d.png)
![](https://s1.md5.ltd/image/0f3abfeaa41180e9ff7bf4cac5908312.png)
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에서 로그 확인
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
![](https://s1.md5.ltd/image/8854f65ac6cc33136964bee9def80b69.png)
Validation용 GET 메서드 만들기
![](https://s1.md5.ltd/image/ec761fa0341704b83e16efec42bb5d3d.png)
![](https://s1.md5.ltd/image/535e06cf738f2b55793425284773d62e.png)
![](https://s1.md5.ltd/image/cf1c616615aec0b9268fc7913f6c37d6.png)
![](https://s1.md5.ltd/image/e19042550fb6ac5a575aec88abcfd3b4.png)
![](https://s1.md5.ltd/image/0c94064c1a63767b6d592ea8528e9764.png)
![](https://s1.md5.ltd/image/042a78e9c0d030643221cb0b29b6a884.png)
![](https://s1.md5.ltd/image/d2b935332b71c75a1d08304bc789325b.png)
![](https://s1.md5.ltd/image/c5c6c514cf1442a0fe1ed33eabd2b6e2.png)
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
추가.
![](https://s1.md5.ltd/image/b8c5b5de579478e67a69746f4305f91f.png)
![](https://s1.md5.ltd/image/287256bdf1cb734f9d35c20f79900e26.png)
![](https://s1.md5.ltd/image/760745c35603239b807bb33c78b9ca60.png)
![](https://s1.md5.ltd/image/366555d355dce959ca10f738f5609cdb.png)
application/json
{
"hub.verify_token": "$input.params('hub.verify_token')",
"hub.challenge": "$input.params('hub.challenge')"
}
Facebook과 AWS API Gateway 연동
![](https://s1.md5.ltd/image/68b48a13c914c39b10f0a8da503a28f1.png)
![](https://s1.md5.ltd/image/d97c70b66e80b418c0ee3fb9138bc08a.png)
![](https://s1.md5.ltd/image/47c909bb01c222245a29f51207c76901.png)
curl -ik -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=토큰"
명령 행에서 실행.
![](https://s1.md5.ltd/image/3963e34c6fb5c5d27e2e141c731f9be0.png)
![](https://s1.md5.ltd/image/0ddadc5e72bfb76c7c8f3a79bbbc158e.png)
![](https://s1.md5.ltd/image/87cca548be85bfefc239634a016d9a94.png)
만든 페이지에 메시지 쓰기
작성한 페이지의 메시지 작성
Cloud Watch에서 로그 확인
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
메시지가 로그에 올 때 성공!
귀환 보트 프로그램 작성
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에서 로그 확인
![](https://s1.md5.ltd/image/879062dbe270347cdd907e81f89b9341.png)
![](https://s1.md5.ltd/image/be7646a123da4f58b2f0a214eeee1395.png)
![](https://s1.md5.ltd/image/ad33bc88af26b36732d4637709727cef.png)
![](https://s1.md5.ltd/image/33893edc054cba0e04c7333e4779aaad.png)
메시지가 로그에 올 때 성공!
귀환 보트 프로그램 작성
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.)