VietCat commited on
Commit
a4c95d4
·
1 Parent(s): 316fdae

fix duplicate message

Browse files
Files changed (1) hide show
  1. app/sheets.py +9 -11
app/sheets.py CHANGED
@@ -121,7 +121,7 @@ class SheetsClient:
121
  conversation_id: str,
122
  user_id: str,
123
  page_id: str,
124
- message: str,
125
  command: str = "",
126
  content: str = "",
127
  attachments: Optional[List[str]] = None,
@@ -133,8 +133,7 @@ class SheetsClient:
133
  ) -> Optional[Dict[str, Any]]:
134
  """
135
  Ghi log hội thoại vào Google Sheets.
136
- Input: user_id, page_id, message, command, content, attachments, vehicle, is_done
137
- Output: Dict containing the conversation data if successful, None if error
138
  """
139
  try:
140
  if not self.service:
@@ -187,7 +186,7 @@ class SheetsClient:
187
  json.dumps(attachments or []),
188
  user_id,
189
  page_id,
190
- message,
191
  vehicle,
192
  action,
193
  purpose,
@@ -207,7 +206,7 @@ class SheetsClient:
207
  body=body
208
  ).execute()
209
 
210
- logger.info(f"Thêm mới conversation: {conversation_id} | Giá trị: {dict(zip(['conversation_id','command','content','attachments','user_id','page_id','message','vehicle','action','purpose','timestamp','is_done'], new_row))}")
211
 
212
  # Return the conversation data directly
213
  return {
@@ -217,7 +216,7 @@ class SheetsClient:
217
  'originalattachments': attachments or [],
218
  'recipient_id': user_id,
219
  'page_id': page_id,
220
- 'originaltext': message,
221
  'originalvehicle': vehicle,
222
  'originalaction': action,
223
  'originalpurpose': purpose,
@@ -254,7 +253,7 @@ class SheetsClient:
254
  json.dumps(attachments) if attachments is not None else current_row[3],
255
  user_id if user_id else current_row[4],
256
  page_id if page_id else current_row[5],
257
- message if message else current_row[6],
258
  vehicle if vehicle else current_row[7],
259
  action if action else current_row[8],
260
  purpose if purpose else current_row[9],
@@ -272,12 +271,11 @@ class SheetsClient:
272
  valueInputOption='RAW',
273
  body=body
274
  ).execute()
275
- changed_cols = []
276
- col_names = ['conversation_id','command','content','attachments','user_id','page_id','message','vehicle','action','purpose','timestamp','is_done']
277
  for idx, (old, new) in enumerate(zip(current_row, new_row)):
278
  if old != new:
279
- changed_cols.append(col_names[idx])
280
- logger.info(f"Cập nhật conversation: {conversation_id} tại dòng {sheet_row_number} | Cột cập nhật: {changed_cols} | Giá trị mới: {dict(zip(col_names, new_row))}")
281
 
282
  # Return the updated conversation data
283
  return {
 
121
  conversation_id: str,
122
  user_id: str,
123
  page_id: str,
124
+ originaltext: str = "",
125
  command: str = "",
126
  content: str = "",
127
  attachments: Optional[List[str]] = None,
 
133
  ) -> Optional[Dict[str, Any]]:
134
  """
135
  Ghi log hội thoại vào Google Sheets.
136
+ Dùng originaltext cho cột message trong sheet các logic liên quan.
 
137
  """
138
  try:
139
  if not self.service:
 
186
  json.dumps(attachments or []),
187
  user_id,
188
  page_id,
189
+ originaltext,
190
  vehicle,
191
  action,
192
  purpose,
 
206
  body=body
207
  ).execute()
208
 
209
+ logger.info(f"Thêm mới conversation: {conversation_id} | Giá trị: {dict(zip(['conversation_id','command','content','attachments','user_id','page_id','originaltext','vehicle','action','purpose','timestamp','is_done'], new_row))}")
210
 
211
  # Return the conversation data directly
212
  return {
 
216
  'originalattachments': attachments or [],
217
  'recipient_id': user_id,
218
  'page_id': page_id,
219
+ 'originaltext': originaltext,
220
  'originalvehicle': vehicle,
221
  'originalaction': action,
222
  'originalpurpose': purpose,
 
253
  json.dumps(attachments) if attachments is not None else current_row[3],
254
  user_id if user_id else current_row[4],
255
  page_id if page_id else current_row[5],
256
+ originaltext if originaltext else current_row[6],
257
  vehicle if vehicle else current_row[7],
258
  action if action else current_row[8],
259
  purpose if purpose else current_row[9],
 
271
  valueInputOption='RAW',
272
  body=body
273
  ).execute()
274
+ changed_cols = ['conversation_id','command','content','attachments','user_id','page_id','originaltext','vehicle','action','purpose','timestamp','is_done']
 
275
  for idx, (old, new) in enumerate(zip(current_row, new_row)):
276
  if old != new:
277
+ changed_cols.append(changed_cols[idx])
278
+ logger.info(f"Cập nhật conversation: {conversation_id} tại dòng {sheet_row_number} | Cột cập nhật: {changed_cols} | Giá trị mới: {dict(zip(changed_cols, new_row))}")
279
 
280
  # Return the updated conversation data
281
  return {