Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1763,7 +1763,18 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
| 1763 |
)
|
| 1764 |
return
|
| 1765 |
|
| 1766 |
-
# π― PRIORITY 2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1767 |
if current_state in ['main_menu', 'category_selection_menu', 'category_products_menu', 'all_products_menu', 'product_inquiry']:
|
| 1768 |
# Validate menu selection
|
| 1769 |
is_valid, error_msg = validate_menu_selection(message_body, current_state, user_context)
|
|
@@ -1854,7 +1865,7 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
| 1854 |
await handle_veterinary_product_followup(message_body, from_number)
|
| 1855 |
return # Exit after handling menu selection
|
| 1856 |
|
| 1857 |
-
# π― PRIORITY
|
| 1858 |
# This ensures users can say product names like "hydropex", "respira aid plus", etc. from any menu
|
| 1859 |
logger.info(f"[Process] Checking for product name in message: '{message_body}' from state: {current_state}")
|
| 1860 |
products = get_veterinary_product_matches(message_body)
|
|
@@ -1933,16 +1944,8 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
| 1933 |
else:
|
| 1934 |
send_whatsjet_message(from_number, message)
|
| 1935 |
|
| 1936 |
-
# π― PRIORITY
|
| 1937 |
-
|
| 1938 |
-
await handle_contact_request_response(from_number, message_body)
|
| 1939 |
-
elif current_state == 'availability_request':
|
| 1940 |
-
await handle_availability_request_response(from_number, message_body)
|
| 1941 |
-
elif current_state == 'ai_chat_mode':
|
| 1942 |
-
await handle_ai_chat_mode(from_number, message_body, reply_language)
|
| 1943 |
-
else:
|
| 1944 |
-
# π― PRIORITY 5: Default: treat as general query with intelligent product inquiry
|
| 1945 |
-
await handle_intelligent_product_inquiry(from_number, message_body, user_context, reply_language)
|
| 1946 |
|
| 1947 |
except Exception as e:
|
| 1948 |
logger.error(f"Error in process_incoming_message: {e}")
|
|
|
|
| 1763 |
)
|
| 1764 |
return
|
| 1765 |
|
| 1766 |
+
# π― PRIORITY 2: State-specific handling (contact_request, availability_request, ai_chat_mode)
|
| 1767 |
+
if current_state == 'contact_request':
|
| 1768 |
+
await handle_contact_request_response(from_number, message_body)
|
| 1769 |
+
return
|
| 1770 |
+
elif current_state == 'availability_request':
|
| 1771 |
+
await handle_availability_request_response(from_number, message_body)
|
| 1772 |
+
return
|
| 1773 |
+
elif current_state == 'ai_chat_mode':
|
| 1774 |
+
await handle_ai_chat_mode(from_number, message_body, reply_language)
|
| 1775 |
+
return
|
| 1776 |
+
|
| 1777 |
+
# π― PRIORITY 3: Menu selections - check if this is a valid menu selection for current state
|
| 1778 |
if current_state in ['main_menu', 'category_selection_menu', 'category_products_menu', 'all_products_menu', 'product_inquiry']:
|
| 1779 |
# Validate menu selection
|
| 1780 |
is_valid, error_msg = validate_menu_selection(message_body, current_state, user_context)
|
|
|
|
| 1865 |
await handle_veterinary_product_followup(message_body, from_number)
|
| 1866 |
return # Exit after handling menu selection
|
| 1867 |
|
| 1868 |
+
# π― PRIORITY 4: Product names - works from ANY menu state
|
| 1869 |
# This ensures users can say product names like "hydropex", "respira aid plus", etc. from any menu
|
| 1870 |
logger.info(f"[Process] Checking for product name in message: '{message_body}' from state: {current_state}")
|
| 1871 |
products = get_veterinary_product_matches(message_body)
|
|
|
|
| 1944 |
else:
|
| 1945 |
send_whatsjet_message(from_number, message)
|
| 1946 |
|
| 1947 |
+
# π― PRIORITY 5: Default: treat as general query with intelligent product inquiry
|
| 1948 |
+
await handle_intelligent_product_inquiry(from_number, message_body, user_context, reply_language)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1949 |
|
| 1950 |
except Exception as e:
|
| 1951 |
logger.error(f"Error in process_incoming_message: {e}")
|