telethon.tl.custom package

telethon.tl.custom.draft module

class telethon.tl.custom.draft.Draft(client, peer, draft)

Bases: object

Custom class that encapsulates a draft on the Telegram servers, providing an abstraction to change the message conveniently. The library will return instances of this class when calling get_drafts().

Args:
date (datetime):
The date of the draft.
link_preview (bool):
Whether the link preview is enabled or not.
reply_to_msg_id (int):
The message ID that the draft will reply to.
delete()

Deletes this draft, and returns True on success.

entity

The entity that belongs to this dialog (user, chat or channel).

input_entity

Input version of the entity.

is_empty

Convenience bool to determine if the draft is empty or not.

raw_text

The raw (text without formatting) contained in the draft. It will be empty if there is no text (thus draft not set).

send(clear=True, parse_mode='md')

Sends the contents of this draft to the dialog. This is just a wrapper around send_message(dialog.input_entity, *args, **kwargs).

set_message(text=None, reply_to=0, parse_mode='md', link_preview=None)

Changes the draft message on the Telegram servers. The changes are reflected in this object.

Parameters:
  • text (str) – New text of the draft. Preserved if left as None.
  • reply_to (int) – Message ID to reply to. Preserved if left as 0, erased if set to None.
  • link_preview (bool) – Whether to attach a web page preview. Preserved if left as None.
  • parse_mode (str) – The parse mode to be used for the text.
Return bool:

True on success.

stringify()
text

The markdown text contained in the draft. It will be empty if there is no text (and hence no draft is set).

to_dict()

telethon.tl.custom.dialog module

class telethon.tl.custom.dialog.Dialog(client, dialog, entities, messages)

Bases: object

Custom class that encapsulates a dialog (an open “conversation” with someone, a group or a channel) providing an abstraction to easily access the input version/normal entity/message etc. The library will return instances of this class when calling get_dialogs().

Args:
dialog (Dialog):
The original Dialog instance.
pinned (bool):
Whether this dialog is pinned to the top or not.
message (Message):
The last message sent on this dialog. Note that this member will not be updated when new messages arrive, it’s only set on creation of the instance.
date (datetime):
The date of the last message sent on this dialog.
entity (entity):
The entity that belongs to this dialog (user, chat or channel).
input_entity (InputPeer):
Input version of the entity.
id (int):
The marked ID of the entity, which is guaranteed to be unique.
name (str):
Display name for this dialog. For chats and channels this is their title, and for users it’s “First-Name Last-Name”.
unread_count (int):
How many messages are currently unread in this dialog. Note that this value won’t update when new messages arrive.
unread_mentions_count (int):
How many mentions are currently unread in this dialog. Note that this value won’t update when new messages arrive.
draft (telethon.tl.custom.draft.Draft):
The draft object in this dialog. It will not be None, so you can call draft.set_message(...).
send_message(*args, **kwargs)

Sends a message to this dialog. This is just a wrapper around client.send_message(dialog.input_entity, *args, **kwargs).

stringify()
to_dict()