Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -141,13 +141,17 @@ async def webhook(
|
|
141 |
body = await request.body()
|
142 |
try:
|
143 |
background_tasks.add_task(
|
144 |
-
|
145 |
)
|
146 |
except InvalidSignatureError:
|
147 |
logging.warning("收到無效的簽章")
|
148 |
raise HTTPException(status_code=400, detail="無效的簽章")
|
149 |
return "ok"
|
150 |
|
|
|
|
|
|
|
|
|
151 |
# --- 4. 對話 Session 管理 ---
|
152 |
class ChatSessionManager:
|
153 |
"""
|
|
|
141 |
body = await request.body()
|
142 |
try:
|
143 |
background_tasks.add_task(
|
144 |
+
self.run_sync_handler, line_bot_manager.line_handler, body.decode("utf-8"), x_line_signature # 修改這裡
|
145 |
)
|
146 |
except InvalidSignatureError:
|
147 |
logging.warning("收到無效的簽章")
|
148 |
raise HTTPException(status_code=400, detail="無效的簽章")
|
149 |
return "ok"
|
150 |
|
151 |
+
# 定義一個方法讓 line_handler 可以正確處理非同步事件
|
152 |
+
async def run_sync_handler(handler, body, signature):
|
153 |
+
await asyncio.to_thread(handler.handle, body, signature)
|
154 |
+
|
155 |
# --- 4. 對話 Session 管理 ---
|
156 |
class ChatSessionManager:
|
157 |
"""
|