Fred808 commited on
Commit
33b0c5b
·
verified ·
1 Parent(s): 673cee3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -293,6 +293,30 @@ def process_order_flow(user_id: str, message: str) -> str:
293
  user_state[user_id] = state
294
  return "Sure! What dish would you like to order?"
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  if state and state.flow == "order":
297
  state.update_last_active()
298
  # --- Step 1: Expecting Dish Selection (and optionally quantity) ---
 
293
  user_state[user_id] = state
294
  return "Sure! What dish would you like to order?"
295
 
296
+ # --- New Logic: Parse Dish and Quantity in a Single Message ---
297
+ if not state or state.flow != "order":
298
+ # Check if the message contains a dish and quantity
299
+ dish_candidates = [item["name"] for item in menu_items]
300
+ found_dish = None
301
+ for dish in dish_candidates:
302
+ if dish.lower() in message.lower():
303
+ found_dish = dish
304
+ break
305
+ numbers = re.findall(r'\d+', message)
306
+ if found_dish and numbers:
307
+ quantity = int(numbers[0])
308
+ if quantity <= 0:
309
+ return "Please enter a valid quantity (e.g., 1, 2, 3)."
310
+ # Initialize state and skip to step 3 (phone number)
311
+ state = ConversationState()
312
+ state.flow = "order"
313
+ state.step = 3
314
+ state.data["dish"] = found_dish
315
+ state.data["quantity"] = quantity
316
+ state.update_last_active()
317
+ user_state[user_id] = state
318
+ return f"You selected {found_dish} with {quantity} serving(s). Please provide your phone number for order updates."
319
+
320
  if state and state.flow == "order":
321
  state.update_last_active()
322
  # --- Step 1: Expecting Dish Selection (and optionally quantity) ---