mottery/backend/app/services/telegram_bot.py

21 lines
612 B
Python

import requests
import os
def send_message(text, token=None, chat_id=None):
token = token or os.getenv(
"TELEGRAM_BOT_TOKEN", "1034761353:AAG8AydVpLCCURPhWAUfBX7I4MyDOb-9H8M")
chat_id = chat_id or os.getenv("TELEGRAM_CHAT_ID", "43709453")
url = f"https://api.telegram.org/bot{token}/sendMessage"
data = {
"chat_id": chat_id,
"text": text,
"parse_mode": "Markdown"
}
try:
resp = requests.post(url, data=data, timeout=10)
return resp.json()
except Exception as e:
print(f"[ERROR] Telegram推送失败: {e}")
return None