This is an automated email from the ASF dual-hosted git repository.
shahar1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 3362f564178 Add telegram_conn_id to TelegramOperator and
TelegramFileOperator template_fields (#73263)
3362f564178 is described below
commit 3362f56417824faa82c893a7d7f89e58ee759c81
Author: Eddy ZHANG <[email protected]>
AuthorDate: Thu Sep 17 22:21:30 2026 +1000
Add telegram_conn_id to TelegramOperator and TelegramFileOperator
template_fields (#73263)
---
.../providers/telegram/operators/telegram.py | 8 +++----
.../tests/unit/telegram/operators/test_telegram.py | 26 ++++++++++++++++++++--
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git
a/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
b/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
index f55f7e1864f..f34907299f3 100644
--- a/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
+++ b/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
@@ -40,14 +40,14 @@ class TelegramOperator(BaseOperator):
For more information on how to use this operator, take a look at the
guide:
:ref:`howto/operator:TelegramOperator`
- :param telegram_conn_id: Telegram connection ID which its password is
Telegram API token
+ :param telegram_conn_id: Telegram connection ID which its password is
Telegram API token. (templated)
:param token: Telegram API Token
:param chat_id: Telegram chat ID for a chat/channel/group
:param text: Message to be sent on telegram
:param telegram_kwargs: Extra args to be passed to telegram client
"""
- template_fields: Sequence[str] = ("text", "chat_id")
+ template_fields: Sequence[str] = ("text", "chat_id", "telegram_conn_id")
ui_color = "#FFBA40"
def __init__(
@@ -96,14 +96,14 @@ class TelegramFileOperator(BaseOperator):
For more information on how to use this operator, take a look at the
guide:
:ref:`howto/operator:TelegramOperator`
- :param telegram_conn_id: Telegram connection ID which its password is
Telegram API token
+ :param telegram_conn_id: Telegram connection ID which its password is
Telegram API token. (templated)
:param token: Telegram API Token
:param chat_id: Telegram chat ID for a chat/channel/group
:param file: The path of the file or media to be sent via Telegram
:param telegram_kwargs: Extra args to be passed to telegram client
"""
- template_fields: Sequence[str] = ("chat_id",)
+ template_fields: Sequence[str] = ("chat_id", "telegram_conn_id")
ui_color = "#FFBA40"
def __init__(
diff --git a/providers/telegram/tests/unit/telegram/operators/test_telegram.py
b/providers/telegram/tests/unit/telegram/operators/test_telegram.py
index a1cdd92322c..783877e8957 100644
--- a/providers/telegram/tests/unit/telegram/operators/test_telegram.py
+++ b/providers/telegram/tests/unit/telegram/operators/test_telegram.py
@@ -146,7 +146,7 @@ class TestTelegramOperator:
text="some non empty text - higher precedence",
telegram_kwargs={"custom_arg": "value", "text": "some text, that
will be ignored"},
)
- assert hook.template_fields == ("text", "chat_id")
+ assert hook.template_fields == ("text", "chat_id", "telegram_conn_id")
@mock.patch("airflow.providers.telegram.operators.telegram.TelegramHook")
def test_should_return_templatized_text_field(self, mock_hook):
@@ -175,10 +175,21 @@ class TestTelegramOperator:
operator.render_template_fields({"chat_id": "1234567"})
assert operator.chat_id == "1234567"
+ def test_telegram_conn_id_is_templated(self):
+ operator = TelegramOperator(
+ telegram_conn_id="{{ conn_id }}",
+ chat_id="-420913222",
+ task_id="telegram",
+ text="text",
+ )
+ assert "telegram_conn_id" in operator.template_fields
+ operator.render_template_fields({"conn_id": "telegram_staging"})
+ assert operator.telegram_conn_id == "telegram_staging"
+
class TestTelegramFileOperator:
def test_should_return_template_fields(self):
- assert TelegramFileOperator.template_fields == ("chat_id",)
+ assert TelegramFileOperator.template_fields == ("chat_id",
"telegram_conn_id")
def test_should_return_templatized_chat_id_field(self):
operator = TelegramFileOperator(
@@ -189,3 +200,14 @@ class TestTelegramFileOperator:
)
operator.render_template_fields({"chat_id": "1234567"})
assert operator.chat_id == "1234567"
+
+ def test_telegram_conn_id_is_templated(self):
+ operator = TelegramFileOperator(
+ telegram_conn_id="{{ conn_id }}",
+ chat_id="-420913222",
+ task_id="telegram",
+ file="/tmp/file.txt",
+ )
+ assert "telegram_conn_id" in operator.template_fields
+ operator.render_template_fields({"conn_id": "telegram_staging"})
+ assert operator.telegram_conn_id == "telegram_staging"