msg redesign

This commit is contained in:
Aron Petau 2025-12-25 20:53:10 +01:00
parent d33b6c4226
commit a29412b4da

View file

@ -513,10 +513,43 @@ Total listings tracked: {total_listings}
return "" return ""
self._send_message(f"❓ Unknown command: <code>{cmd}</code>\n\nUse /help to see available commands.") self._send_message(f"❓ Unknown command: <code>{cmd}</code>\n\nUse /help to see available commands.")
def _send_message(self, text): def _send_message(self, text, company=None, auto_applied=None, details=None):
"""
Redesigned Telegram message format.
Args:
text (str): The main message text.
company (str): The company name (e.g., Howoge, WGCompany).
auto_applied (bool): Whether auto-apply was successful.
details (dict): Additional details about the listing.
"""
try: try:
# Construct the new message format
title = f"[{company}] "
title += "✅ Auto-applied!" if auto_applied else "❌ Auto-apply failed."
# Add details if provided
if details:
details_text = "\n".join([
f"🚪 {details.get('rooms', 'N/A')} Zimmer",
f"📐 {details.get('size', 'N/A')}",
f"💰 {details.get('price', 'N/A')}",
f"📍 {details.get('address', 'N/A')}"
])
else:
details_text = ""
# Combine title, details, and additional text
message = f"{title}\n\n{details_text}\n\n{text}"
# Send the message via Telegram
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
data = {"chat_id": TELEGRAM_CHAT_ID, "text": text, "parse_mode": "HTML", "disable_web_page_preview": True} data = {
"chat_id": TELEGRAM_CHAT_ID,
"text": message,
"parse_mode": "HTML",
"disable_web_page_preview": True
}
requests.post(url, data=data) requests.post(url, data=data)
except Exception as e: except Exception as e:
logger.error(f"Failed to send Telegram message: {e}") logger.error(f"Failed to send Telegram message: {e}")