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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -279,36 +279,6 @@ def process_order_flow(user_id: str, message: str) -> str:
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)
@@ -493,6 +463,37 @@ def process_order_flow(user_id: str, message: str) -> str:
493
  # Record the initial tracking update: Order Placed
494
  asyncio.create_task(log_order_tracking(order_id, "Order Placed", "Order placed and awaiting payment."))
495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  # Notify management of the new order via WhatsApp
497
  async def notify_management_order(order_details: dict):
498
  message_body = (
 
279
  """
280
  Implements an FSM-based order flow with shipping cost calculation.
281
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
 
283
  # Retrieve or initialize conversation state
284
  state = user_state.get(user_id)
 
463
  # Record the initial tracking update: Order Placed
464
  asyncio.create_task(log_order_tracking(order_id, "Order Placed", "Order placed and awaiting payment."))
465
 
466
+
467
+ # Check if the message contains an order ID (e.g., "ord-123456789")
468
+ order_id_match = re.search(r"ord-\d+", message.lower())
469
+ if order_id_match:
470
+ order_id = order_id_match.group(0)
471
+ # Fetch order tracking details
472
+ async def fetch_order_tracking():
473
+ async with async_session() as session:
474
+ result = await session.execute(
475
+ select(OrderTracking)
476
+ .where(OrderTracking.order_id == order_id)
477
+ .order_by(OrderTracking.timestamp)
478
+ )
479
+ tracking_updates = result.scalars().all()
480
+ if tracking_updates:
481
+ return tracking_updates
482
+ return None
483
+
484
+ tracking_updates = await fetch_order_tracking()
485
+ if tracking_updates:
486
+ response = "📦 *Order Tracking Details:*\n"
487
+ for update in tracking_updates:
488
+ response += (
489
+ f"• *Status:* {update.status}\n"
490
+ f"• *Message:* {update.message or 'No additional details'}\n"
491
+ f"• *Timestamp:* {update.timestamp}\n\n"
492
+ )
493
+ return response
494
+ else:
495
+ return f"⚠️ Sorry, we couldn't find tracking details for order ID: {order_id}."
496
+
497
  # Notify management of the new order via WhatsApp
498
  async def notify_management_order(order_details: dict):
499
  message_body = (