DreamStream-1 commited on
Commit
15b9da8
·
verified ·
1 Parent(s): d671c65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -2318,10 +2318,15 @@ async def process_incoming_message(from_number: str, msg: dict):
2318
  send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
2319
  elif current_state == 'all_products_menu':
2320
  # Handle product selection from all products
2321
- if products_df is not None and not products_df.empty:
2322
- all_products = products_df.to_dict('records')
2323
- if message_body.isdigit() and 1 <= int(message_body) <= len(all_products):
2324
- selected_product = all_products[int(message_body) - 1]
 
 
 
 
 
2325
  context_manager.update_context(
2326
  from_number,
2327
  current_product=selected_product,
@@ -2330,10 +2335,13 @@ async def process_incoming_message(from_number: str, msg: dict):
2330
  current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
2331
  )
2332
  await send_product_image_with_caption(from_number, selected_product, user_context, reply_language)
 
2333
  else:
2334
  send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
 
2335
  else:
2336
  send_whatsjet_message(from_number, "❌ No products available. Type 'main' to return to main menu.")
 
2337
  elif current_state == 'product_inquiry':
2338
  await handle_veterinary_product_followup(message_body, from_number)
2339
  elif current_state == 'intelligent_products_menu':
 
2318
  send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
2319
  elif current_state == 'all_products_menu':
2320
  # Handle product selection from all products
2321
+ available_products = user_context.get('available_products', [])
2322
+ if not available_products:
2323
+ # Fallback to products_df if available_products not set
2324
+ if products_df is not None and not products_df.empty:
2325
+ available_products = products_df.to_dict('records')
2326
+
2327
+ if available_products:
2328
+ if message_body.isdigit() and 1 <= int(message_body) <= len(available_products):
2329
+ selected_product = available_products[int(message_body) - 1]
2330
  context_manager.update_context(
2331
  from_number,
2332
  current_product=selected_product,
 
2335
  current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
2336
  )
2337
  await send_product_image_with_caption(from_number, selected_product, user_context, reply_language)
2338
+ return # Exit after handling product selection
2339
  else:
2340
  send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
2341
+ return # Exit after showing validation message
2342
  else:
2343
  send_whatsjet_message(from_number, "❌ No products available. Type 'main' to return to main menu.")
2344
+ return # Exit after showing error message
2345
  elif current_state == 'product_inquiry':
2346
  await handle_veterinary_product_followup(message_body, from_number)
2347
  elif current_state == 'intelligent_products_menu':