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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -52
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 and (image_path.startswith('http') or os.path.exists(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
- media_path = image_path
2849
- logger.info(f"[Product] Using existing public URL: {media_path}")
2850
- else:
2851
- # Convert local path to public URL
2852
- media_path = f"https://dreamstream-1-chatbot.hf.space/uploads/{os.path.basename(image_path).replace(' ', '%20')}"
2853
- logger.info(f"[Product] Converted local path to public URL: {media_path}")
2854
-
2855
- success = send_whatsjet_message(
2856
- from_number,
2857
- details,
2858
- media_type=media_type,
2859
- media_path=media_path, # Use public URL
2860
- filename=filename
2861
- )
2862
-
2863
- if success:
2864
- logger.info(f"[Product] Successfully sent image with caption for product: {product_name}")
2865
- else:
2866
- logger.warning(f"[Product] Failed to send image, sending text only: {product_name}")
2867
- send_whatsjet_message(from_number, details)
2868
- else:
2869
- # No image available, send text only
2870
- logger.info(f"[Product] No image available, sending text only for: {product_name}")
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 and (image_path.startswith('http') or os.path.exists(image_path)):
3559
  media_type = get_product_image_media_type(image_path)
3560
  filename = f"{product_name.replace(' ', '_')}.jpg"
3561
- # If it's already a public URL, use it directly
3562
  if image_path.startswith('http'):
3563
- media_path = image_path
3564
- logger.info(f"[Product] Using existing public URL: {media_path}")
3565
- else:
3566
- # Convert local path to public URL
3567
- media_path = f"https://dreamstream-1-chatbot.hf.space/uploads/{os.path.basename(image_path).replace(' ', '%20')}"
3568
- logger.info(f"[Product] Converted local path to public URL: {media_path}")
3569
- success = send_whatsjet_message(
3570
- from_number,
3571
- details,
3572
- media_type=media_type,
3573
- media_path=media_path, # Use public URL
3574
- filename=filename
3575
- )
3576
- if success:
3577
- logger.info(f"[Product] Successfully sent image with caption for product: {product_name}")
3578
- else:
3579
- logger.warning(f"[Product] Failed to send image, sending text only: {product_name}")
3580
- send_whatsjet_message(from_number, details)
3581
- else:
3582
- # No image available, send text only
3583
- logger.info(f"[Product] No image available, sending text only for: {product_name}")
3584
- send_whatsjet_message(from_number, details)
 
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}")