feat: Add markdown parsing to Telegram messages
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -220,7 +220,7 @@ async def send_batch_notification():
|
|||||||
file_list_str = "\n".join(f"{name}" for name in filenames)
|
file_list_str = "\n".join(f"{name}" for name in filenames)
|
||||||
|
|
||||||
msg = f"New files uploaded:\n\n- Files: {num_files}\n- Total size: {human_size(total_size)}\n\n```\n{file_list_str}\n```".strip()
|
msg = f"New files uploaded:\n\n- Files: {num_files}\n- Total size: {human_size(total_size)}\n\n```\n{file_list_str}\n```".strip()
|
||||||
await send_telegram_message(TELEGRAM_OWNER_ID, msg)
|
await send_telegram_message(TELEGRAM_OWNER_ID, msg, markdown=True)
|
||||||
|
|
||||||
def _schedule_batch_notification():
|
def _schedule_batch_notification():
|
||||||
# Helper to run async func from sync context of call_later
|
# Helper to run async func from sync context of call_later
|
||||||
@@ -249,13 +249,16 @@ async def add_file_to_batch(filename: str, size: int):
|
|||||||
TELEGRAM_API_URL = f"https://api.telegram.org/bot{SETTINGS.telegram_bot_api_key}"
|
TELEGRAM_API_URL = f"https://api.telegram.org/bot{SETTINGS.telegram_bot_api_key}"
|
||||||
TELEGRAM_OWNER_ID = SETTINGS.telegram_bot_owner_id
|
TELEGRAM_OWNER_ID = SETTINGS.telegram_bot_owner_id
|
||||||
|
|
||||||
async def send_telegram_message(chat_id: str, text: str):
|
async def send_telegram_message(chat_id: str, text: str, markdown: bool = False):
|
||||||
"""Send a message via Telegram bot."""
|
"""Send a message via Telegram bot."""
|
||||||
if not SETTINGS.telegram_bot_api_key:
|
if not SETTINGS.telegram_bot_api_key:
|
||||||
return
|
return
|
||||||
|
payload = {"chat_id": chat_id, "text": text}
|
||||||
|
if markdown:
|
||||||
|
payload["parse_mode"] = "MarkdownV2"
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
await client.post(f"{TELEGRAM_API_URL}/sendMessage", json={"chat_id": chat_id, "text": text})
|
await client.post(f"{TELEGRAM_API_URL}/sendMessage", json=payload)
|
||||||
logger.info("Sent Telegram message to %s", chat_id)
|
logger.info("Sent Telegram message to %s", chat_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to send Telegram message: %s", e)
|
logger.error("Failed to send Telegram message: %s", e)
|
||||||
|
|||||||
Reference in New Issue
Block a user