Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1939,23 +1939,41 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
| 1939 |
|
| 1940 |
if products:
|
| 1941 |
logger.info(f"[Process] Product name detected: '{message_body}' -> Found {len(products)} products")
|
| 1942 |
-
# Show ONLY the highest probability match (first product after sorting by score)
|
| 1943 |
-
selected_product = products[0] # Get the highest scored product
|
| 1944 |
-
product_name = selected_product.get('Product Name', 'Unknown')
|
| 1945 |
-
product_score = selected_product.get('_score', 0)
|
| 1946 |
-
logger.info(f"[Process] Highest probability product: {product_name} (score: {product_score})")
|
| 1947 |
|
| 1948 |
-
|
| 1949 |
-
|
| 1950 |
-
|
| 1951 |
-
|
| 1952 |
-
|
| 1953 |
-
|
| 1954 |
-
|
| 1955 |
-
|
| 1956 |
-
|
| 1957 |
-
|
| 1958 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1959 |
|
| 1960 |
else:
|
| 1961 |
# Enhanced "not found" response with veterinary suggestions
|
|
@@ -3104,7 +3122,7 @@ async def display_all_products(from_number: str):
|
|
| 3104 |
chunk_size = 5
|
| 3105 |
for i in range(0, len(products), chunk_size):
|
| 3106 |
chunk = products[i:i + chunk_size]
|
| 3107 |
-
message = f"📋 *Products ({i+1}-{min(i+chunk_size, len(products))} of {len(products)})*\n\n"
|
| 3108 |
for j, product in enumerate(chunk, i+1):
|
| 3109 |
message += f"{format_number_with_emoji(j)} {product.get('Product Name', 'Unknown')}\n"
|
| 3110 |
if product.get('Category'):
|
|
|
|
| 1939 |
|
| 1940 |
if products:
|
| 1941 |
logger.info(f"[Process] Product name detected: '{message_body}' -> Found {len(products)} products")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1942 |
|
| 1943 |
+
# Check if this is a specific product name search or a category/symptom search
|
| 1944 |
+
is_specific_product = False
|
| 1945 |
+
|
| 1946 |
+
# Check for exact product name match (indicating specific product search)
|
| 1947 |
+
normalized_input = normalize(message_body).lower().strip()
|
| 1948 |
+
for product in products:
|
| 1949 |
+
product_name = product.get('Product Name', '')
|
| 1950 |
+
normalized_product_name = normalize(product_name).lower().strip()
|
| 1951 |
+
if normalized_product_name == normalized_input:
|
| 1952 |
+
is_specific_product = True
|
| 1953 |
+
break
|
| 1954 |
+
|
| 1955 |
+
# If it's a specific product name, show only that product
|
| 1956 |
+
if is_specific_product and len(products) == 1:
|
| 1957 |
+
selected_product = products[0]
|
| 1958 |
+
product_name = selected_product.get('Product Name', 'Unknown')
|
| 1959 |
+
logger.info(f"[Process] Specific product found: {product_name}")
|
| 1960 |
+
|
| 1961 |
+
context_manager.update_context(
|
| 1962 |
+
from_number,
|
| 1963 |
+
current_product=selected_product,
|
| 1964 |
+
current_state='product_inquiry',
|
| 1965 |
+
current_menu='product_inquiry',
|
| 1966 |
+
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
| 1967 |
+
)
|
| 1968 |
+
await send_product_image_with_caption(from_number, selected_product, user_context)
|
| 1969 |
+
return
|
| 1970 |
+
|
| 1971 |
+
# If it's a category/symptom search with multiple products, show all products
|
| 1972 |
+
else:
|
| 1973 |
+
logger.info(f"[Process] Category/symptom search with {len(products)} products")
|
| 1974 |
+
# Use intelligent product inquiry to show all matching products
|
| 1975 |
+
await handle_intelligent_product_inquiry(from_number, message_body, user_context, reply_language)
|
| 1976 |
+
return
|
| 1977 |
|
| 1978 |
else:
|
| 1979 |
# Enhanced "not found" response with veterinary suggestions
|
|
|
|
| 3122 |
chunk_size = 5
|
| 3123 |
for i in range(0, len(products), chunk_size):
|
| 3124 |
chunk = products[i:i + chunk_size]
|
| 3125 |
+
message = f"📋 *Products List ({i+1}-{min(i+chunk_size, len(products))} of {len(products)})*\n\n"
|
| 3126 |
for j, product in enumerate(chunk, i+1):
|
| 3127 |
message += f"{format_number_with_emoji(j)} {product.get('Product Name', 'Unknown')}\n"
|
| 3128 |
if product.get('Category'):
|