fix remove retry
Browse files- app/main.py +20 -5
app/main.py
CHANGED
|
@@ -174,12 +174,20 @@ async def process_message(message_data: Dict[str, Any]):
|
|
| 174 |
)
|
| 175 |
logger.info(f"[DEBUG] history: {history}")
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
-
|
| 183 |
page_token = supabase_client.get_page_token(page_id)
|
| 184 |
if page_token:
|
| 185 |
logger.info(f"[DEBUG] page_token: {page_token[:10]} ... {page_token[-10:]}")
|
|
@@ -234,6 +242,7 @@ async def process_message(message_data: Dict[str, Any]):
|
|
| 234 |
|
| 235 |
# 1. Nếu history rỗng (conversation mới)
|
| 236 |
if not history:
|
|
|
|
| 237 |
if not command:
|
| 238 |
if keywords:
|
| 239 |
# Có thông tin phương tiện
|
|
@@ -278,6 +287,12 @@ async def process_message(message_data: Dict[str, Any]):
|
|
| 278 |
log_kwargs[key] = history_val # Ưu tiên giá trị từ lịch sử
|
| 279 |
# --- END cập nhật log_kwargs ---
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
if not last_command:
|
| 282 |
# Lịch sử không có command
|
| 283 |
if keywords:
|
|
|
|
| 174 |
)
|
| 175 |
logger.info(f"[DEBUG] history: {history}")
|
| 176 |
|
| 177 |
+
# 1. Chặn duplicate message (trùng sender_id, page_id, timestamp)
|
| 178 |
+
for row in history:
|
| 179 |
+
if (
|
| 180 |
+
str(row.get('timestamp')) == str(timestamp)
|
| 181 |
+
and str(row.get('recipient_id')) == str(sender_id)
|
| 182 |
+
and str(row.get('page_id')) == str(page_id)
|
| 183 |
+
):
|
| 184 |
+
logger.info("[DUPLICATE] Message duplicate, skipping log.")
|
| 185 |
+
return
|
| 186 |
+
|
| 187 |
+
# Tìm conversation chưa kết thúc (isdone = false)
|
| 188 |
+
open_conv = next((row for row in history if not row.get('isdone')), None)
|
| 189 |
|
| 190 |
+
# Get page access token (sync)
|
| 191 |
page_token = supabase_client.get_page_token(page_id)
|
| 192 |
if page_token:
|
| 193 |
logger.info(f"[DEBUG] page_token: {page_token[:10]} ... {page_token[-10:]}")
|
|
|
|
| 242 |
|
| 243 |
# 1. Nếu history rỗng (conversation mới)
|
| 244 |
if not history:
|
| 245 |
+
log_kwargs['conversation_id'] = None
|
| 246 |
if not command:
|
| 247 |
if keywords:
|
| 248 |
# Có thông tin phương tiện
|
|
|
|
| 287 |
log_kwargs[key] = history_val # Ưu tiên giá trị từ lịch sử
|
| 288 |
# --- END cập nhật log_kwargs ---
|
| 289 |
|
| 290 |
+
# Đảm bảo truyền đúng conversation_id khi update
|
| 291 |
+
if open_conv:
|
| 292 |
+
log_kwargs['conversation_id'] = open_conv['conversation_id']
|
| 293 |
+
else:
|
| 294 |
+
log_kwargs['conversation_id'] = None
|
| 295 |
+
|
| 296 |
if not last_command:
|
| 297 |
# Lịch sử không có command
|
| 298 |
if keywords:
|