xtr_telegram_notifier ¶
Telegram for xtr-notifier: chat messages sent, edited and answered through a bot.
Install it beside xtr-notifier and a telegram://BOT_ID:TOKEN@default?channel=CHAT_ID
DSN is served by :class:TelegramTransportFactory with no wiring. Build a message's
options with :class:TelegramOptions — keyboards from :mod:.reply.markup, media, an
edit of an earlier message, a callback query's answer.
TelegramOptions ¶
Bases: MessageOptionsInterface
The options of a Telegram message, one fluent call at a time.
Each method sets a field of the bot API's request, and :meth:to_options
renders them, in the order they were set, as the
:class:~xtr_notifier.message.MessageOptions a message carries. What a
message is — a photo, a location, an edit of an earlier message — is
picked by the option set; options that each pick one cannot be combined,
and the transport refuses a message that combines them.
A file to upload is read when the option is set, and kept as its name and its bytes in base64, so the message stays plain data that crosses a message bus — and a worker sending it needs no access to the file the path named.
Start from options, the bot API's fields as they are sent.
Parameters:
-
options(Mapping[str, object] | None, default:None) –Fields to start from; copied, so the caller's mapping cannot change these options.
recipient_id
property
¶
The chat the message goes to, or None for the transport's channel.
to_options ¶
Render the options set so far — a copy, so later calls do not change it.
chat_id ¶
Send to the chat chat_id rather than the transport's channel.
parse_mode ¶
Parse the text as mode, one of the PARSE_MODE_* constants.
disable_web_page_preview ¶
Show no preview of the links in the text.
protect_content ¶
Keep the message from being forwarded or saved.
has_spoiler ¶
Blur the photo, video or animation until it is tapped.
upload_photo ¶
Upload the photo at path, with the text as its caption.
reply_markup ¶
Show markup with the message: a keyboard, its removal, a forced reply.
edit ¶
Edit the message message_id instead of sending one: its text, or its media.
edit_caption ¶
Edit the caption of the media message message_id, keeping its media.
The subject of the message is the new caption.
answer_callback_query ¶
answer_callback_query(callback_query_id: str, show_alert: bool = False, cache_time: int = 0) -> Self
Answer the callback query callback_query_id a button sent, with the text.
Parameters:
venue ¶
Send a named place on the map.
upload_document ¶
Upload the file at path, with the text as its caption.
upload_video ¶
Upload the video at path, with the text as its caption.
audio ¶
Send an audio file, by URL or file id, with the text as its caption.
upload_audio ¶
Upload the audio file at path, with the text as its caption.
animation ¶
Send an animation, by URL or file id, with the text as its caption.
upload_animation ¶
Upload the animation at path, with the text as its caption.
sticker ¶
Send a sticker, by URL or file id, tied to emoji; the text is not sent.
upload_sticker ¶
Upload the sticker at path, tied to emoji; the text is not sent.
contact ¶
contact(phone_number: str, first_name: str, last_name: str | None = None, v_card: str | None = None) -> Self
Send a phone contact, with a vCard when given; the text is not sent.
TelegramTransport ¶
TelegramTransport(token: str, channel: str | None, http_client: HttpClientInterface, event_dispatcher: EventDispatcherInterface | None = None)
Bases: AbstractTransport
Posts, edits and answers through the Telegram bot API.
The chat a message goes to is the one its options name, else the channel the transport was built with. The text is sent as MarkdownV2 unless the options pick another parse mode, escaped so that a plain sentence is accepted and markup written on purpose is kept.
A file to upload arrives as its name and base64 bytes, and is sent from
memory, the fields going as a form body the HTTP client sends as
multipart/form-data; without one they go as JSON. The files are closed
once the request is made, whatever came of it.
To find a chat's id, message the bot from that chat and read
https://api.telegram.org/bot<token>/getUpdates.
Send as the bot token to channel unless a message names its chat.
Parameters:
-
token(str) –The bot's token,
<bot id>:<secret>; never shown. -
channel(str | None) –The chat sent to when a message names none, or
None. -
http_client(HttpClientInterface) –What the bot API is reached through.
-
event_dispatcher(EventDispatcherInterface | None, default:None) –Where the message events go;
Noneannounces nothing.
supports ¶
Send chat messages carrying no options or Telegram's.
TelegramTransportFactory ¶
TelegramTransportFactory(http_client: HttpClientInterface, event_dispatcher: EventDispatcherInterface | None = None)
Bases: AbstractTransportFactory
Builds a :class:TelegramTransport from telegram://BOT_ID:TOKEN@default?channel=CHAT_ID.
The bot token is the DSN's user and password joined by : — the token
as the bot API hands it out. default stands for api.telegram.org;
channel is the chat sent to when a message names none; ssl=false
(or the older sslmode=disable) reaches the host over plain HTTP.
create ¶
Build the transport dsn describes.
Raises:
-
UnsupportedSchemeError–If the scheme is not
telegram. -
IncompleteDsnError–If the DSN carries no token, or half of one.
-
InvalidArgumentError–If
sslis not a boolean.