From 9a947f56356cf13374001668efcd5e7f3418dd69 Mon Sep 17 00:00:00 2001 From: AutoSWE Bot Date: Wed, 19 Nov 2025 13:27:50 +0000 Subject: [PATCH] AI: feat: add telegram tool --- .../a8m/py-server/nodes/telegram/__init__.py | 26 ++++++++ .../__pycache__/__init__.cpython-312.pyc | Bin 0 -> 778 bytes .../__pycache__/sendTelegram.cpython-312.pyc | Bin 0 -> 2680 bytes .../py-server/nodes/telegram/sendTelegram.py | 61 ++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 home/user/project/a8m/py-server/nodes/telegram/__init__.py create mode 100644 home/user/project/a8m/py-server/nodes/telegram/__pycache__/__init__.cpython-312.pyc create mode 100644 home/user/project/a8m/py-server/nodes/telegram/__pycache__/sendTelegram.cpython-312.pyc create mode 100644 home/user/project/a8m/py-server/nodes/telegram/sendTelegram.py diff --git a/home/user/project/a8m/py-server/nodes/telegram/__init__.py b/home/user/project/a8m/py-server/nodes/telegram/__init__.py new file mode 100644 index 0000000..0078a2a --- /dev/null +++ b/home/user/project/a8m/py-server/nodes/telegram/__init__.py @@ -0,0 +1,26 @@ +"""Telegram node package. + +This module is intentionally lightweight and serves only to expose the +public API of the :mod:`telegram` node implementation. Importing this +package will automatically expose the primary node class and any other +public objects defined in submodules. + +The module is deliberately minimal to keep import time low and avoid +unnecessary dependencies until the node is actually used. +""" + +# Public interface +__all__ = [] + +# Import the primary node class lazily to keep the package import fast. +# If the implementation changes, update this import accordingly. +try: + from .node import TelegramNode # noqa: F401 + __all__.append("TelegramNode") +except Exception: # pragma: no cover + # The node implementation may not be present yet; this allows the package + # to be imported without raising errors during development or in + # environments where the telegram node is optional. + pass + +# End of file \ No newline at end of file diff --git a/home/user/project/a8m/py-server/nodes/telegram/__pycache__/__init__.cpython-312.pyc b/home/user/project/a8m/py-server/nodes/telegram/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f27e349f914064b5e5a811194d7e0bf672606cd0 GIT binary patch literal 778 z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>44WFHo)T6x4MuQ|nuP{EJV;e%WF?{l zc#fB^k5aRlo)d1MP%3Z=N`-ZX3p(TUa>E%cLCy+K-*r5l9soZew@}L*)RFNTH<;>P zm<+21CfukCXs>#bAoi*!%R2o^1E}ep0e%*#IS!@Nux>OM3uagFWqSRnWffUhGN~5z zgl8^c(vc)UO-GVE`ER(Vt5c->hNb+vdBE>XcpQ9V%rtD7$8DCZ>CHzWG?(mf91LJS zFJQwvIDK9C^n-cWJH3A8ETo3N7_id`A5V*2czWvz15S~yImP^!B6i`@c%btHd&#Iy4HN+A&V1UWZE# zBb)?u1}T5ini;YE4l8V_MDw;>RHyQ$s&VTs_iTww4%;Coyo_$-Ovc|Iey2F?@571Y zs97LMey);Gw=u|FQr%xj7N_>W)Huu<;1NrDHF7HBW}X+Dy-#b(?1QE<~T7Iac#Y{xib8){f5(e0tz&>+H+dyMJjt^uAJ4kP=^#I~L@Q z&)IGHxtb^ix8G^s^wowhHeBBL{>kM4ignzH?wsAfwCm8qu0z$Ghv&q(uDRXSNdH4g zjD>1Q42EioRR7h;=Xb;E-XPl7(U{n2t9MdC~0jSJz894zI6bi4W2P`H0&AK6dH^jBw+t7`j@t!!k`An>5AG*1%wWme8`AV!uk!~q| zkZ;8|_Pi+FdO_gdeXYIgr5}}8?;7dHHGYtRAN&b*7(`ctWCyINBHR^}|D&M%?~E;H zGHO1b$=DKH!%peGMh`)O=q9dKUMrYdDNhd4?J(qjjMxBtASgk&i-LDi_%4e5hSuK? zud9YSX5?C6uaFWx-+NWMn!2idaj=H?_}d=0zs}r#&YJJ3o=MLizwyqpvw&^`(0>4^ C?7~6- literal 0 HcmV?d00001 diff --git a/home/user/project/a8m/py-server/nodes/telegram/sendTelegram.py b/home/user/project/a8m/py-server/nodes/telegram/sendTelegram.py new file mode 100644 index 0000000..0035d68 --- /dev/null +++ b/home/user/project/a8m/py-server/nodes/telegram/sendTelegram.py @@ -0,0 +1,61 @@ +import os +import json +import requests +from typing import Any, Dict + +__all__ = ["send_telegram"] + + +def send_telegram(context: Dict[str, Any], chat_id: str, text: str) -> Dict[str, Any]: + """ + Send a message to a Telegram chat using the Bot API. + + Parameters + ---------- + context : dict + Workflow context containing configuration values. Expected to have a + ``telegram_bot_token`` key or the token must be available as the + environment variable ``TELEGRAM_BOT_TOKEN``. + chat_id : str + The unique identifier for the target chat or username of the target + channel (e.g. ``@channelname``). + text : str + The message text to send. + + Returns + ------- + dict + The JSON-decoded response from Telegram. + + Raises + ------ + ValueError + If the bot token is missing. + RuntimeError + If the HTTP request fails or Telegram returns an error. + """ + token = context.get("telegram_bot_token") or os.getenv("TELEGRAM_BOT_TOKEN") + if not token: + raise ValueError("Telegram bot token not provided in context or environment") + + url = f"https://api.telegram.org/bot{token}/sendMessage" + payload = {"chat_id": chat_id, "text": text} + + try: + response = requests.post(url, json=payload, timeout=10) + except requests.RequestException as exc: + raise RuntimeError(f"Failed to connect to Telegram API: {exc}") from exc + + if response.status_code != 200: + try: + error_info = response.json() + except json.JSONDecodeError: + error_info = response.text + raise RuntimeError( + f"Telegram API returned error {response.status_code}: {error_info}" + ) + + try: + return response.json() + except json.JSONDecodeError as exc: + raise RuntimeError(f"Invalid JSON response from Telegram: {exc}") from exc \ No newline at end of file