File size: 816 Bytes
161c07b 7d7f669 9024123 7d7f669 9024123 88b42a4 9024123 7d7f669 9024123 161c07b ef4bf50 161c07b 7d7f669 ef4bf50 |
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 |
import httpx
import asyncio
import os
import sys
async def send_telegram_message(message):
TELEGRAM_BOT_TOKEN = os.environ.get("T_bot")
TELEGRAM_CHAT_ID = os.environ.get("nroChat")
if not TELEGRAM_BOT_TOKEN or not TELEGRAM_CHAT_ID:
raise Exception("Telegram bot token or chat ID not set")
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
params = {
"chat_id": TELEGRAM_CHAT_ID,
"text": message
}
async with httpx.AsyncClient() as client:
response = await client.post(url, params=params)
if response.status_code != 200:
raise Exception(f"Error sending message: {response.text}")
if __name__ == '__main__':
if len(sys.argv) > 1:
message = sys.argv[1]
asyncio.run(send_telegram_message(message))
|