Fred808 commited on
Commit
2273b54
·
verified ·
1 Parent(s): ab89947

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -45
app.py CHANGED
@@ -510,53 +510,53 @@ async def process_order_flow(user_id: str, message: str) -> str:
510
 
511
  # 2) If we are not already in the order flow, detect dish(es) from the message.
512
  if not state or state.flow != "order":
513
- matched = match_dishes(message)
514
- if matched:
515
- if len(matched) == 1:
516
- # Single dish order
517
- found_dish = matched[0]
518
- state = ConversationState()
519
- state.flow = "order"
520
- state.update_last_active()
521
- user_state[user_id] = state
522
- state.data["dish"] = found_dish
523
- # Try to parse quantity, phone, address from the same message.
524
- single_parse = _parse_single_dish_line(message, found_dish)
525
- if single_parse["quantity"]:
526
- state.data["quantity"] = single_parse["quantity"]
527
- state.step = 3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
  else:
 
 
 
 
 
 
529
  state.step = 2
530
- if single_parse["phone"]:
531
- state.data["phone_number"] = single_parse["phone"]
532
- if single_parse["address"]:
533
- state.data["address"] = single_parse["address"]
534
- if state.step == 2 and not state.data.get("quantity"):
535
- return f"You selected {found_dish}. How many servings would you like?"
536
- elif state.step == 3:
537
- if state.data.get("phone_number") and state.data.get("address"):
538
- shipping_cost = calculate_shipping_cost(state.data["address"])
539
- state.data["shipping_cost"] = shipping_cost
540
- state.step = 5
541
- return (f"Thanks! Your phone number is recorded as: {state.data['phone_number']}.\n"
542
- f"Your delivery address is: {state.data['address']}.\n"
543
- f"Your delivery cost is N{shipping_cost}. Would you like extras (yes/no)?")
544
- elif state.data.get("phone_number") and not state.data.get("address"):
545
- return "Thank you. Please provide your delivery address."
546
- else:
547
- return "Please provide your phone number and address."
548
- else:
549
- # Multiple dishes detected – support unlimited dishes.
550
- state = ConversationState()
551
- state.flow = "order"
552
- state.update_last_active()
553
- user_state[user_id] = state
554
- state.data["dishes"] = matched # Store all matched dishes
555
- state.step = 2
556
- dish_options = ", ".join(matched)
557
- return (f"You have selected the following dishes: {dish_options}.\n"
558
- "How many servings of each would you like? "
559
- "For example: '2 for Jollof Rice, 3 for Chicken, 1 for Fish'")
560
  else:
561
  return "I couldn't identify the dish. Please type the dish name from our menu."
562
 
 
510
 
511
  # 2) If we are not already in the order flow, detect dish(es) from the message.
512
  if not state or state.flow != "order":
513
+ matched = match_dishes(message)
514
+ if matched:
515
+ if len(matched) == 1:
516
+ # Single dish order
517
+ found_dish = matched[0]
518
+ state = ConversationState()
519
+ state.flow = "order"
520
+ state.update_last_active()
521
+ user_state[user_id] = state
522
+ state.data["dish"] = found_dish
523
+ # Try to parse quantity, phone, address from the same message.
524
+ single_parse = _parse_single_dish_line(message, found_dish)
525
+ if single_parse["quantity"]:
526
+ state.data["quantity"] = single_parse["quantity"]
527
+ state.step = 3
528
+ else:
529
+ state.step = 2
530
+ if single_parse["phone"]:
531
+ state.data["phone_number"] = single_parse["phone"]
532
+ if single_parse["address"]:
533
+ state.data["address"] = single_parse["address"]
534
+ if state.step == 2 and not state.data.get("quantity"):
535
+ return f"You selected {found_dish}. How many servings would you like?"
536
+ elif state.step == 3:
537
+ if state.data.get("phone_number") and state.data.get("address"):
538
+ shipping_cost = calculate_shipping_cost(state.data["address"])
539
+ state.data["shipping_cost"] = shipping_cost
540
+ state.step = 5
541
+ return (f"Thanks! Your phone number is recorded as: {state.data['phone_number']}.\n"
542
+ f"Your delivery address is: {state.data['address']}.\n"
543
+ f"Your delivery cost is N{shipping_cost}. Would you like extras (yes/no)?")
544
+ elif state.data.get("phone_number") and not state.data.get("address"):
545
+ return "Thank you. Please provide your delivery address."
546
+ else:
547
+ return "Please provide your phone number and address."
548
  else:
549
+ # Multiple dishes detected – support unlimited dishes.
550
+ state = ConversationState()
551
+ state.flow = "order"
552
+ state.update_last_active()
553
+ user_state[user_id] = state
554
+ state.data["dishes"] = matched # Store all matched dishes
555
  state.step = 2
556
+ dish_options = ", ".join(matched)
557
+ return (f"You have selected the following dishes: {dish_options}.\n"
558
+ "How many servings of each would you like? "
559
+ "For example: '2 for Jollof Rice, 3 for Chicken, 1 for Fish'")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
  else:
561
  return "I couldn't identify the dish. Please type the dish name from our menu."
562