DreamStream-1 commited on
Commit
cd5d194
·
verified ·
1 Parent(s): 7915a03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -65
app.py CHANGED
@@ -129,7 +129,7 @@ MENU_CONFIG = {
129
  'name': 'Main Menu',
130
  'valid_options': ['1', '2', '3', '4'],
131
  'option_descriptions': {
132
- '1': 'Search Products',
133
  '2': 'Browse Categories',
134
  '3': 'Download Catalog',
135
  '4': 'Chat with Veterinary AI Assistant'
@@ -1992,41 +1992,12 @@ async def process_incoming_message(from_number: str, msg: dict):
1992
 
1993
  # Handle valid menu selection
1994
  if message_body == '1':
1995
- # Product Search
1996
- context_manager.update_context(
1997
- from_number,
1998
- current_state='product_inquiry',
1999
- current_menu='product_inquiry',
2000
- current_menu_options=['main'],
2001
- reply_language=reply_language
2002
- )
2003
- if reply_language == 'ur':
2004
- message = (
2005
- "🔍 *پروڈکٹ سرچ*\n\n"
2006
- "براہ کرم پروڈکٹ کا نام، زمرہ، یا علامات لکھیں:\n\n"
2007
- "📝 *مثال:*\n"
2008
- "• Hydropex\n"
2009
- "• سانس کی بیماری\n"
2010
- "• جگر کی صحت\n"
2011
- "• اینٹی بائیوٹکس\n\n"
2012
- "💬 'main' لکھ کر مین مینو پر واپس جائیں۔"
2013
- )
2014
- else:
2015
- message = (
2016
- "🔍 *Product Search*\n\n"
2017
- "Please enter a product name, category, or symptoms:\n\n"
2018
- "📝 *Examples:*\n"
2019
- "• Hydropex\n"
2020
- "• Respiratory disease\n"
2021
- "• Liver health\n"
2022
- "• Antibiotics\n\n"
2023
- "💬 Type 'main' to return to main menu"
2024
- )
2025
- send_whatsjet_message(from_number, message)
2026
  return
2027
 
2028
  elif message_body == '2':
2029
- # Category Browse
2030
  categories = get_all_categories()
2031
  if reply_language == 'ur':
2032
  message = "📂 *زمرے براؤز کریں:*\n\n"
@@ -2045,6 +2016,7 @@ async def process_incoming_message(from_number: str, msg: dict):
2045
  current_state='category_selection',
2046
  current_menu='category_selection',
2047
  current_menu_options=categories,
 
2048
  reply_language=reply_language
2049
  )
2050
  return
@@ -2061,7 +2033,7 @@ async def process_incoming_message(from_number: str, msg: dict):
2061
  current_state='ai_chat_mode',
2062
  current_menu='ai_chat_mode',
2063
  current_menu_options=['main'],
2064
- reply_language='ur'
2065
  )
2066
  if reply_language == 'ur':
