flexget.components.notify.notifiers.telegram module#

class flexget.components.notify.notifiers.telegram.ChatIdEntry(**kwargs)[source]#

Bases: VersionedBase

_sa_class_manager = {'firstname': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'group': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'surname': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'username': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}#
firstname#
group#
id#
surname#
username#
class flexget.components.notify.notifiers.telegram.TelegramNotifier[source]#

Bases: object

Send a message to one or more Telegram users or groups upon accepting a download.

Preparations:

  • Install ‘python-telegram-bot’ python pkg (i.e. pip install python-telegram-bot)

  • Create a bot & obtain a token for it (see https://core.telegram.org/bots#botfather).

  • For direct messages (not to a group), start a conversation with the bot and click “START” in the Telegram app.

  • For group messages, add the bot to the desired group and send a start message to the bot: “/start” (heed the leading ‘/’).

Configuration example:

my-task:
  notify:
    title: {{title}}
    message: {{title}}
    entries:
      via:
        telegram:
          bot_token: token
          use_markdown: no
          disable_previews: yes
          images:
            - image1.png
            - image2.jpg
          recipients:
            - chat_id: ask @raw_data_bot (most recommended)
            - username: my-user-name
            - group: my-group-name
            - fullname:
                first: my-first-name
                sur: my-sur-name
          socks_proxy: socks5://user:pass@host:port
Configuration notes

You may use any combination of recipients types (username, group or fullname) - 0 or more of each (but you need at least one total…).

parse_mode

Optional. Whether the template uses markdown or html formatting.

Note:

The markdown parser will fall back to basic parsing if there is a parsing error. This can be cause due to unclosed tags (watch out for wandering underscore when using markdown)

chat_id vs. username vs. fullname

The chat_id approach is the most recommended, because with this approach, you don’t have to send a message to get the chat ID before the program runs. In addition, it is the most stable. Even if you change your name, the program will still work properly. chat_id can be a user’s or a group’s (including private groups). If the chat is a group, the chat id is negative. If it is a single person, then positive.

static _get_cached_chat_id_entries(session, usernames, fullnames, groups)[source]#

Get chat ids from the cache (DB). remove found entries from usernames, fullnames & groups.

Parameters:
Return type:

list[ChatIdEntry]

async _check_token()[source]#
Return type:

None

async _get_bot_updates()[source]#

Get updated chats info from telegram.

Return type:

tuple[dict[str, telegram.Chat], dict[tuple[str, str], telegram.Chat], dict[str, telegram.Chat]]

async _get_chat_id_entries(session, usernames, fullnames, groups)[source]#

Get chat ids for usernames, fullnames & groups.

Entries with a matching chat ids will be removed from the input lists.

Parameters:
Return type:

tuple[list[ChatIdEntry], bool]

async _get_chat_ids_and_update_db(session)[source]#
Parameters:

session (sqlalchemy.orm.Session)

Return type:

set[int]

async _get_new_chat_id_entries(usernames, fullnames, groups)[source]#

Get chat ids by querying the telegram bot.

Parameters:
Return type:

AsyncGenerator[ChatIdEntry, None]

_load_config(config)[source]#
Parameters:

config (dict)

Return type:

None

async _replace_chat_id(old_id, new_id, session)[source]#
Parameters:
Return type:

None

async _send_images(chat_ids, session)[source]#
Parameters:
Return type:

None

async _send_msgs(msg, chat_ids, session)[source]#
Parameters:
Return type:

None

_update_db(session, chat_id_entries)[source]#

Update the DB with found chat_ids.

Parameters:
Return type:

None

async main(message)[source]#

Send a Telegram notification.

Parameters:

message (str)

Return type:

None

notify(title, message, config)[source]#
Parameters:
Return type:

None

_bot = None#
_chat_ids_from_config = None#
_fullnames = None#
_groups = None#
_images = None#
_token = None#
_usernames = None#
schema = {'additionalProperties': False, 'properties': {'bot_token': {'type': 'string'}, 'disable_previews': {'default': False, 'type': 'boolean'}, 'images': {'items': {'type': 'string'}, 'type': 'array'}, 'parse_mode': {'enum': ['html', 'markdown', 'markdown_legacy'], 'type': 'string'}, 'recipients': {'items': {'oneOf': [{'additionalProperties': False, 'properties': {'chat_id': {'type': 'integer'}}, 'required': ['chat_id'], 'type': 'object'}, {'additionalProperties': False, 'properties': {'username': {'type': 'string'}}, 'required': ['username'], 'type': 'object'}, {'additionalProperties': False, 'properties': {'fullname': {'additionalProperties': False, 'properties': {'first': {'type': 'string'}, 'sur': {'type': 'string'}}, 'required': ['first', 'sur'], 'type': 'object'}}, 'required': ['fullname'], 'type': 'object'}, {'additionalProperties': False, 'properties': {'group': {'type': 'string'}}, 'required': ['group'], 'type': 'object'}]}, 'minItems': 1, 'type': 'array'}, 'socks_proxy': {'type': 'string'}}, 'required': ['bot_token', 'recipients'], 'type': 'object'}#
flexget.components.notify.notifiers.telegram.register_plugin()[source]#