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:
objectSend 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,grouporfullname) - 0 or more of each (but you need at least one total…).parse_modeOptional. Whether the template uses
markdownorhtmlformatting.- 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_idvs.usernamevs.fullnameThe
chat_idapproach 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_idcan 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.
- 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.
- async _get_chat_ids_and_update_db(session)[source]#
- Parameters:
session (sqlalchemy.orm.Session)
- Return type:
- async _get_new_chat_id_entries(usernames, fullnames, groups)[source]#
Get chat ids by querying the telegram
bot.
- async _replace_chat_id(old_id, new_id, session)[source]#
- Parameters:
old_id (int)
new_id (int)
session (sqlalchemy.orm.Session)
- Return type:
None
- async _send_images(chat_ids, session)[source]#
- Parameters:
session (sqlalchemy.orm.Session)
- Return type:
None
- async _send_msgs(msg, chat_ids, session)[source]#
- Parameters:
msg (str)
session (sqlalchemy.orm.Session)
- Return type:
None
- _update_db(session, chat_id_entries)[source]#
Update the DB with found
chat_ids.- Parameters:
session (sqlalchemy.orm.Session)
chat_id_entries (list[ChatIdEntry])
- Return type:
None
- async main(message)[source]#
Send a Telegram notification.
- Parameters:
message (str)
- 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'}#