DreamStream-1 commited on
Commit
5b566bd
·
verified ·
1 Parent(s): f5ebfbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -2769,12 +2769,8 @@ async def send_product_image_with_caption(from_number: str, product: Dict[str, A
2769
  if file_id:
2770
  image_url = f"https://drive.google.com/uc?export=download&id={file_id}"
2771
  logger.info(f"[Product] Converted to direct download URL: {image_url}")
2772
-
2773
- # Use the public URL directly for WhatsApp API
2774
  media_type = 'image/jpeg'
2775
  filename = f"{product_name.replace(' ', '_')}.jpg"
2776
-
2777
- # Test the image URL first
2778
  try:
2779
  logger.info(f"[Product] Testing image URL accessibility: {image_url}")
2780
  headers = {
@@ -2793,7 +2789,18 @@ async def send_product_image_with_caption(from_number: str, product: Dict[str, A
2793
  except Exception as e:
2794
  logger.warning(f"[Product] Failed to test image URL {image_url}: {e}")
2795
  image_url = None
2796
-
 
 
 
 
 
 
 
 
 
 
 
2797
  # Send using public URL (not local file)
2798
  if image_url:
2799
  logger.info(f"[Product] Attempting to send image from CSV URL for: {product_name}")
 
2769
  if file_id:
2770
  image_url = f"https://drive.google.com/uc?export=download&id={file_id}"
2771
  logger.info(f"[Product] Converted to direct download URL: {image_url}")
 
 
2772
  media_type = 'image/jpeg'
2773
  filename = f"{product_name.replace(' ', '_')}.jpg"
 
 
2774
  try:
2775
  logger.info(f"[Product] Testing image URL accessibility: {image_url}")
2776
  headers = {
 
2789
  except Exception as e:
2790
  logger.warning(f"[Product] Failed to test image URL {image_url}: {e}")
2791
  image_url = None
2792
+ # If image_url is public, send image+caption in a single message
2793
+ if image_url and image_url.startswith('http'):
2794
+ logger.info(f"[Product] Sending public image URL with caption using send_whatsjet_message: {image_url}")
2795
+ send_whatsjet_message(
2796
+ from_number,
2797
+ details,
2798
+ media_type=media_type,
2799
+ media_path=image_url,
2800
+ filename=filename
2801
+ )
2802
+ return
2803
+ # Otherwise, fallback to local file logic
2804
  # Send using public URL (not local file)
2805
  if image_url:
2806
  logger.info(f"[Product] Attempting to send image from CSV URL for: {product_name}")