Spaces:
Running

axeronis commited on
Commit
bb11f5e
ยท
1 Parent(s): c1efa37

feat: enable image sending - add product image URLs to AI context

Browse files
backend/app/services/ai_memory_manager.py CHANGED
@@ -302,8 +302,11 @@ class AIMemoryManager:
302
  context += "\nโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
303
  context += "[๐Ÿ“ฆ ะšะะขะะ›ะžะ“ ะขะžะ’ะะ ะžะ’]\n"
304
  context += "โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
 
305
  for p in products:
306
  context += f"โ€ข {p.name} | ะฆะตะฝะฐ: {p.price} {p.currency}\n"
 
 
307
  if p.description:
308
  context += f" ะžะฟะธัะฐะฝะธะต: {p.description}\n"
309
 
 
302
  context += "\nโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
303
  context += "[๐Ÿ“ฆ ะšะะขะะ›ะžะ“ ะขะžะ’ะะ ะžะ’]\n"
304
  context += "โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
305
+ context += "๐Ÿ’ก ะšะพะณะดะฐ ั€ะฐััะบะฐะทั‹ะฒะฐะตัˆัŒ ะพ ั‚ะพะฒะฐั€ะต ั ะบะฐั€ั‚ะธะฝะบะพะน โ€” ะ’ะšะ›ะฎะงะ˜ URL ะฒ ะพั‚ะฒะตั‚, ัะธัั‚ะตะผะฐ ะพั‚ะฟั€ะฐะฒะธั‚ ั„ะพั‚ะพ ะฐะฒั‚ะพะผะฐั‚ะธั‡ะตัะบะธ!\n\n"
306
  for p in products:
307
  context += f"โ€ข {p.name} | ะฆะตะฝะฐ: {p.price} {p.currency}\n"
308
+ if p.image_url:
309
+ context += f" ๐Ÿ“ท ะคะพั‚ะพ: {p.image_url}\n"
310
  if p.description:
311
  context += f" ะžะฟะธัะฐะฝะธะต: {p.description}\n"
312
 
backend/app/services/telegram_service.py CHANGED
@@ -45,6 +45,38 @@ class TelegramService:
45
  logger.error(f"Telegram API error: {e}")
46
  return False
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  async def set_webhook(self, token: str, webhook_url: str) -> bool:
49
  """
50
  Set webhook URL for the bot.
 
45
  logger.error(f"Telegram API error: {e}")
46
  return False
47
 
48
+ async def send_photo(self, token: str, chat_id: str, photo_url: str, caption: str = None) -> bool:
49
+ """
50
+ Send photo to Telegram chat via URL.
51
+ """
52
+ if not token:
53
+ logger.error("Telegram token not provided")
54
+ return False
55
+
56
+ url = self._get_url(token, "sendPhoto")
57
+ payload = {
58
+ "chat_id": chat_id,
59
+ "photo": photo_url,
60
+ "parse_mode": "HTML"
61
+ }
62
+
63
+ if caption:
64
+ payload["caption"] = caption[:1024] # Telegram caption limit
65
+
66
+ try:
67
+ async with httpx.AsyncClient() as client:
68
+ response = await client.post(url, json=payload)
69
+
70
+ if response.status_code == 200:
71
+ logger.info(f"๐Ÿ“ท Photo sent to chat {chat_id}")
72
+ return True
73
+ else:
74
+ logger.error(f"Telegram sendPhoto failed: {response.text}")
75
+ return False
76
+ except Exception as e:
77
+ logger.error(f"Telegram sendPhoto error: {e}")
78
+ return False
79
+
80
  async def set_webhook(self, token: str, webhook_url: str) -> bool:
81
  """
82
  Set webhook URL for the bot.