Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2839,37 +2839,34 @@ async def send_product_image_with_caption(from_number: str, product: Dict[str, A
|
|
| 2839 |
# Fallback 2: Try local uploads directory (public URL)
|
| 2840 |
logger.info(f"[Product] Trying local uploads directory for: {product_name}")
|
| 2841 |
image_path = get_product_image_path(product_name)
|
| 2842 |
-
if image_path
|
| 2843 |
media_type = get_product_image_media_type(image_path)
|
| 2844 |
filename = f"{product_name.replace(' ', '_')}.jpg"
|
| 2845 |
-
|
| 2846 |
-
# If it's already a public URL, use it directly
|
| 2847 |
if image_path.startswith('http'):
|
| 2848 |
-
|
| 2849 |
-
|
| 2850 |
-
|
| 2851 |
-
|
| 2852 |
-
|
| 2853 |
-
|
| 2854 |
-
|
| 2855 |
-
|
| 2856 |
-
|
| 2857 |
-
|
| 2858 |
-
|
| 2859 |
-
|
| 2860 |
-
|
| 2861 |
-
|
| 2862 |
-
|
| 2863 |
-
|
| 2864 |
-
|
| 2865 |
-
|
| 2866 |
-
|
| 2867 |
-
|
| 2868 |
-
|
| 2869 |
-
|
| 2870 |
-
|
| 2871 |
-
send_whatsjet_message(from_number, details)
|
| 2872 |
-
|
| 2873 |
except Exception as e:
|
| 2874 |
logger.error(f"[Product] Error sending product image with caption: {e}")
|
| 2875 |
logger.info(f"[Product] Falling back to text-only message for: {product_name}")
|
|
@@ -3555,33 +3552,34 @@ async def send_product_image_with_caption(from_number: str, product: Dict[str, A
|
|
| 3555 |
# Fallback 2: Try local uploads directory (public URL)
|
| 3556 |
logger.info(f"[Product] Trying local uploads directory for: {product_name}")
|
| 3557 |
image_path = get_product_image_path(product_name)
|
| 3558 |
-
if image_path
|
| 3559 |
media_type = get_product_image_media_type(image_path)
|
| 3560 |
filename = f"{product_name.replace(' ', '_')}.jpg"
|
| 3561 |
-
# If it's
|
| 3562 |
if image_path.startswith('http'):
|
| 3563 |
-
|
| 3564 |
-
|
| 3565 |
-
|
| 3566 |
-
|
| 3567 |
-
|
| 3568 |
-
|
| 3569 |
-
|
| 3570 |
-
|
| 3571 |
-
|
| 3572 |
-
|
| 3573 |
-
|
| 3574 |
-
|
| 3575 |
-
|
| 3576 |
-
|
| 3577 |
-
|
| 3578 |
-
|
| 3579 |
-
|
| 3580 |
-
|
| 3581 |
-
|
| 3582 |
-
|
| 3583 |
-
|
| 3584 |
-
|
|
|
|
| 3585 |
except Exception as e:
|
| 3586 |
logger.error(f"[Product] Error sending product image with caption: {e}")
|
| 3587 |
logger.info(f"[Product] Falling back to text-only message for: {product_name}")
|
|
|
|
| 2839 |
# Fallback 2: Try local uploads directory (public URL)
|
| 2840 |
logger.info(f"[Product] Trying local uploads directory for: {product_name}")
|
| 2841 |
image_path = get_product_image_path(product_name)
|
| 2842 |
+
if image_path:
|
| 2843 |
media_type = get_product_image_media_type(image_path)
|
| 2844 |
filename = f"{product_name.replace(' ', '_')}.jpg"
|
| 2845 |
+
# If it's a public URL, send as image+caption
|
|
|
|
| 2846 |
if image_path.startswith('http'):
|
| 2847 |
+
logger.info(f"[Product] Sending normalized cPanel public URL with caption: {image_path}")
|
| 2848 |
+
send_whatsjet_message(
|
| 2849 |
+
from_number,
|
| 2850 |
+
details,
|
| 2851 |
+
media_type=media_type,
|
| 2852 |
+
media_path=image_path,
|
| 2853 |
+
filename=filename
|
| 2854 |
+
)
|
| 2855 |
+
return
|
| 2856 |
+
# Otherwise, treat as local file
|
| 2857 |
+
elif os.path.exists(image_path):
|
| 2858 |
+
logger.info(f"[Product] Sending local file with caption: {image_path}")
|
| 2859 |
+
send_whatsjet_message(
|
| 2860 |
+
from_number,
|
| 2861 |
+
details,
|
| 2862 |
+
media_type=media_type,
|
| 2863 |
+
media_path=image_path,
|
| 2864 |
+
filename=filename
|
| 2865 |
+
)
|
| 2866 |
+
return
|
| 2867 |
+
# No image available, send text only
|
| 2868 |
+
logger.info(f"[Product] No image available, sending text only for: {product_name}")
|
| 2869 |
+
send_whatsjet_message(from_number, details)
|
|
|
|
|
|
|
| 2870 |
except Exception as e:
|
| 2871 |
logger.error(f"[Product] Error sending product image with caption: {e}")
|
| 2872 |
logger.info(f"[Product] Falling back to text-only message for: {product_name}")
|
|
|
|
| 3552 |
# Fallback 2: Try local uploads directory (public URL)
|
| 3553 |
logger.info(f"[Product] Trying local uploads directory for: {product_name}")
|
| 3554 |
image_path = get_product_image_path(product_name)
|
| 3555 |
+
if image_path:
|
| 3556 |
media_type = get_product_image_media_type(image_path)
|
| 3557 |
filename = f"{product_name.replace(' ', '_')}.jpg"
|
| 3558 |
+
# If it's a public URL, send as image+caption
|
| 3559 |
if image_path.startswith('http'):
|
| 3560 |
+
logger.info(f"[Product] Sending normalized cPanel public URL with caption: {image_path}")
|
| 3561 |
+
send_whatsjet_message(
|
| 3562 |
+
from_number,
|
| 3563 |
+
details,
|
| 3564 |
+
media_type=media_type,
|
| 3565 |
+
media_path=image_path,
|
| 3566 |
+
filename=filename
|
| 3567 |
+
)
|
| 3568 |
+
return
|
| 3569 |
+
# Otherwise, treat as local file
|
| 3570 |
+
elif os.path.exists(image_path):
|
| 3571 |
+
logger.info(f"[Product] Sending local file with caption: {image_path}")
|
| 3572 |
+
send_whatsjet_message(
|
| 3573 |
+
from_number,
|
| 3574 |
+
details,
|
| 3575 |
+
media_type=media_type,
|
| 3576 |
+
media_path=image_path,
|
| 3577 |
+
filename=filename
|
| 3578 |
+
)
|
| 3579 |
+
return
|
| 3580 |
+
# No image available, send text only
|
| 3581 |
+
logger.info(f"[Product] No image available, sending text only for: {product_name}")
|
| 3582 |
+
send_whatsjet_message(from_number, details)
|
| 3583 |
except Exception as e:
|
| 3584 |
logger.error(f"[Product] Error sending product image with caption: {e}")
|
| 3585 |
logger.info(f"[Product] Falling back to text-only message for: {product_name}")
|