Update app.py
Browse files
app.py
CHANGED
|
@@ -397,22 +397,22 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 397 |
user_state[user_id] = state
|
| 398 |
return "Sure! What dish would you like to order?"
|
| 399 |
|
| 400 |
-
#
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
phone_pattern = r'(\+?\d{10,15})'
|
| 417 |
phone_match = re.search(phone_pattern, message)
|
| 418 |
address = None
|
|
@@ -430,7 +430,7 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 430 |
state.step = 5
|
| 431 |
return (f"Thanks! Your phone number is recorded as: {phone_number}.\n"
|
| 432 |
f"Your delivery address is: {address}.\n"
|
| 433 |
-
f"Your delivery cost is N{shipping_cost}. Would you like
|
| 434 |
elif phone_match:
|
| 435 |
state.data["phone_number"] = phone_match.group(1)
|
| 436 |
asyncio.create_task(update_user_profile(user_id, phone_number))
|
|
|
|
| 397 |
user_state[user_id] = state
|
| 398 |
return "Sure! What dish would you like to order?"
|
| 399 |
|
| 400 |
+
# Use fuzzy matching to detect a dish even with typos
|
| 401 |
+
if not state or state.flow != "order":
|
| 402 |
+
found_dish = match_dish(message)
|
| 403 |
+
if found_dish:
|
| 404 |
+
state = ConversationState()
|
| 405 |
+
state.flow = "order"
|
| 406 |
+
state.data["dish"] = found_dish
|
| 407 |
+
state.update_last_active()
|
| 408 |
+
user_state[user_id] = state
|
| 409 |
+
numbers = re.findall(r'\d+', message)
|
| 410 |
+
if numbers:
|
| 411 |
+
quantity = int(numbers[0])
|
| 412 |
+
if quantity <= 0:
|
| 413 |
+
return "Please enter a valid quantity (e.g., 1, 2, 3)."
|
| 414 |
+
state.data["quantity"] = quantity
|
| 415 |
+
state.step = 3
|
| 416 |
phone_pattern = r'(\+?\d{10,15})'
|
| 417 |
phone_match = re.search(phone_pattern, message)
|
| 418 |
address = None
|
|
|
|
| 430 |
state.step = 5
|
| 431 |
return (f"Thanks! Your phone number is recorded as: {phone_number}.\n"
|
| 432 |
f"Your delivery address is: {address}.\n"
|
| 433 |
+
f"Your delivery cost is N{shipping_cost}. Would you like extras (yes/no)?")
|
| 434 |
elif phone_match:
|
| 435 |
state.data["phone_number"] = phone_match.group(1)
|
| 436 |
asyncio.create_task(update_user_profile(user_id, phone_number))
|