VietCat commited on
Commit
dbbd289
·
1 Parent(s): 135c478

fix duplicate message

Browse files
Files changed (1) hide show
  1. app/main.py +12 -4
app/main.py CHANGED
@@ -69,6 +69,15 @@ executor = ThreadPoolExecutor(max_workers=4)
69
 
70
  message_text = None
71
 
 
 
 
 
 
 
 
 
 
72
  @app.get("/")
73
  async def root():
74
  """Endpoint root để kiểm tra trạng thái app."""
@@ -195,7 +204,7 @@ async def process_message(message_data: Dict[str, Any]):
195
  if history:
196
  # 1. Chặn duplicate message (trùng sender_id, page_id, timestamp)
197
  for row in history:
198
- row_timestamps = row.get('timestamp', [])
199
  if isinstance(row_timestamps, list) and len(row_timestamps) == 1 and isinstance(row_timestamps[0], list):
200
  row_timestamps = row_timestamps[0]
201
  if (
@@ -233,8 +242,7 @@ async def process_message(message_data: Dict[str, Any]):
233
  conv[key] = value
234
  logger.info(f"[DEBUG] Message history sau update: {conv}")
235
  # Thêm timestamp mới nếu chưa có
236
- if isinstance(conv['timestamp'], list) and len(conv['timestamp']) == 1 and isinstance(conv['timestamp'][0], list):
237
- conv['timestamp'] = conv['timestamp'][0]
238
  if timestamp not in conv['timestamp']:
239
  conv['timestamp'].append(timestamp)
240
 
@@ -286,7 +294,7 @@ async def process_message(message_data: Dict[str, Any]):
286
  'originalvehicle': ','.join(keywords),
287
  'originalaction': hanh_vi_vi_pham,
288
  'originalpurpose': muc_dich,
289
- 'timestamp': conv['timestamp'],
290
  'isdone': False
291
  }
292
 
 
69
 
70
  message_text = None
71
 
72
+ def flatten_timestamp(ts):
73
+ flat = []
74
+ for t in ts:
75
+ if isinstance(t, list):
76
+ flat.extend(flatten_timestamp(t))
77
+ else:
78
+ flat.append(t)
79
+ return flat
80
+
81
  @app.get("/")
82
  async def root():
83
  """Endpoint root để kiểm tra trạng thái app."""
 
204
  if history:
205
  # 1. Chặn duplicate message (trùng sender_id, page_id, timestamp)
206
  for row in history:
207
+ row_timestamps = flatten_timestamp(row.get('timestamp', []))
208
  if isinstance(row_timestamps, list) and len(row_timestamps) == 1 and isinstance(row_timestamps[0], list):
209
  row_timestamps = row_timestamps[0]
210
  if (
 
242
  conv[key] = value
243
  logger.info(f"[DEBUG] Message history sau update: {conv}")
244
  # Thêm timestamp mới nếu chưa có
245
+ conv['timestamp'] = flatten_timestamp(conv['timestamp'])
 
246
  if timestamp not in conv['timestamp']:
247
  conv['timestamp'].append(timestamp)
248
 
 
294
  'originalvehicle': ','.join(keywords),
295
  'originalaction': hanh_vi_vi_pham,
296
  'originalpurpose': muc_dich,
297
+ 'timestamp': flatten_timestamp(conv['timestamp']),
298
  'isdone': False
299
  }
300