Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1886,7 +1886,14 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
| 1886 |
return
|
| 1887 |
return # Exit after handling menu selection
|
| 1888 |
|
| 1889 |
-
# π― PRIORITY 4:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1890 |
# This ensures users can say product names like "hydropex", "respira aid plus", etc. from any menu
|
| 1891 |
logger.info(f"[Process] Checking for product name in message: '{message_body}' from state: {current_state}")
|
| 1892 |
products = get_veterinary_product_matches(message_body)
|
|
@@ -1974,14 +1981,14 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
| 1974 |
# Check for general veterinary questions
|
| 1975 |
veterinary_keywords = ['weather', 'temperature', 'disease', 'symptoms', 'treatment', 'prevention', 'vaccination', 'nutrition', 'health']
|
| 1976 |
if any(keyword in query_lower for keyword in veterinary_keywords):
|
| 1977 |
-
#
|
| 1978 |
-
|
| 1979 |
return
|
| 1980 |
|
| 1981 |
# Simple one-liner for wrong queries
|
| 1982 |
send_whatsjet_message(from_number, "β Please correct your question or type 'main' to go to main menu.")
|
| 1983 |
|
| 1984 |
-
# π― PRIORITY
|
| 1985 |
await handle_intelligent_product_inquiry(from_number, message_body, user_context, reply_language)
|
| 1986 |
|
| 1987 |
except Exception as e:
|
|
@@ -2011,21 +2018,25 @@ Current State: {current_state}
|
|
| 2011 |
Current Product: {current_product.get('Product Name', 'None') if current_product else 'None'}
|
| 2012 |
|
| 2013 |
IMPORTANT INSTRUCTIONS:
|
| 2014 |
-
1. If the user asks about "Apex" or "Apex Biotical" - provide a
|
| 2015 |
|
| 2016 |
-
2. If the user asks about specific product details (mode of action, dosage, administration, composition, etc.) - search through the veterinary products database and provide detailed, accurate information about the specific product mentioned.
|
| 2017 |
|
| 2018 |
3. If the user asks about products (e.g., 'poultry products', 'respiratory medicine'), list ALL relevant products from the database with a short description for each.
|
| 2019 |
|
| 2020 |
4. If the user asks a general veterinary question, provide a concise, expert answer.
|
| 2021 |
|
| 2022 |
-
5.
|
| 2023 |
-
|
| 2024 |
-
|
| 2025 |
-
7. Use emojis and bullet points for better readability.
|
| 2026 |
-
8. If you don't have specific information, say so clearly and suggest alternatives.
|
| 2027 |
|
| 2028 |
Available Products Database: {products_df.to_dict('records') if products_df is not None else 'No products loaded'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2029 |
"""
|
| 2030 |
response = openai.ChatCompletion.create(
|
| 2031 |
model="gpt-4o",
|
|
@@ -3757,8 +3768,8 @@ async def handle_intelligent_product_inquiry(from_number: str, query: str, user_
|
|
| 3757 |
# Check for general veterinary questions
|
| 3758 |
veterinary_keywords = ['weather', 'temperature', 'disease', 'symptoms', 'treatment', 'prevention', 'vaccination', 'nutrition', 'health']
|
| 3759 |
if any(keyword in query_lower for keyword in veterinary_keywords):
|
| 3760 |
-
#
|
| 3761 |
-
|
| 3762 |
return
|
| 3763 |
|
| 3764 |
# Simple one-liner for wrong queries
|
|
|
|
| 1886 |
return
|
| 1887 |
return # Exit after handling menu selection
|
| 1888 |
|
| 1889 |
+
# π― PRIORITY 4: Check for company/about queries first (before product search)
|
| 1890 |
+
query_lower = message_body.lower().strip()
|
| 1891 |
+
if any(keyword in query_lower for keyword in ['apex', 'company', 'about', 'who', 'what is']):
|
| 1892 |
+
# Use OpenAI for company information
|
| 1893 |
+
await handle_general_query_with_ai(from_number, message_body, user_context, reply_language)
|
| 1894 |
+
return
|
| 1895 |
+
|
| 1896 |
+
# π― PRIORITY 5: Product names - works from ANY menu state
|
| 1897 |
# This ensures users can say product names like "hydropex", "respira aid plus", etc. from any menu
|
| 1898 |
logger.info(f"[Process] Checking for product name in message: '{message_body}' from state: {current_state}")
|
| 1899 |
products = get_veterinary_product_matches(message_body)
|
|
|
|
| 1981 |
# Check for general veterinary questions
|
| 1982 |
veterinary_keywords = ['weather', 'temperature', 'disease', 'symptoms', 'treatment', 'prevention', 'vaccination', 'nutrition', 'health']
|
| 1983 |
if any(keyword in query_lower for keyword in veterinary_keywords):
|
| 1984 |
+
# Simple redirect for non-veterinary topics
|
| 1985 |
+
send_whatsjet_message(from_number, "β Please ask the correct question related to Apex Biotical Solutions or type 'main' to go to main menu.")
|
| 1986 |
return
|
| 1987 |
|
| 1988 |
# Simple one-liner for wrong queries
|
| 1989 |
send_whatsjet_message(from_number, "β Please correct your question or type 'main' to go to main menu.")
|
| 1990 |
|
| 1991 |
+
# π― PRIORITY 6: Default: treat as general query with intelligent product inquiry
|
| 1992 |
await handle_intelligent_product_inquiry(from_number, message_body, user_context, reply_language)
|
| 1993 |
|
| 1994 |
except Exception as e:
|
|
|
|
| 2018 |
Current Product: {current_product.get('Product Name', 'None') if current_product else 'None'}
|
| 2019 |
|
| 2020 |
IMPORTANT INSTRUCTIONS:
|
| 2021 |
+
1. If the user asks about "Apex" or "Apex Biotical" - provide a brief, professional overview of Apex Biotical Solutions as a veterinary pharmaceutical company, including their expertise, product range, and commitment to animal health. Keep it concise and welcoming.
|
| 2022 |
|
| 2023 |
+
2. If the user asks about specific product details (mode of action, dosage, administration, composition, etc.) - search through the veterinary products database and provide detailed, accurate information about the specific product mentioned. If the product exists in the database, provide comprehensive details. If not found, suggest similar products.
|
| 2024 |
|
| 2025 |
3. If the user asks about products (e.g., 'poultry products', 'respiratory medicine'), list ALL relevant products from the database with a short description for each.
|
| 2026 |
|
| 2027 |
4. If the user asks a general veterinary question, provide a concise, expert answer.
|
| 2028 |
|
| 2029 |
+
5. Always keep responses professional, concise, and user-friendly with proper formatting.
|
| 2030 |
+
6. Use emojis and bullet points for better readability.
|
| 2031 |
+
7. If you don't have specific information, say so clearly and suggest alternatives.
|
|
|
|
|
|
|
| 2032 |
|
| 2033 |
Available Products Database: {products_df.to_dict('records') if products_df is not None else 'No products loaded'}
|
| 2034 |
+
|
| 2035 |
+
RESPONSE FORMAT:
|
| 2036 |
+
- Keep responses concise and to the point
|
| 2037 |
+
- Use emojis sparingly but effectively
|
| 2038 |
+
- Avoid long titles or headers
|
| 2039 |
+
- Focus on providing accurate, helpful information
|
| 2040 |
"""
|
| 2041 |
response = openai.ChatCompletion.create(
|
| 2042 |
model="gpt-4o",
|
|
|
|
| 3768 |
# Check for general veterinary questions
|
| 3769 |
veterinary_keywords = ['weather', 'temperature', 'disease', 'symptoms', 'treatment', 'prevention', 'vaccination', 'nutrition', 'health']
|
| 3770 |
if any(keyword in query_lower for keyword in veterinary_keywords):
|
| 3771 |
+
# Simple redirect for non-veterinary topics
|
| 3772 |
+
send_whatsjet_message(from_number, "β Please ask the correct question related to Apex Biotical Solutions or type 'main' to go to main menu.")
|
| 3773 |
return
|
| 3774 |
|
| 3775 |
# Simple one-liner for wrong queries
|