1 | # |
2 | # requires-python = ">=3.11" |
3 | # dependencies = [ |
4 | # "requests", |
5 | # ] |
6 | # |
7 |
|
8 | import requests |
9 |
|
10 |
|
11 | def main( |
12 | bot_token: str, |
13 | chat_id: str, |
14 | message: str, |
15 | parse_mode: str = "MarkdownV2", |
16 | ) -> dict: |
17 | """ |
18 | Send a Telegram message using bot token from Windmill resource. |
19 | """ |
20 |
|
21 | url = f"https://api.telegram.org/bot{bot_token}/sendMessage" |
22 |
|
23 | payload = { |
24 | "chat_id": chat_id, |
25 | "text": message, |
26 | "parse_mode": parse_mode, |
27 | } |
28 |
|
29 | response = requests.post(url, json=payload) |
30 | response.raise_for_status() |
31 |
|
32 | result = response.json() |
33 |
|
34 | if not result.get("ok"): |
35 | raise Exception(f"Telegram API error: {result.get('description')}") |
36 |
|
37 | return result |
38 |
|