Spaces:
Running
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.
|