Update app.py
Browse files
app.py
CHANGED
@@ -329,7 +329,7 @@ def process_order_flow(user_id: str, message: str) -> str:
|
|
329 |
state.data["quantity"] = quantity
|
330 |
state.update_last_active()
|
331 |
user_state[user_id] = state
|
332 |
-
return f"You selected {found_dish} with {quantity} serving(s). Please provide your phone number
|
333 |
|
334 |
if state and state.flow == "order":
|
335 |
state.update_last_active()
|
@@ -350,7 +350,7 @@ def process_order_flow(user_id: str, message: str) -> str:
|
|
350 |
return "Please enter a valid quantity (e.g., 1, 2, 3)."
|
351 |
state.data["quantity"] = quantity
|
352 |
state.step = 3 # Move to phone number step
|
353 |
-
return f"You selected {found_dish} with {quantity} serving(s). Please provide your phone number
|
354 |
else:
|
355 |
state.step = 2 # Ask for quantity
|
356 |
return f"You selected {found_dish}. How many servings would you like?"
|
@@ -367,17 +367,37 @@ def process_order_flow(user_id: str, message: str) -> str:
|
|
367 |
return "Please enter a valid quantity (e.g., 1, 2, 3)."
|
368 |
state.data["quantity"] = quantity
|
369 |
state.step = 3
|
370 |
-
return f"Got it. {quantity} serving(s) of {state.data.get('dish')}. Please provide your phone number
|
371 |
|
372 |
-
# --- Step 3: Requesting Phone Number ---
|
373 |
if state.step == 3:
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
return "Thank you. Please provide your delivery address."
|
|
|
|
|
|
|
379 |
else:
|
380 |
-
return "Please
|
381 |
|
382 |
# --- Step 4: Requesting Delivery Address ---
|
383 |
if state.step == 4:
|
@@ -463,9 +483,6 @@ def process_order_flow(user_id: str, message: str) -> str:
|
|
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 |
-
|
468 |
-
|
469 |
# Notify management of the new order via WhatsApp
|
470 |
async def notify_management_order(order_details: dict):
|
471 |
message_body = (
|
|
|
329 |
state.data["quantity"] = quantity
|
330 |
state.update_last_active()
|
331 |
user_state[user_id] = state
|
332 |
+
return f"You selected {found_dish} with {quantity} serving(s). Please provide your phone number and delivery address."
|
333 |
|
334 |
if state and state.flow == "order":
|
335 |
state.update_last_active()
|
|
|
350 |
return "Please enter a valid quantity (e.g., 1, 2, 3)."
|
351 |
state.data["quantity"] = quantity
|
352 |
state.step = 3 # Move to phone number step
|
353 |
+
return f"You selected {found_dish} with {quantity} serving(s). Please provide your phone number and delivery address."
|
354 |
else:
|
355 |
state.step = 2 # Ask for quantity
|
356 |
return f"You selected {found_dish}. How many servings would you like?"
|
|
|
367 |
return "Please enter a valid quantity (e.g., 1, 2, 3)."
|
368 |
state.data["quantity"] = quantity
|
369 |
state.step = 3
|
370 |
+
return f"Got it. {quantity} serving(s) of {state.data.get('dish')}. Please provide your phone number and delivery address."
|
371 |
|
372 |
+
# --- Step 3: Requesting Phone Number and Address ---
|
373 |
if state.step == 3:
|
374 |
+
# Regular expression to extract phone number and address
|
375 |
+
phone_pattern = r'(\+?\d{10,15})'
|
376 |
+
address_pattern = r'address:\s*(.+)'
|
377 |
+
|
378 |
+
phone_match = re.search(phone_pattern, message)
|
379 |
+
address_match = re.search(address_pattern, message, re.IGNORECASE)
|
380 |
+
|
381 |
+
if phone_match and address_match:
|
382 |
+
phone_number = phone_match.group(1)
|
383 |
+
address = address_match.group(1)
|
384 |
+
state.data["phone_number"] = phone_number
|
385 |
+
state.data["address"] = address
|
386 |
+
# Calculate shipping cost based on the address
|
387 |
+
shipping_cost = calculate_shipping_cost(address)
|
388 |
+
state.data["shipping_cost"] = shipping_cost
|
389 |
+
state.step = 5
|
390 |
+
return (f"Thanks. Your phone number is recorded as: {phone_number}.\n"
|
391 |
+
f"Your delivery address is: {address}.\n"
|
392 |
+
f"Your delivery cost is N{shipping_cost}. Would you like to add any extras such as sides or drinks? (yes/no)")
|
393 |
+
elif phone_match:
|
394 |
+
state.data["phone_number"] = phone_match.group(1)
|
395 |
return "Thank you. Please provide your delivery address."
|
396 |
+
elif address_match:
|
397 |
+
state.data["address"] = address_match.group(1)
|
398 |
+
return "Thank you. Please provide your phone number."
|
399 |
else:
|
400 |
+
return "Please provide both your phone number and delivery address. For example: 'Phone: 08123456789, Address: 123 Main St, Lagos'."
|
401 |
|
402 |
# --- Step 4: Requesting Delivery Address ---
|
403 |
if state.step == 4:
|
|
|
483 |
# Record the initial tracking update: Order Placed
|
484 |
asyncio.create_task(log_order_tracking(order_id, "Order Placed", "Order placed and awaiting payment."))
|
485 |
|
|
|
|
|
|
|
486 |
# Notify management of the new order via WhatsApp
|
487 |
async def notify_management_order(order_details: dict):
|
488 |
message_body = (
|