airflow.providers.telegram.hooks.telegram

Telegram Hook。

TelegramHook

此 Hook 允许您使用 telegram python-telegram-bot 库向 Telegram 发布消息。

模块内容

class airflow.providers.telegram.hooks.telegram.TelegramHook(telegram_conn_id=default_conn_name, token=None, chat_id=None)[source]

基类: airflow.hooks.base.BaseHook

此 Hook 允许您使用 telegram python-telegram-bot 库向 Telegram 发布消息。

此库可以在这里找到: https://github.com/python-telegram-bot/python-telegram-bot 它既接受 Telegram 机器人 API 令牌,也接受包含 Telegram 机器人 API 令牌的连接。如果两者都提供,token 参数将优先使用,否则将使用来自 telegram_conn_id 连接中的 'password' 字段。chat_id 也可以通过连接中的 'host' 字段提供。以下是 telegram_connection 的详细信息: name: 'telegram-connection-name' conn_type: 'telegram' password: 'TELEGRAM_TOKEN' (可选) host: 'chat_id' (可选) 示例: .. code-block:: python

# 创建 hook telegram_hook = TelegramHook(telegram_conn_id=”telegram_default”) telegram_hook = TelegramHook() # 将使用 telegram_default # 或者 telegram_hook = TelegramHook(telegram_conn_id=’telegram_default’, chat_id=’-1xxx’) # 或者 telegram_hook = TelegramHook(token=’xxx:xxx’, chat_id=’-1xxx’)

# 调用 telegram bot client 的方法 telegram_hook.send_message(None, {“text”: “message”, “chat_id”: “-1xxx”}) # 或者 telegram_hook.send_message(None’, {“text”: “message”})

参数:
  • telegram_conn_id (str | None) – 可选地包含 Telegram API 令牌在 password 字段中的连接

  • token (str | None) – 可选的 Telegram API 令牌

  • chat_id (str | None) – 可选的 Telegram 聊天/频道/群组的 chat_id

conn_name_attr = 'telegram_conn_id'[source]
default_conn_name = 'telegram_default'[source]
conn_type = 'telegram'[source]
hook_name = 'Telegram'[source]
token[source]
chat_id[source]
connection[source]
classmethod get_ui_field_behaviour()[source]

返回自定义字段行为。

get_conn()[source]

返回 telegram bot 客户端。

返回:

telegram bot 客户端

返回类型:

telegram.Bot

send_message(api_params)[source]

发送消息到 Telegram 频道或聊天。

参数:

api_params (dict) – telegram_instance.send_message 的参数。也可以用于覆盖 chat_id

send_file(api_params)[source]

发送文件到 Telegram 频道或聊天。

参数:

api_params (dict) – telegram_instance.send_document 的参数。也可以用于覆盖 chat_id

此条目有帮助吗?