Spaces:
Running
on
Zero
Running
on
Zero
df
Browse files- mysite/asgi.py +9 -20
mysite/asgi.py
CHANGED
@@ -633,38 +633,27 @@ import requests
|
|
633 |
async def webhook(request: Request):
|
634 |
try:
|
635 |
# 受信したデータとヘッダーを取得
|
636 |
-
|
637 |
-
received_headers = request.headers
|
638 |
|
639 |
# ログに記録
|
640 |
-
logger.info('Received Data: %s', received_data)
|
641 |
logger.info('Received Headers: %s', received_headers)
|
642 |
-
|
643 |
-
# 必要なヘッダー情報を抽出
|
644 |
-
line_signature = None
|
645 |
-
for header in received_headers.raw:
|
646 |
-
if header[0].decode('utf-8').lower() == 'x-line-signature':
|
647 |
-
line_signature = header[1].decode('utf-8')
|
648 |
-
break
|
649 |
-
|
650 |
-
if not line_signature:
|
651 |
-
raise HTTPException(status_code=400, detail="X-Line-Signature header is missing.")
|
652 |
|
653 |
# 送信先のURLとヘッダー
|
654 |
-
headers = {
|
655 |
-
|
656 |
-
'X-Line-Signature': line_signature,
|
657 |
-
'Authorization': f'Bearer {CHANNEL_ACCESS_TOKEN}'
|
658 |
-
}
|
659 |
|
660 |
# データを転送
|
661 |
-
response = requests.post(WEBHOOK_URL,
|
662 |
|
663 |
# レスポンスをログに記録
|
664 |
logger.info('Response Code: %s', response.status_code)
|
665 |
logger.info('Response Content: %s', response.text)
|
|
|
666 |
|
667 |
-
|
|
|
668 |
|
669 |
except Exception as e:
|
670 |
logger.error("Error: %s", str(e))
|
|
|
633 |
async def webhook(request: Request):
|
634 |
try:
|
635 |
# 受信したデータとヘッダーを取得
|
636 |
+
body = await request.body()
|
637 |
+
received_headers = dict(request.headers)
|
638 |
|
639 |
# ログに記録
|
|
|
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 |
|
650 |
# レスポンスをログに記録
|
651 |
logger.info('Response Code: %s', response.status_code)
|
652 |
logger.info('Response Content: %s', response.text)
|
653 |
+
logger.info('Response Headers: %s', response.headers)
|
654 |
|
655 |
+
# クライアントにレスポンスを返却
|
656 |
+
return {"status": "success", "response_content": response.text}, response.status_code
|
657 |
|
658 |
except Exception as e:
|
659 |
logger.error("Error: %s", str(e))
|