airflow.providers.telegram.hooks.telegram

Hook for Telegram.

Module Contents

Classes

TelegramHook

This hook allows you to post messages to Telegram using the telegram python-telegram-bot library.

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

Bases: airflow.hooks.base.BaseHook

This hook allows you to post messages to Telegram using the telegram python-telegram-bot library.

The library can be found here: https://github.com/python-telegram-bot/python-telegram-bot It accepts both telegram bot API token directly or connection that has telegram bot API token. If both supplied, token parameter will be given precedence, otherwise ‘password’ field in the connection from telegram_conn_id will be used. chat_id can also be provided in the connection using ‘host’ field in connection. Following is the details of a telegram_connection: name: ‘telegram-connection-name’ conn_type: ‘telegram’ password: ‘TELEGRAM_TOKEN’ (optional) host: ‘chat_id’ (optional) Examples: .. code-block:: python

# Create hook telegram_hook = TelegramHook(telegram_conn_id=”telegram_default”) telegram_hook = TelegramHook() # will use telegram_default # or telegram_hook = TelegramHook(telegram_conn_id=’telegram_default’, chat_id=’-1xxx’) # or telegram_hook = TelegramHook(token=’xxx:xxx’, chat_id=’-1xxx’)

# Call method from telegram bot client telegram_hook.send_message(None, {“text”: “message”, “chat_id”: “-1xxx”}) # or telegram_hook.send_message(None’, {“text”: “message”})

Parameters
  • telegram_conn_id (str | None) – connection that optionally has Telegram API token in the password field

  • token (str | None) – optional telegram API token

  • chat_id (str | None) – optional chat_id of the telegram chat/channel/group

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

Return custom field behaviour.

get_conn()[source]

Return the telegram bot client.

Returns

telegram bot client

Return type

telegram.Bot

send_message(api_params)[source]

Send the message to a telegram channel or chat.

Parameters

api_params (dict) – params for telegram_instance.send_message. It can also be used to override chat_id

Was this entry helpful?