Last active
January 12, 2021 13:47
-
-
Save okdtsk/af70f33e2197b759848df8d6a800ce0a to your computer and use it in GitHub Desktop.
Revisions
-
okdtsk revised this gist
Sep 1, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,5 +36,5 @@ def callback(): def handle_text_message(event): line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Reply: {}'.format(event.message.text)) ) -
okdtsk revised this gist
Sep 1, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,5 +36,5 @@ def callback(): def handle_text_message(event): line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Reply to {}'.format(event.message.text)) ) -
okdtsk revised this gist
Sep 1, 2017 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,9 +29,6 @@ def callback(): handler.handle(body, signature) except InvalidSignatureError as e: return Response({'error': e.message}, status_code=400) return Response({'ok': True}) -
okdtsk revised this gist
Sep 1, 2017 . 1 changed file with 2 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,24 +28,15 @@ def callback(): try: handler.handle(body, signature) except InvalidSignatureError as e: return Response({'error': e.message}, status_code=400) except LineBotApiError as e: return Response({'error': e}, status_code=500) return Response({'ok': True}) @handler.add(MessageEvent, message=TextMessage) def handle_text_message(event): line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text) -
okdtsk revised this gist
Sep 1, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,9 +41,10 @@ def callback(): @handler.add(MessageEvent, message=TextMessage) def handle_text_message(event): # Ignore a request for verification # (when pressing 'VERIFY' button in developers console) if event.reply_token in ('00000000000000000000000000000000', 'ffffffffffffffffffffffffffffffff'): return line_bot_api.reply_message( event.reply_token, -
okdtsk revised this gist
Sep 1, 2017 . 1 changed file with 9 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,19 +28,24 @@ def callback(): try: handler.handle(body, signature) except InvalidSignatureError as e: return Response({'ok': False, 'error': e.message}, status_code=400) except LineBotApiError as e: return Response({'ok': False, 'error': 'Failed {}'.format(e)}, status_code=500) return Response({'ok': True}) @handler.add(MessageEvent, message=TextMessage) def handle_text_message(event): if event.reply_token in ('00000000000000000000000000000000', 'ffffffffffffffffffffffffffffffff'): # Ignore a request for verification (when pressing 'VERIFY' button in developers console) return line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text) ) -
okdtsk created this gist
Sep 1, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ { "version": "2.0", "app_name": "./line-bot-for-pycon", "stages": { "dev": { "api_gateway_stage": "dev", "environment_variables": { "LINEBOT_CHANNEL_ACCESS_TOKEN": "blahblahblah", "LINEBOT_CHANNEL_SECRET": "blahblahblah" } }, "prod": { "api_gateway_stage": "prod", "environment_variables": { "LINEBOT_CHANNEL_ACCESS_TOKEN": "blahblahblah", "LINEBOT_CHANNEL_SECRET": "blahblahblah" } } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ #!/usr/bin/env python import os from chalice import Chalice from chalice import Response from linebot import LineBotApi from linebot import WebhookHandler from linebot.models import MessageEvent from linebot.models import TextMessage from linebot.models import TextSendMessage from linebot.exceptions import InvalidSignatureError from linebot.exceptions import LineBotApiError app = Chalice(app_name='line-bot') line_bot_api = LineBotApi(os.environ['LINEBOT_CHANNEL_ACCESS_TOKEN']) handler = WebhookHandler(os.environ['LINEBOT_CHANNEL_SECRET']) @app.route('/callback', methods=['POST']) def callback(): signature = app.current_request.headers['X-Line-Signature'] body = app.current_request.raw_body.decode('utf-8') try: handler.handle(body, signature) except InvalidSignatureError as e: return Response({'ok': False, 'error': e.message}, status_code=400) except LineBotApiError as e: return Response({'ok': False, 'error': 'Failed to call line bot api {}'.format(e)}, status_code=500) return Response({'ok': True}) @handler.add(MessageEvent, message=TextMessage) def handle_text_message(event): if event.reply_token in ('00000000000000000000000000000000', 'ffffffffffffffffffffffffffffffff'): # Ignore a request for verification (when pressing 'VERIFY' button in developers console) return line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Reply to {}'.format(event.message.text)) )