发送图片API:https://core.telegram.org/bots/api#sendphoto
发送消息API:https://core.telegram.org/bots/api#sendmessage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| TELEGRAM_TOKEN = "your_telegram_bot_token" TELEGRAM_CHAT_ID = "your_chat_id"
ACCOUNTS = [ { "username": "your_github_username1", "token": "your_github_token1", "repository": "salvatorepollich/website" }, { "username": "your_github_username2", "token": "your_github_token2", "repository": "salvatorepollich/website" }, { "username": "your_github_username3", "token": "your_github_token3", "repository": "salvatorepollich/website" } ]
def send_success_message(username, action, repo=None, next_time=None): emoji_action = "🌟" if action == "star" else "✅" action_message = f"{emoji_action} *{username}* successfully performed *{action}*!" repo_message = f"Repository: `{repo}`" if repo else "" next_message = f"\n🔄 Next *{action}* scheduled at: `{next_time}`" if next_time else "" message = f"{action_message}\n{repo_message}{next_message}" send_telegram_message(message)
def send_error_message(username, action, error): emoji_action = "⚠️" if action == "star" else "❗" message = f"{emoji_action} *{username}* encountered an error during *{action}*:\n`{error}`" send_telegram_message(message)
def send_telegram_message(message): url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage" payload = { "chat_id": TELEGRAM_CHAT_ID, "text": message, "parse_mode": "Markdown" } try: response = requests.post(url, json=payload) if response.status_code == 200: logging.info("Telegram 通知发送成功") else: logging.error(f"Telegram 通知发送失败,状态码: {response.status_code}") except requests.exceptions.RequestException as e: logging.error(f"Telegram 请求失败: {e}")
|