2067
  message = (
@@ -2091,7 +2063,34 @@ async def process_incoming_message(from_number: str, msg: dict):
2091
  await handle_category_selection(message_body, from_number)
2092
  return
2093
 
2094
- # 🎯 PRIORITY 5: Product inquiry handling
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2095
  elif current_state == 'product_inquiry':
2096
  # Check for voice commands first
2097
  mapped_command = process_intelligent_voice_command(message_body, current_state, user_context)
@@ -2180,36 +2179,6 @@ async def process_incoming_message(from_number: str, msg: dict):
2180
  await handle_general_query_with_ai(from_number, message_body, user_context, reply_language)
2181
  return
2182
 
2183
- # 🎯 PRIORITY 6: Product selection handling
2184
- elif current_state == 'product_selection':
2185
- # Handle product selection from list
2186
- try:
2187
- selection_index = int(message_body) - 1
2188
- menu_options = user_context.get('current_menu_options', [])
2189
-
2190
- if 0 <= selection_index < len(menu_options):
2191
- selected_product_name = menu_options[selection_index]
2192
- # Find the product in the database
2193
- if products_df is not None and not products_df.empty:
2194
- product_match = products_df[products_df['Product Name'].str.contains(selected_product_name, case=False, na=False)]
2195
- if not product_match.empty:
2196
- product = product_match.iloc[0].to_dict()
2197
- context_manager.update_context(from_number, current_product=product)
2198
- await send_product_with_image(from_number, product, user_context)
2199
- await handle_veterinary_product_followup(selected_product_name, from_number)
2200
- return
2201
-
2202
- # Invalid selection
2203
- if reply_language == 'ur':
2204
- send_whatsjet_message(from_number, "❌ *غلط انتخاب۔ براہ کرم دوبارہ کوشش کریں یا 'main' لکھ کر مین مینو پر واپس جائیں۔*")
2205
- else:
2206
- send_whatsjet_message(from_number, "❌ *Invalid selection. Please try again or type 'main' to return to main menu.*")
2207
-
2208
- except ValueError:
2209
- # Not a number - treat as general query
2210
- await handle_general_query_with_ai(from_number, message_body, user_context, reply_language)
2211
- return
2212
-
2213
  # 🎯 PRIORITY 7: All other queries - use OpenAI for intelligent response
2214
  await handle_general_query_with_ai(from_number, message_body, user_context, reply_language)
2215
  return
 
129
  'name': 'Main Menu',
130
  'valid_options': ['1', '2', '3', '4'],
131
  'option_descriptions': {
132
+ '1': 'Complete Products List',
133
  '2': 'Browse Categories',
134
  '3': 'Download Catalog',
135
  '4': 'Chat with Veterinary AI Assistant'
 
1992
 
1993
  # Handle valid menu selection
1994
  if message_body == '1':
1995
+ # Complete Products List - Display all 23 products
1996
+ await display_all_products(from_number)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1997
  return
1998
 
1999
  elif message_body == '2':
2000
+ # Category Browse - Show all categories
2001
  categories = get_all_categories()
2002
  if reply_language == 'ur':
2003
  message = "📂 *زمرے براؤز کریں:*\n\n"
 
2016
  current_state='category_selection',
2017
  current_menu='category_selection',
2018
  current_menu_options=categories,
2019
+ available_categories=categories,
2020
  reply_language=reply_language
2021
  )
2022
  return
 
2033
  current_state='ai_chat_mode',
2034
  current_menu='ai_chat_mode',
2035
  current_menu_options=['main'],
2036
+ reply_language=reply_language
2037
  )
2038
  if reply_language == 'ur':
2039
  message = (
 
2063
  await handle_category_selection(message_body, from_number)
2064
  return
2065
 
2066
+ # 🎯 PRIORITY 5: Individual product selection by number
2067
+ elif current_state in ['all_products_menu', 'category_products_menu']:
2068
+ # Handle product selection from numbered list
2069
+ try:
2070
+ selection_index = int(message_body) - 1
2071
+ menu_options = user_context.get('current_menu_options', [])
2072
+ available_products = user_context.get('available_products', [])
2073
+
2074
+ if 0 <= selection_index < len(available_products):
2075
+ selected_product = available_products[selection_index]
2076
+ context_manager.update_context(from_number, current_product=selected_product)
2077
+ await send_product_with_image(from_number, selected_product, user_context)
2078
+ await handle_veterinary_product_followup(selected_product.get('Product Name', ''), from_number)
2079
+ return
2080
+ else:
2081
+ # Invalid selection
2082
+ if reply_language == 'ur':
2083
+ send_whatsjet_message(from_number, f"❌ *غلط انتخاب۔ براہ کرم 1 سے {len(available_products)} کے درمیان نمبر منتخب کریں یا 'main' لکھ کر مین مینو پر واپس جائیں۔*")
2084
+ else:
2085
+ send_whatsjet_message(from_number, f"❌ *Invalid selection. Please choose a number between 1 and {len(available_products)}, or type 'main' to return to main menu.*")
2086
+ return
2087
+
2088
+ except ValueError:
2089
+ # Not a number - treat as general query
2090
+ await handle_general_query_with_ai(from_number, message_body, user_context, reply_language)
2091
+ return
2092
+
2093
+ # 🎯 PRIORITY 6: Product inquiry handling (for direct product searches)
2094
  elif current_state == 'product_inquiry':
2095
  # Check for voice commands first
2096
  mapped_command = process_intelligent_voice_command(message_body, current_state, user_context)
 
2179
  await handle_general_query_with_ai(from_number, message_body, user_context, reply_language)
2180
  return
2181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2182
  # 🎯 PRIORITY 7: All other queries - use OpenAI for intelligent response
2183
  await handle_general_query_with_ai(from_number, message_body, user_context, reply_language)
2184
  return