Fred808 commited on
Commit
65f5508
·
verified ·
1 Parent(s): 4070775

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -279,6 +279,37 @@ def process_order_flow(user_id: str, message: str) -> str:
279
  """
280
  Implements an FSM-based order flow with shipping cost calculation.
281
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  # Retrieve or initialize conversation state
283
  state = user_state.get(user_id)
284
  if state and state.is_expired():
 
279
  """
280
  Implements an FSM-based order flow with shipping cost calculation.
281
  """
282
+
283
+ # Check if the message contains an order ID (e.g., "ord-123456789")
284
+ order_id_match = re.search(r"ord-\d+", message.lower())
285
+ if order_id_match:
286
+ order_id = order_id_match.group(0)
287
+ # Fetch order tracking details
288
+ async def fetch_order_tracking():
289
+ async with async_session() as session:
290
+ result = await session.execute(
291
+ select(OrderTracking)
292
+ .where(OrderTracking.order_id == order_id)
293
+ .order_by(OrderTracking.timestamp)
294
+ )
295
+ tracking_updates = result.scalars().all()
296
+ if tracking_updates:
297
+ return tracking_updates
298
+ return None
299
+
300
+ tracking_updates = await fetch_order_tracking()
301
+ if tracking_updates:
302
+ response = "📦 *Order Tracking Details:*\n"
303
+ for update in tracking_updates:
304
+ response += (
305
+ f"• *Status:* {update.status}\n"
306
+ f"• *Message:* {update.message or 'No additional details'}\n"
307
+ f"• *Timestamp:* {update.timestamp}\n\n"
308
+ )
309
+ return response
310
+ else:
311
+ return f"⚠️ Sorry, we couldn't find tracking details for order ID: {order_id}."
312
+
313
  # Retrieve or initialize conversation state
314
  state = user_state.get(user_id)
315
  if state and state.is_expired():