kenken999 commited on
Commit
e0629b3
1 Parent(s): d47fd3e
Files changed (3) hide show
  1. mysite/asgi.py +14 -2
  2. sample.csv +0 -0
  3. workspace/sample.duckdb +2 -2
mysite/asgi.py CHANGED
@@ -627,7 +627,7 @@ logger = logging.getLogger(__name__)
627
  CHANNEL_ID = os.getenv('CHANNEL_ID')
628
  CHANNEL_SECRET = os.getenv('CHANNEL_SECRET')
629
  CHANNEL_ACCESS_TOKEN = os.getenv('CHANNEL_ACCESS_TOKEN')
630
- WEBHOOK_URL = "https://api.coze.com/adapter/line/webhook/7372538698808246290"
631
  import requests
632
  @app.post("/webhook")
633
  async def webhook(request: Request):
@@ -640,10 +640,22 @@ async def webhook(request: Request):
640
  logger.info('Received Headers: %s', received_headers)
641
  logger.info('Received Body: %s', body.decode('utf-8'))
642
 
643
- # 送信先のURLとヘッダー
 
 
 
 
 
 
 
 
 
644
  headers = {key: value for key, value in received_headers.items()}
645
  headers['Authorization'] = f'Bearer {CHANNEL_ACCESS_TOKEN}' # 認証トークンを追加
646
 
 
 
 
647
  # データを転送
648
  response = requests.post(WEBHOOK_URL, headers=headers, data=body)
649
 
 
627
  CHANNEL_ID = os.getenv('CHANNEL_ID')
628
  CHANNEL_SECRET = os.getenv('CHANNEL_SECRET')
629
  CHANNEL_ACCESS_TOKEN = os.getenv('CHANNEL_ACCESS_TOKEN')
630
+ WEBHOOK_URL = os.getenv('WEBHOOK_URL')
631
  import requests
632
  @app.post("/webhook")
633
  async def webhook(request: Request):
 
640
  logger.info('Received Headers: %s', received_headers)
641
  logger.info('Received Body: %s', body.decode('utf-8'))
642
 
643
+ # 必要なヘッダー情報を抽出
644
+ line_signature = received_headers.get('x-line-signature')
645
+ if not line_signature:
646
+ raise HTTPException(status_code=400, detail="X-Line-Signature header is missing.")
647
+
648
+ # 署名を検証
649
+ if not validate_signature(body.decode('utf-8'), line_signature, os.getenv('CHANNEL_SECRET')):
650
+ raise HTTPException(status_code=400, detail="Invalid signature.")
651
+
652
+ # 送信するヘッダーを設定
653
  headers = {key: value for key, value in received_headers.items()}
654
  headers['Authorization'] = f'Bearer {CHANNEL_ACCESS_TOKEN}' # 認証トークンを追加
655
 
656
+ # ログに転送先URLを記録
657
+ logger.info('Forwarding to URL: %s', WEBHOOK_URL)
658
+
659
  # データを転送
660
  response = requests.post(WEBHOOK_URL, headers=headers, data=body)
661
 
sample.csv CHANGED
The diff for this file is too large to render. See raw diff
 
workspace/sample.duckdb CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7dd4e50b45bf63d6559530169865f5ebbc89b73b78dd6f1f490828b79fa504d4
3
- size 12288
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5feab3c6ad6f1a743f0216146bf119734da52492ab89a3bea577c5165a4584e9
3
+ size 798720