Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -874,7 +874,7 @@ class VeterinaryContextManager:
|
|
874 |
context_manager = VeterinaryContextManager()
|
875 |
|
876 |
# Enhanced product response with veterinary domain expertise
|
877 |
-
def generate_veterinary_product_response(product_info: Dict[str, Any], user_context: Dict[str, Any]) -> str:
|
878 |
"""Generate comprehensive veterinary product response with intelligent information handling"""
|
879 |
|
880 |
def clean_text(text):
|
@@ -904,18 +904,38 @@ def generate_veterinary_product_response(product_info: Dict[str, Any], user_cont
|
|
904 |
except Exception as e:
|
905 |
logger.warning(f"Error checking PDF link for {product_name}: {e}")
|
906 |
|
907 |
-
# Build the response
|
908 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
909 |
📦 *Type:* {product_type}
|
910 |
🏥 *Category:* {category}
|
911 |
💊 *Used For:* {indications}"""
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
|
920 |
💬 *Available Actions:*
|
921 |
1️⃣ Talk to Veterinary Consultant
|
@@ -1788,6 +1808,39 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
1788 |
if not message_body:
|
1789 |
return
|
1790 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1791 |
# Check for greetings with multilingual support
|
1792 |
if is_greeting(message_body):
|
1793 |
# Check if user is currently in AI chat mode - if so, don't trigger menu mode
|
@@ -1798,13 +1851,28 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
1798 |
return
|
1799 |
else:
|
1800 |
# Only trigger menu mode if not in AI chat mode
|
1801 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1802 |
send_whatsjet_message(from_number, welcome_msg)
|
1803 |
context_manager.update_context(
|
1804 |
from_number,
|
1805 |
current_state='main_menu',
|
1806 |
current_menu='main_menu',
|
1807 |
-
current_menu_options=list(MENU_CONFIG['main_menu']['option_descriptions'].values())
|
|
|
1808 |
)
|
1809 |
return
|
1810 |
|
@@ -1814,25 +1882,55 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
1814 |
mapped_navigation = process_intelligent_voice_command(message_body, current_state, user_context)
|
1815 |
if mapped_navigation == 'main':
|
1816 |
logger.info(f"[Process] Navigation command detected: '{message_body}' -> 'main'")
|
1817 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1818 |
send_whatsjet_message(from_number, welcome_msg)
|
1819 |
context_manager.update_context(
|
1820 |
from_number,
|
1821 |
current_state='main_menu',
|
1822 |
current_menu='main_menu',
|
1823 |
-
current_menu_options=list(MENU_CONFIG['main_menu']['option_descriptions'].values())
|
|
|
1824 |
)
|
1825 |
return
|
1826 |
|
1827 |
# Also check for text-based navigation commands
|
1828 |
if message_body.lower() in ['main', 'menu', 'start', 'home', 'back']:
|
1829 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1830 |
send_whatsjet_message(from_number, welcome_msg)
|
1831 |
context_manager.update_context(
|
1832 |
from_number,
|
1833 |
current_state='main_menu',
|
1834 |
current_menu='main_menu',
|
1835 |
-
current_menu_options=list(MENU_CONFIG['main_menu']['option_descriptions'].values())
|
|
|
1836 |
)
|
1837 |
return
|
1838 |
|
@@ -1933,7 +2031,7 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
1933 |
current_menu='product_inquiry',
|
1934 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
1935 |
)
|
1936 |
-
await send_product_image_with_caption(from_number, selected_product, user_context)
|
1937 |
else:
|
1938 |
send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
|
1939 |
elif current_state == 'all_products_menu':
|
@@ -1949,7 +2047,7 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
1949 |
current_menu='product_inquiry',
|
1950 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
1951 |
)
|
1952 |
-
await send_product_image_with_caption(from_number, selected_product, user_context)
|
1953 |
else:
|
1954 |
send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
|
1955 |
else:
|
@@ -1968,7 +2066,7 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
1968 |
current_menu='product_inquiry',
|
1969 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
1970 |
)
|
1971 |
-
await send_product_image_with_caption(from_number, selected_product, user_context)
|
1972 |
return
|
1973 |
else:
|
1974 |
# Check if the invalid input might be a product query
|
@@ -2008,7 +2106,7 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
2008 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
2009 |
)
|
2010 |
# Only send one reply: image+caption if possible, else text
|
2011 |
-
await send_product_image_with_caption(from_number, exact_match, user_context)
|
2012 |
return
|
2013 |
|
2014 |
# --- END NEW LOGIC ---
|
@@ -2041,7 +2139,7 @@ async def process_incoming_message(from_number: str, msg: dict):
|
|
2041 |
current_menu='product_inquiry',
|
2042 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
2043 |
)
|
2044 |
-
await send_product_image_with_caption(from_number, selected_product, user_context)
|
2045 |
return
|
2046 |
|
2047 |
# If it's a category/symptom search with multiple products, show all products
|
@@ -2080,9 +2178,36 @@ async def handle_general_query_with_ai(from_number: str, query: str, user_contex
|
|
2080 |
|
2081 |
if is_company_query:
|
2082 |
if reply_language == 'ur':
|
2083 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2084 |
else:
|
2085 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2086 |
send_whatsjet_message(from_number, response)
|
2087 |
return
|
2088 |
|
@@ -2193,29 +2318,33 @@ async def handle_clarification_response(from_number: str, response: str, user_co
|
|
2193 |
clean_response = response.strip().lower()
|
2194 |
|
2195 |
if clean_response in ['yes', 'y', 'apex', 'apex biotical', 'apex biotical solution']:
|
2196 |
-
# User confirmed they want Apex Biotical
|
2197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2198 |
|
2199 |
-
|
2200 |
-
|
|
|
|
|
|
|
|
|
2201 |
|
2202 |
-
if products:
|
2203 |
-
# Found the product - show detailed information
|
2204 |
-
product = products[0]
|
2205 |
-
await send_product_with_image(from_number, product, user_context)
|
2206 |
-
|
2207 |
-
# Update context
|
2208 |
-
user_context['current_product'] = product
|
2209 |
-
user_context['current_state'] = 'product_detail'
|
2210 |
-
user_context['awaiting_clarification'] = False
|
2211 |
-
user_context.pop('clarification_product', None)
|
2212 |
-
context_manager.update_context(from_number, **user_context)
|
2213 |
-
else:
|
2214 |
-
# Product not found even after clarification
|
2215 |
-
send_whatsjet_message(from_number, "❌ *Product not found. Please type 'main' to go to main menu.*")
|
2216 |
-
user_context['awaiting_clarification'] = False
|
2217 |
-
user_context.pop('clarification_product', None)
|
2218 |
-
context_manager.update_context(from_number, **user_context)
|
2219 |
else:
|
2220 |
# User didn't confirm - use OpenAI for intelligent response
|
2221 |
if OPENAI_API_KEY:
|
@@ -3018,7 +3147,7 @@ def ensure_images_dir():
|
|
3018 |
logger.info(f"[Image] Ensured images directory exists: {images_dir}")
|
3019 |
|
3020 |
# New feature: Send product image with caption (product details)
|
3021 |
-
async def send_product_image_with_caption(from_number: str, product: Dict[str, Any], user_context: Dict[str, Any]):
|
3022 |
"""
|
3023 |
Send product image (if available) with product details as caption in a single WhatsApp message.
|
3024 |
Only uses cPanel images from https://amgocus.com/uploads/images/
|
@@ -3026,7 +3155,7 @@ async def send_product_image_with_caption(from_number: str, product: Dict[str, A
|
|
3026 |
"""
|
3027 |
ensure_images_dir()
|
3028 |
product_name = product.get('Product Name', 'Unknown Product')
|
3029 |
-
details = generate_veterinary_product_response(product, user_context)
|
3030 |
|
3031 |
logger.info(f"[Product] Processing cPanel image for product: {product_name}")
|
3032 |
|
@@ -3128,7 +3257,7 @@ async def test_product_image_with_caption(phone: str):
|
|
3128 |
product = products_df.iloc[0].to_dict()
|
3129 |
user_context = {}
|
3130 |
|
3131 |
-
await send_product_image_with_caption(phone, product, user_context)
|
3132 |
|
3133 |
return {
|
3134 |
"success": True,
|
@@ -3890,7 +4019,7 @@ async def test_send_product_image(phone: str, product_name: str = "Bromacid"):
|
|
3890 |
user_context = context_manager.get_context(phone)
|
3891 |
|
3892 |
logger.info(f"[Test] Testing send_product_image_with_caption for product: {product_name}")
|
3893 |
-
await send_product_image_with_caption(phone, product, user_context)
|
3894 |
|
3895 |
return {
|
3896 |
"status": "sent",
|
@@ -4017,13 +4146,13 @@ You are a professional veterinary product assistant for Apex Biotical. The user
|
|
4017 |
Available Products:
|
4018 |
{products_text}
|
4019 |
|
4020 |
-
Please provide:
|
4021 |
-
1.
|
4022 |
-
2.
|
4023 |
-
3.
|
4024 |
-
4. Clear instructions on how to proceed
|
4025 |
|
4026 |
-
|
|
|
4027 |
"""
|
4028 |
|
4029 |
response = openai.ChatCompletion.create(
|
@@ -4155,7 +4284,7 @@ Format your response professionally with emojis and clear structure. Keep it con
|
|
4155 |
# Check if it might be about a product but needs clarification
|
4156 |
if 'apex' in clean_query:
|
4157 |
clarification_message = (
|
4158 |
-
"🤔 *
|
4159 |
"Are you asking about:\n"
|
4160 |
"• Apex Biotical Solution\n"
|
4161 |
"• Or something else?\n\n"
|
|
|
874 |
context_manager = VeterinaryContextManager()
|
875 |
|
876 |
# Enhanced product response with veterinary domain expertise
|
877 |
+
def generate_veterinary_product_response(product_info: Dict[str, Any], user_context: Dict[str, Any], reply_language: str = 'en') -> str:
|
878 |
"""Generate comprehensive veterinary product response with intelligent information handling"""
|
879 |
|
880 |
def clean_text(text):
|
|
|
904 |
except Exception as e:
|
905 |
logger.warning(f"Error checking PDF link for {product_name}: {e}")
|
906 |
|
907 |
+
# Build the response based on language
|
908 |
+
if reply_language == 'ur':
|
909 |
+
response = f"""🧪 *نام:* {product_name}
|
910 |
+
📦 *قسم:* {product_type}
|
911 |
+
🏥 *زمرہ:* {category}
|
912 |
+
💊 *استعمال:* {indications}"""
|
913 |
+
|
914 |
+
# Add PDF link if available, in the requested format
|
915 |
+
if pdf_link:
|
916 |
+
response += f"\n\n📄 پروڈکٹ بروشر دستیاب ہے\n🔗 {product_name} پی ڈی ایف:\n{pdf_link}"
|
917 |
+
|
918 |
+
# Add menu options in Urdu
|
919 |
+
response += f"""
|
920 |
+
|
921 |
+
💬 *دستیاب اختیارات:*
|
922 |
+
1️⃣ ویٹرنری کنسلٹنٹ سے بات کریں
|
923 |
+
2️⃣ دستیابی کے بارے میں پوچھیں
|
924 |
+
3️⃣ مین مینو پر واپس جائیں
|
925 |
+
|
926 |
+
💬 ایک اختیار منتخب کریں یا متعلقہ مصنوعات کے بارے میں پوچھیں"""
|
927 |
+
else:
|
928 |
+
response = f"""🧪 *Name:* {product_name}
|
929 |
📦 *Type:* {product_type}
|
930 |
🏥 *Category:* {category}
|
931 |
💊 *Used For:* {indications}"""
|
932 |
+
|
933 |
+
# Add PDF link if available, in the requested format
|
934 |
+
if pdf_link:
|
935 |
+
response += f"\n\n📄 Product Brochure Available\n🔗 {product_name} PDF:\n{pdf_link}"
|
936 |
+
|
937 |
+
# Add menu options
|
938 |
+
response += f"""
|
939 |
|
940 |
💬 *Available Actions:*
|
941 |
1️⃣ Talk to Veterinary Consultant
|
|
|
1808 |
if not message_body:
|
1809 |
return
|
1810 |
|
1811 |
+
# 🎯 LANGUAGE DETECTION FOR TEXT MESSAGES - STRICTLY ENGLISH OR URDU ONLY
|
1812 |
+
reply_language = 'en' # Default to English
|
1813 |
+
try:
|
1814 |
+
detected_lang = detect(message_body)
|
1815 |
+
logger.info(f"[Process] Raw detected language: {detected_lang}")
|
1816 |
+
|
1817 |
+
# STRICTLY ENGLISH OR URDU ONLY - REJECT ALL OTHER LANGUAGES
|
1818 |
+
if detected_lang in ['en', 'ur']:
|
1819 |
+
reply_language = detected_lang
|
1820 |
+
logger.info(f"[Process] Valid language detected: {detected_lang}")
|
1821 |
+
else:
|
1822 |
+
# Reject any other language and force to English
|
1823 |
+
reply_language = 'en'
|
1824 |
+
logger.warning(f"[Process] Invalid language '{detected_lang}' detected - forcing to English")
|
1825 |
+
|
1826 |
+
# Check if text contains Urdu/Arabic characters or Islamic greetings
|
1827 |
+
urdu_arabic_pattern = re.compile(r'[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]')
|
1828 |
+
islamic_greetings = ['assalamu', 'assalam', 'salam', 'salaam', 'adaab', 'namaste', 'khuda', 'allah']
|
1829 |
+
|
1830 |
+
has_urdu_chars = bool(urdu_arabic_pattern.search(message_body))
|
1831 |
+
has_islamic_greeting = any(greeting in message_body.lower() for greeting in islamic_greetings)
|
1832 |
+
|
1833 |
+
if has_urdu_chars or has_islamic_greeting:
|
1834 |
+
detected_lang = 'ur'
|
1835 |
+
reply_language = 'ur'
|
1836 |
+
logger.info(f"[Process] Overriding language detection to Urdu due to Arabic/Urdu characters or Islamic greeting")
|
1837 |
+
|
1838 |
+
logger.info(f"[Process] Final language set to: {reply_language}")
|
1839 |
+
|
1840 |
+
except Exception as e:
|
1841 |
+
logger.warning(f"[Process] Language detection failed: {e}, defaulting to English")
|
1842 |
+
reply_language = 'en'
|
1843 |
+
|
1844 |
# Check for greetings with multilingual support
|
1845 |
if is_greeting(message_body):
|
1846 |
# Check if user is currently in AI chat mode - if so, don't trigger menu mode
|
|
|
1851 |
return
|
1852 |
else:
|
1853 |
# Only trigger menu mode if not in AI chat mode
|
1854 |
+
# Generate welcome message in detected language
|
1855 |
+
if reply_language == 'ur':
|
1856 |
+
welcome_msg = (
|
1857 |
+
"🩺 *اپیکس بائیوٹیکل ویٹرنری اسسٹنٹ*\n\n"
|
1858 |
+
"آپ کا خیر مقدم ہے! میں آپ کی ویٹرنری مصنوعات کے بارے میں مدد کر سکتا ہوں۔\n\n"
|
1859 |
+
"📋 *مین مینو:*\n"
|
1860 |
+
"1️⃣ مصنوعات تلاش کریں\n"
|
1861 |
+
"2️⃣ زمرے براؤز کریں\n"
|
1862 |
+
"3️⃣ کیٹلاگ ڈاؤن لوڈ کریں\n"
|
1863 |
+
"4️⃣ اے آئی چیٹ موڈ\n\n"
|
1864 |
+
"💬 اپنا انتخاب لکھیں یا 'main' لکھ کر مین مینو پر واپس جائیں۔"
|
1865 |
+
)
|
1866 |
+
else:
|
1867 |
+
welcome_msg = generate_veterinary_welcome_message()
|
1868 |
+
|
1869 |
send_whatsjet_message(from_number, welcome_msg)
|
1870 |
context_manager.update_context(
|
1871 |
from_number,
|
1872 |
current_state='main_menu',
|
1873 |
current_menu='main_menu',
|
1874 |
+
current_menu_options=list(MENU_CONFIG['main_menu']['option_descriptions'].values()),
|
1875 |
+
reply_language=reply_language
|
1876 |
)
|
1877 |
return
|
1878 |
|
|
|
1882 |
mapped_navigation = process_intelligent_voice_command(message_body, current_state, user_context)
|
1883 |
if mapped_navigation == 'main':
|
1884 |
logger.info(f"[Process] Navigation command detected: '{message_body}' -> 'main'")
|
1885 |
+
# Generate welcome message in detected language
|
1886 |
+
if reply_language == 'ur':
|
1887 |
+
welcome_msg = (
|
1888 |
+
"🩺 *اپیکس بائیوٹیکل ویٹرنری اسسٹنٹ*\n\n"
|
1889 |
+
"آپ کا خیر مقدم ہے! میں آپ کی ویٹرنری مصنوعات کے بارے میں مدد کر سکتا ہوں۔\n\n"
|
1890 |
+
"📋 *مین مینو:*\n"
|
1891 |
+
"1️⃣ مصنوعات تلاش کریں\n"
|
1892 |
+
"2️⃣ زمرے براؤز کریں\n"
|
1893 |
+
"3️⃣ کیٹلاگ ڈاؤن لوڈ کریں\n"
|
1894 |
+
"4️⃣ اے آئی چیٹ موڈ\n\n"
|
1895 |
+
"💬 اپنا انتخاب لکھیں یا 'main' لکھ کر مین مینو پر واپس جائیں۔"
|
1896 |
+
)
|
1897 |
+
else:
|
1898 |
+
welcome_msg = generate_veterinary_welcome_message()
|
1899 |
+
|
1900 |
send_whatsjet_message(from_number, welcome_msg)
|
1901 |
context_manager.update_context(
|
1902 |
from_number,
|
1903 |
current_state='main_menu',
|
1904 |
current_menu='main_menu',
|
1905 |
+
current_menu_options=list(MENU_CONFIG['main_menu']['option_descriptions'].values()),
|
1906 |
+
reply_language=reply_language
|
1907 |
)
|
1908 |
return
|
1909 |
|
1910 |
# Also check for text-based navigation commands
|
1911 |
if message_body.lower() in ['main', 'menu', 'start', 'home', 'back']:
|
1912 |
+
# Generate welcome message in detected language
|
1913 |
+
if reply_language == 'ur':
|
1914 |
+
welcome_msg = (
|
1915 |
+
"🩺 *اپیکس بائیوٹیکل ویٹرنری اسسٹنٹ*\n\n"
|
1916 |
+
"آپ کا خیر مقدم ہے! میں آپ کی ویٹرنری مصنوعات کے بارے میں مدد کر سکتا ہوں۔\n\n"
|
1917 |
+
"📋 *مین مینو:*\n"
|
1918 |
+
"1️⃣ مصنوعات تلاش کریں\n"
|
1919 |
+
"2️⃣ زمرے براؤز کریں\n"
|
1920 |
+
"3️⃣ کیٹلاگ ڈاؤن لوڈ کریں\n"
|
1921 |
+
"4️⃣ اے آئی چیٹ موڈ\n\n"
|
1922 |
+
"💬 اپنا انتخاب لکھیں یا 'main' لکھ کر مین مینو پر واپس جائیں۔"
|
1923 |
+
)
|
1924 |
+
else:
|
1925 |
+
welcome_msg = generate_veterinary_welcome_message()
|
1926 |
+
|
1927 |
send_whatsjet_message(from_number, welcome_msg)
|
1928 |
context_manager.update_context(
|
1929 |
from_number,
|
1930 |
current_state='main_menu',
|
1931 |
current_menu='main_menu',
|
1932 |
+
current_menu_options=list(MENU_CONFIG['main_menu']['option_descriptions'].values()),
|
1933 |
+
reply_language=reply_language
|
1934 |
)
|
1935 |
return
|
1936 |
|
|
|
2031 |
current_menu='product_inquiry',
|
2032 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
2033 |
)
|
2034 |
+
await send_product_image_with_caption(from_number, selected_product, user_context, reply_language)
|
2035 |
else:
|
2036 |
send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
|
2037 |
elif current_state == 'all_products_menu':
|
|
|
2047 |
current_menu='product_inquiry',
|
2048 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
2049 |
)
|
2050 |
+
await send_product_image_with_caption(from_number, selected_product, user_context, reply_language)
|
2051 |
else:
|
2052 |
send_whatsjet_message(from_number, get_menu_validation_message(current_state, user_context))
|
2053 |
else:
|
|
|
2066 |
current_menu='product_inquiry',
|
2067 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
2068 |
)
|
2069 |
+
await send_product_image_with_caption(from_number, selected_product, user_context, reply_language)
|
2070 |
return
|
2071 |
else:
|
2072 |
# Check if the invalid input might be a product query
|
|
|
2106 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
2107 |
)
|
2108 |
# Only send one reply: image+caption if possible, else text
|
2109 |
+
await send_product_image_with_caption(from_number, exact_match, user_context, reply_language)
|
2110 |
return
|
2111 |
|
2112 |
# --- END NEW LOGIC ---
|
|
|
2139 |
current_menu='product_inquiry',
|
2140 |
current_menu_options=list(MENU_CONFIG['product_inquiry']['option_descriptions'].values())
|
2141 |
)
|
2142 |
+
await send_product_image_with_caption(from_number, selected_product, user_context, reply_language)
|
2143 |
return
|
2144 |
|
2145 |
# If it's a category/symptom search with multiple products, show all products
|
|
|
2178 |
|
2179 |
if is_company_query:
|
2180 |
if reply_language == 'ur':
|
2181 |
+
response = (
|
2182 |
+
"🏥 *Apex Biotical Solutions*\n\n"
|
2183 |
+
"ہم ایک پیشہ ور ویٹرنری فارماسیوٹیکل کمپنی ہیں جو مندرجہ ذیل میں مہارت رکھتے ہیں:\n\n"
|
2184 |
+
"📦 *ہماری مصنوعات:*\n"
|
2185 |
+
"• سانس کی مدد (Respira Aid Plus, Bromacid)\n"
|
2186 |
+
"• جگر کی صحت (Heposel, Liverpex)\n"
|
2187 |
+
"• مدافعتی نظام (EC-Immune)\n"
|
2188 |
+
"• اینٹی بائیوٹکس (Tribiotic, Para C.E)\n"
|
2189 |
+
"• وٹامنز اور سپلیمنٹس (Symodex, Adek Gold)\n\n"
|
2190 |
+
"💬 *مصنوعات دیکھنے کے لیے:*\n"
|
2191 |
+
"• 'main' لکھ کر مین مینو پر جائیں"
|
2192 |
+
)
|
2193 |
else:
|
2194 |
+
response = (
|
2195 |
+
"🏥 *Apex Biotical Solutions*\n\n"
|
2196 |
+
"We are a leading veterinary pharmaceutical company specializing in:\n\n"
|
2197 |
+
"📦 *Our Products:*\n"
|
2198 |
+
"• Respiratory support (Respira Aid Plus, Bromacid)\n"
|
2199 |
+
"• Liver health (Heposel, Liverpex)\n"
|
2200 |
+
"• Immune system (EC-Immune)\n"
|
2201 |
+
"• Antibiotics (Tribiotic, Para C.E)\n"
|
2202 |
+
"• Vitamins & supplements (Symodex, Adek Gold)\n\n"
|
2203 |
+
"🌍 *Our Focus:*\n"
|
2204 |
+
"• Professional veterinary solutions\n"
|
2205 |
+
"• Quality pharmaceutical products\n"
|
2206 |
+
"• Comprehensive animal healthcare\n\n"
|
2207 |
+
"💬 *To explore our products:*\n"
|
2208 |
+
"• Type 'main' to see the main menu\n"
|
2209 |
+
"• Type a product name (e.g., 'hydropex', 'respira aid plus')"
|
2210 |
+
)
|
2211 |
send_whatsjet_message(from_number, response)
|
2212 |
return
|
2213 |
|
|
|
2318 |
clean_response = response.strip().lower()
|
2319 |
|
2320 |
if clean_response in ['yes', 'y', 'apex', 'apex biotical', 'apex biotical solution']:
|
2321 |
+
# User confirmed they want Apex Biotical - provide company information
|
2322 |
+
company_info = (
|
2323 |
+
"🏥 *Apex Biotical Solutions*\n\n"
|
2324 |
+
"We are a leading veterinary pharmaceutical company specializing in:\n\n"
|
2325 |
+
"📦 *Our Products:*\n"
|
2326 |
+
"• Respiratory support (Respira Aid Plus, Bromacid)\n"
|
2327 |
+
"• Liver health (Heposel, Liverpex)\n"
|
2328 |
+
"• Immune system (EC-Immune)\n"
|
2329 |
+
"• Antibiotics (Tribiotic, Para C.E)\n"
|
2330 |
+
"• Vitamins & supplements (Symodex, Adek Gold)\n\n"
|
2331 |
+
"🌍 *Our Focus:*\n"
|
2332 |
+
"• Professional veterinary solutions\n"
|
2333 |
+
"• Quality pharmaceutical products\n"
|
2334 |
+
"• Comprehensive animal healthcare\n\n"
|
2335 |
+
"💬 *To explore our products:*\n"
|
2336 |
+
"• Type a product name (e.g., 'hydropex', 'respira aid plus')\n"
|
2337 |
+
"• Type 'main' to see the main menu\n"
|
2338 |
+
"• Ask about specific symptoms or conditions"
|
2339 |
+
)
|
2340 |
|
2341 |
+
send_whatsjet_message(from_number, company_info)
|
2342 |
+
|
2343 |
+
# Update context
|
2344 |
+
user_context['awaiting_clarification'] = False
|
2345 |
+
user_context.pop('clarification_product', None)
|
2346 |
+
context_manager.update_context(from_number, **user_context)
|
2347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2348 |
else:
|
2349 |
# User didn't confirm - use OpenAI for intelligent response
|
2350 |
if OPENAI_API_KEY:
|
|
|
3147 |
logger.info(f"[Image] Ensured images directory exists: {images_dir}")
|
3148 |
|
3149 |
# New feature: Send product image with caption (product details)
|
3150 |
+
async def send_product_image_with_caption(from_number: str, product: Dict[str, Any], user_context: Dict[str, Any], reply_language: str = 'en'):
|
3151 |
"""
|
3152 |
Send product image (if available) with product details as caption in a single WhatsApp message.
|
3153 |
Only uses cPanel images from https://amgocus.com/uploads/images/
|
|
|
3155 |
"""
|
3156 |
ensure_images_dir()
|
3157 |
product_name = product.get('Product Name', 'Unknown Product')
|
3158 |
+
details = generate_veterinary_product_response(product, user_context, reply_language)
|
3159 |
|
3160 |
logger.info(f"[Product] Processing cPanel image for product: {product_name}")
|
3161 |
|
|
|
3257 |
product = products_df.iloc[0].to_dict()
|
3258 |
user_context = {}
|
3259 |
|
3260 |
+
await send_product_image_with_caption(phone, product, user_context, 'en')
|
3261 |
|
3262 |
return {
|
3263 |
"success": True,
|
|
|
4019 |
user_context = context_manager.get_context(phone)
|
4020 |
|
4021 |
logger.info(f"[Test] Testing send_product_image_with_caption for product: {product_name}")
|
4022 |
+
await send_product_image_with_caption(phone, product, user_context, 'en')
|
4023 |
|
4024 |
return {
|
4025 |
"status": "sent",
|
|
|
4146 |
Available Products:
|
4147 |
{products_text}
|
4148 |
|
4149 |
+
Please provide a CONCISE response:
|
4150 |
+
1. Brief acknowledgment (1 line max)
|
4151 |
+
2. Simple numbered list of products with category only
|
4152 |
+
3. Clear instructions on how to proceed
|
|
|
4153 |
|
4154 |
+
Keep it SHORT and PRECISE. No marketing language, no detailed explanations, no repetition.
|
4155 |
+
Format: Brief intro + numbered list + instructions only.
|
4156 |
"""
|
4157 |
|
4158 |
response = openai.ChatCompletion.create(
|
|
|
4284 |
# Check if it might be about a product but needs clarification
|
4285 |
if 'apex' in clean_query:
|
4286 |
clarification_message = (
|
4287 |
+
"🤔 *Product Inquiry*\n\n"
|
4288 |
"Are you asking about:\n"
|
4289 |
"• Apex Biotical Solution\n"
|
4290 |
"• Or something else?\n\n"
|