# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests",
# ]
# ///
import requests
def main(
bot_token: str,
chat_id: str,
message: str,
parse_mode: str = "MarkdownV2",
) -> dict:
"""
Send a Telegram message using bot token from Windmill resource.
"""
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
payload = {
"chat_id": chat_id,
"text": message,
"parse_mode": parse_mode,
}
response = requests.post(url, json=payload)
response.raise_for_status()
result = response.json()
if not result.get("ok"):
raise Exception(f"Telegram API error: {result.get('description')}")
return result
Submitted by bernard yip231 85 days ago