Custom package¶
The telethon.tl.custom
package contains custom classes that the library
uses in order to make working with Telegram easier. Only those that you
are supposed to use will be documented here. You can use undocumented ones
at your own risk.
More often than not, you don’t need to import these (unless you want type hinting), nor do you need to manually create instances of these classes. They are returned by client methods.
Contents
AdminLogEvent¶
-
class
telethon.tl.custom.adminlogevent.
AdminLogEvent
(original, entities)¶ Bases:
object
Represents a more friendly interface for admin log events.
- Members:
- original (ChannelAdminLogEvent):
- The original ChannelAdminLogEvent.
- entities (
dict
): A dictionary mapping user IDs to User.
When
old
andnew
are ChannelParticipant, you can use this dictionary to map theuser_id
,kicked_by
,inviter_id
andpromoted_by
IDs to their User.- user (User):
- The user that caused this action (
entities[original.user_id]
). - input_user (InputPeerUser):
- Input variant of
user
.
-
__str__
()¶ Return str(self).
-
__weakref__
¶ list of weak references to the object (if defined)
-
action
¶ The original ChannelAdminLogEventAction.
-
changed_about
¶ Whether the channel’s about was changed or not.
-
changed_admin
¶ Whether the permissions for an admin in this channel changed or not.
If
True
,old
andnew
will be present as ChannelParticipant.
-
changed_call_settings
¶ Whether the group call settings were changed or not.
-
changed_default_banned_rights
¶ Whether the default banned rights were changed or not.
If
True
,old
andnew
will be present as ChatBannedRights.
-
changed_hide_history
¶ Whether hiding the previous message history for new members in the channel was toggled or not.
-
changed_history_ttl
¶ Whether the Time To Live of the message history has changed.
Messages sent after this change will have a
ttl_period
in seconds indicating how long they should live for before being auto-deleted.If
True
,old
will be the old TTL, andnew
the new TTL, in seconds.
-
changed_invites
¶ Whether the invites in the channel were toggled or not.
-
changed_location
¶ Whether the location setting of the channel has changed or not.
If
True
,old
andnew
will be present as ChannelLocation.
-
changed_message
¶ Whether a message in this channel was edited or not.
-
changed_photo
¶ Whether the channel’s photo was changed or not.
-
changed_pin
¶ Whether a new message in this channel was pinned or not.
-
changed_restrictions
¶ Whether a message in this channel was edited or not.
If
True
,old
andnew
will be present as ChannelParticipant.
-
changed_signatures
¶ Whether the message signatures in the channel were toggled or not.
-
changed_sticker_set
¶ Whether the channel’s sticker set was changed or not.
If
True
,old
andnew
will be present as InputStickerSet.
-
changed_title
¶ Whether the channel’s title was changed or not.
-
changed_user_volume
¶ Whether a participant’s volume in a call has been changed.
If
True
,new
will be the updated GroupCallParticipant.
-
changed_username
¶ Whether the channel’s username was changed or not.
-
date
¶ The date when this event occurred.
-
deleted_exported_invite
¶ Whether the exported chat invite has been deleted.
If
True
,old
will be the deleted ExportedChatInvite.
-
deleted_message
¶ Whether a message in this channel was deleted or not.
-
discarded_group_call
¶ Whether a group call was started or not.
If
True
,old
will be present as InputGroupCall.
-
edited_exported_invite
¶ Whether the exported chat invite has been edited.
If
True
,old
andnew
will be the old and new ExportedChatInvite, respectively.
-
id
¶ The ID of this event.
-
joined
¶ Whether
user
joined through the channel’s public username or not.
-
joined_by_invite
¶ Whether a new participant has joined with the use of an invite link.
If
True
,old
will be pre-existing (old) ExportedChatInvite used to join.
-
joined_invite
¶ Whether a new user joined through an invite link to the channel or not.
If
True
,new
will be present as ChannelParticipant.
-
left
¶ Whether
user
left the channel or not.
-
new
¶ The new value present in the event.
-
old
¶ The old value from the event.
-
revoked_exported_invite
¶ Whether the exported chat invite has been revoked.
If
True
,old
will be the revoked ExportedChatInvite.
-
started_group_call
¶ Whether a group call was started or not.
If
True
,new
will be present as InputGroupCall.
-
stringify
()¶
-
user_id
¶ The ID of the user that triggered this event.
-
user_muted
¶ Whether a participant was muted in the ongoing group call or not.
If
True
,new
will be present as GroupCallParticipant.
-
user_unmutted
¶ Whether a participant was unmuted from the ongoing group call or not.
If
True
,new
will be present as GroupCallParticipant.
Button¶
Bases:
object
Note
This class is used to define reply markups, e.g. when sending a message or replying to events. When you access
Message.buttons
they are actuallyMessageButton
, so you might want to refer to that class instead.Helper class to allow defining
reply_markup
when sending a message with inline or keyboard buttons.You should make use of the defined class methods to create button instances instead making them yourself (i.e. don’t do
Button(...)
but instead use methods lineButton.inline(...)
etc.You can use
inline
,switch_inline
,url
,auth
,buy
andgame
together to create inline buttons (under the message).You can use
text
,request_location
,request_phone
andrequest_poll
together to create a reply markup (replaces the user keyboard). You can also configure the aspect of the reply with these. The latest message with a reply markup will be the one shown to the user (messages contain the buttons, not the chat itself).You cannot mix the two type of buttons together, and it will error if you try to do so.
The text for all buttons may be at most 142 characters. If more characters are given, Telegram will cut the text to 128 characters and add the ellipsis (…) character as the 129.
list of weak references to the object (if defined)
Creates a new inline button to authorize the user at the given URL.
You should set the
url
to be on the same domain as the one configured for the desiredbot
via @BotFather using the/setdomain
command.For more information about letting the user login via Telegram to a certain domain, see https://core.telegram.org/widgets/login.
If no
url
is specified, it will default totext
.- Args:
- bot (
hints.EntityLike
): The bot that requires this authorization. By default, this is the bot that is currently logged in (itself), although you may pass a different input peer.
Note
For now, you cannot use ID or username for this argument. If you want to use a different bot than the one currently logged in, you must manually use
client.get_input_entity()
.- write_access (
bool
): - Whether write access is required or not.
This is
False
by default (read-only access). - fwd_text (
str
): - The new text to show in the button if the message is forwarded. By default, the button text will be the same.
- bot (
When the user clicks this button, a confirmation box will be shown to the user asking whether they want to login to the specified domain.
Creates a new inline button to buy a product.
This can only be used when sending files of type InputMediaInvoice, and must be the first button.
If the button is not specified, Telegram will automatically add the button to the message. See the Payments API documentation for more information.
- Clears all keyboard buttons after sending a message with this markup. When used, no other button should be present or it will be ignored.
selective
is as documented intext
.
Forces a reply to the message with this markup. If used, no other button should be present or it will be ignored.
single_use
andselective
are as documented intext
.- Args:
- placeholder (str):
text to show the user at typing place of message.
If the placeholder is too long, Telegram applications will crop the text (for example, to 64 characters and adding an ellipsis (…) character as the 65th).
Creates a new inline button to start playing a game.
This should be used when sending files of type InputMediaGame, and must be the first button.
See the Games documentation for more information on using games.
Creates a new inline button with some payload data in it.
If
data
is omitted, the giventext
will be used asdata
. In any casedata
should be eitherbytes
orstr
.Note that the given
data
must be less or equal to 64 bytes. If more than 64 bytes are passed as data,ValueError
is raised. If you need to store more than 64 bytes, consider saving the real data in a database and a reference to that data inside the button.When the user clicks this button,
events.CallbackQuery
will trigger with the same data that the button contained, so that you can determine which button was pressed.
Creates a new keyboard button to request the user’s location on click.
resize
,single_use
andselective
are documented intext
.When the user clicks this button, a confirmation box will be shown to the user asking whether they want to share their location with the bot, and if confirmed a message with geo media will be sent.
Creates a new keyboard button to request the user’s phone on click.
resize
,single_use
andselective
are documented intext
.When the user clicks this button, a confirmation box will be shown to the user asking whether they want to share their phone with the bot, and if confirmed a message with contact media will be sent.
Creates a new keyboard button to request the user to create a poll.
If
force_quiz
isFalse
, the user will be allowed to choose whether they want their poll to be a quiz or not. Otherwise, the user will be forced to create a quiz when creating the poll.If a poll is a quiz, there will be only one answer that is valid, and the votes cannot be retracted. Otherwise, users can vote and retract the vote, and the pol might be multiple choice.
resize
,single_use
andselective
are documented intext
.When the user clicks this button, a screen letting the user create a poll will be shown, and if they do create one, the poll will be sent.
Creates a new inline button to switch to inline query.
If
query
is given, it will be the default text to be used when making the inline query.If
same_peer is True
the inline query will directly be set under the currently opened chat. Otherwise, the user will have to select a different dialog to make the query.When the user clicks this button, after a chat is selected, their input field will be filled with the username of your bot followed by the query text, ready to make inline queries.
Creates a new keyboard button with the given text.
- Args:
- resize (
bool
): - If present, the entire keyboard will be reconfigured to be resized and be smaller if there are not many buttons.
- single_use (
bool
): - If present, the entire keyboard will be reconfigured to be usable only once before it hides itself.
- selective (
bool
): - If present, the entire keyboard will be reconfigured to be “selective”. The keyboard will be shown only to specific users. It will target users that are @mentioned in the text of the message or to the sender of the message you reply to.
- resize (
When the user clicks this button, a text message with the same text as the button will be sent, and can be handled with
events.NewMessage
. You cannot distinguish between a button press and the user typing and sending exactly the same text on their own.
Creates a new inline button to open the desired URL on click.
If no
url
is given, thetext
will be used as said URL instead.You cannot detect that the user clicked this button directly.
When the user clicks this button, a confirmation box will be shown to the user asking whether they want to open the displayed URL unless the domain is trusted, and once confirmed the URL will open in their device.
ChatGetter¶
-
class
telethon.tl.custom.chatgetter.
ChatGetter
(chat_peer=None, *, input_chat=None, chat=None, broadcast=None)¶ Bases:
abc.ABC
Helper base class that introduces the
chat
,input_chat
andchat_id
properties andget_chat
andget_input_chat
methods.-
__weakref__
¶ list of weak references to the object (if defined)
-
chat
¶ Returns the User, Chat or Channel where this object belongs to. It may be
None
if Telegram didn’t send the chat.If you only need the ID, use
chat_id
instead.If you need to call a method which needs this chat, use
input_chat
instead.If you’re using
telethon.events
, useget_chat()
instead.
-
chat_id
¶ Returns the marked chat integer ID. Note that this value will be different from
peer_id
for incoming private messages, since the chat to which the messages go is to your own person, but the chat itself is with the one who sent the message.TL;DR; this gets the ID that you expect.
If there is a chat in the object,
chat_id
will always be set, which is why you should use it instead ofchat.id
.
-
get_chat
()¶ Returns
chat
, but will make an API call to find the chat unless it’s already cached.If you only need the ID, use
chat_id
instead.If you need to call a method which needs this chat, use
get_input_chat()
instead.
-
get_input_chat
()¶ Returns
input_chat
, but will make an API call to find the input chat unless it’s already cached.
-
input_chat
¶ This InputPeer is the input version of the chat where the message was sent. Similarly to
input_sender
, this doesn’t have things like username or similar, but still useful in some cases.Note that this might not be available if the library doesn’t have enough information available.
-
is_group
¶ True if the message was sent on a group or megagroup.
Returns
None
if there isn’t enough information (e.g. onevents.MessageDeleted
).
-
is_private
¶ True
if the message was sent as a private message.Returns
None
if there isn’t enough information (e.g. onevents.MessageDeleted
).
-
Conversation¶
-
class
telethon.tl.custom.conversation.
Conversation
(client, input_chat, *, timeout, total_timeout, max_messages, exclusive, replies_are_responses)¶ Bases:
telethon.tl.custom.chatgetter.ChatGetter
Represents a conversation inside an specific chat.
A conversation keeps track of new messages since it was created until its exit and easily lets you query the current state.
If you need a conversation across two or more chats, you should use two conversations and synchronize them as you better see fit.
-
__aenter__
()¶
-
__aexit__
(exc_type, exc_val, exc_tb)¶
-
__enter__
()¶ Helps to cut boilerplate on async context managers that offer synchronous variants.
-
__exit__
(*args)¶
-
cancel
()¶ Cancels the current conversation. Pending responses and subsequent calls to get a response will raise
asyncio.CancelledError
.This method is synchronous and should not be awaited.
-
cancel_all
()¶ Calls
cancel
on all conversations in this chat.Note that you should
await
this method, since it’s meant to be used outside of a context manager, and it needs to resolve the chat.
-
get_edit
(message=None, *, timeout=None)¶ Awaits for an edit after the last message to arrive. The arguments are the same as those for
get_response
.
-
get_reply
(message=None, *, timeout=None)¶ Gets the next message that explicitly replies to a previous one.
-
get_response
(message=None, *, timeout=None)¶ Gets the next message that responds to a previous one. This is the method you need most of the time, along with
get_edit
.- Args:
async with client.conversation(...) as conv: await conv.send_message('Hey, what is your name?') response = await conv.get_response() name = response.text await conv.send_message('Nice to meet you, {}!'.format(name))
-
mark_read
(message=None)¶ Marks as read the latest received message if
message is None
. Otherwise, marks as read until the given message (or message ID).This is equivalent to calling
client.send_read_acknowledge
.
-
send_file
(*args, **kwargs)¶ Sends a file in the context of this conversation. Shorthand for
telethon.client.uploads.UploadMethods.send_file
withentity
already set.
-
send_message
(*args, **kwargs)¶ Sends a message in the context of this conversation. Shorthand for
telethon.client.messages.MessageMethods.send_message
withentity
already set.
-
wait_event
(event, *, timeout=None)¶ Waits for a custom event to occur. Timeouts still apply.
Note
Only use this if there isn’t another method available! For example, don’t use
wait_event
for new messages, sinceget_response
already exists, etc.Unless you’re certain that your code will run fast enough, generally you should get a “handle” of this special coroutine before acting. In this example you will see how to wait for a user to join a group with proper use of
wait_event
:from telethon import TelegramClient, events client = TelegramClient(...) group_id = ... async def main(): # Could also get the user id from an event; this is just an example user_id = ... async with client.conversation(user_id) as conv: # Get a handle to the future event we'll wait for handle = conv.wait_event(events.ChatAction( group_id, func=lambda e: e.user_joined and e.user_id == user_id )) # Perform whatever action in between await conv.send_message('Please join this group before speaking to me!') # Wait for the event we registered above to fire event = await handle # Continue with the conversation await conv.send_message('Thanks!')
This way your event can be registered before acting, since the response may arrive before your event was registered. It depends on your use case since this also means the event can arrive before you send a previous action.
-
wait_read
(message=None, *, timeout=None)¶ Awaits for the sent message to be marked as read. Note that receiving a response doesn’t imply the message was read, and this action will also trigger even without a response.
-
Dialog¶
-
class
telethon.tl.custom.dialog.
Dialog
(client, dialog, entities, message)¶ 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.
- folder_id (
folder_id
): - The folder ID that this dialog belongs to.
- archived (
bool
): - Whether this dialog is archived or not (
folder_id is None
). - 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”.
- title (
str
): - Alias for
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 (
Draft
): - The draft object in this dialog. It will not be
None
, so you can calldraft.set_message(...)
. - is_user (
bool
): True
if theentity
is a User.- is_group (
bool
): True
if theentity
is a Chat or a Channel megagroup.- is_channel (
bool
): True
if theentity
is a Channel.
-
__str__
()¶ Return str(self).
-
__weakref__
¶ list of weak references to the object (if defined)
-
archive
(folder=1)¶ Archives (or un-archives) this dialog.
- Args:
- folder (
int
, optional): The folder to which the dialog should be archived to.
If you want to “un-archive” it, use
folder=0
.
- folder (
- Returns:
- The Updates object that the request produces.
Example:
# Archiving dialog.archive() # Un-archiving dialog.archive(0)
-
delete
(revoke=False)¶ Deletes the dialog from your dialog list. If you own the channel this won’t destroy it, only delete it from the list.
Shorthand for
telethon.client.dialogs.DialogMethods.delete_dialog
withentity
already set.
-
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
()¶
Draft¶
-
class
telethon.tl.custom.draft.
Draft
(client, entity, 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:
-
__str__
()¶ Return str(self).
-
__weakref__
¶ list of weak references to the object (if defined)
-
entity
¶ The entity that belongs to this dialog (user, chat or channel).
-
get_input_entity
()¶ Returns
input_entity
but will make an API call if necessary.
-
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=())¶ 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=(), link_preview=None)¶ Changes the draft message on the Telegram servers. The changes are reflected in this object.
Parameters: 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
()¶
File¶
-
class
telethon.tl.custom.file.
File
(media)¶ Bases:
object
Convenience class over media like photos or documents, which supports accessing the attributes in a more convenient way.
If any of the attributes are not present in the current media, the properties will be
None
.The original media is available through the
media
attribute.-
__weakref__
¶ list of weak references to the object (if defined)
-
duration
¶ The duration in seconds of the audio or video.
-
emoji
¶ A string with all emoji that represent the current sticker.
-
ext
¶ The extension from the mime type of this file.
If the mime type is unknown, the extension from the file name (if any) will be used.
-
height
¶ The height in pixels of this media if it’s a photo or a video.
-
id
¶ The old bot-API style
file_id
representing this file.Warning
This feature has not been maintained for a long time and may not work. It will be removed in future versions.
Note
This file ID may not work under user accounts, but should still be usable by bot accounts.
You can, however, still use it to identify a file in for example a database.
-
mime_type
¶ The mime-type of this file.
-
name
¶ The file name of this document.
-
performer
¶ The performer of the song.
-
size
¶ The size in bytes of this file.
For photos, this is the heaviest thumbnail, as it often repressents the largest dimensions.
-
sticker_set
¶ The InputStickerSet to which the sticker file belongs.
-
title
¶ The title of the song.
-
width
¶ The width in pixels of this media if it’s a photo or a video.
-
Forward¶
-
class
telethon.tl.custom.forward.
Forward
(client, original, entities)¶ Bases:
telethon.tl.custom.chatgetter.ChatGetter
,telethon.tl.custom.sendergetter.SenderGetter
Custom class that encapsulates a MessageFwdHeader providing an abstraction to easily access information like the original sender.
Remember that this class implements
ChatGetter
andSenderGetter
which means you have access to all their sender and chat properties and methods.Attributes:
- original_fwd (MessageFwdHeader):
- The original MessageFwdHeader instance.
- Any other attribute:
- Attributes not described here are the same as those available in the original MessageFwdHeader.
InlineBuilder¶
-
class
telethon.tl.custom.inlinebuilder.
InlineBuilder
(client)¶ Bases:
object
Helper class to allow defining
InlineQuery
results
.Common arguments to all methods are explained here to avoid repetition:
- text (
str
, optional): - If present, the user will send a text message with this text upon being clicked.
- link_preview (
bool
, optional): - Whether to show a link preview in the sent text message or not.
- geo (InputGeoPoint, GeoPoint, InputMediaVenue, MessageMediaVenue, optional):
- If present, it may either be a geo point or a venue.
- period (int, optional):
- The period in seconds to be used for geo points.
- contact (InputMediaContact, MessageMediaContact, optional):
- If present, it must be the contact information to send.
- game (
bool
, optional): - May be
True
to indicate that the game will be sent. - buttons (
list
,custom.Button
, KeyboardButton, optional): - Same as
buttons
forclient.send_message()
. - parse_mode (
str
, optional): - Same as
parse_mode
forclient.send_message()
. - id (
str
, optional): The string ID to use for this result. If not present, it will be the SHA256 hexadecimal digest of converting the created InputBotInlineResult with empty ID to
bytes()
, so that the ID will be deterministic for the same input.Note
If two inputs are exactly the same, their IDs will be the same too. If you send two articles with the same ID, it will raise
ResultIdDuplicateError
. Consider giving them an explicit ID if you need to send two results that are the same.
-
__weakref__
¶ list of weak references to the object (if defined)
-
article
(title, description=None, *, url=None, thumb=None, content=None, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None)¶ Creates new inline result of article type.
- Args:
- title (
str
): - The title to be shown for this result.
- description (
str
, optional): - Further explanation of what this result means.
- url (
str
, optional): - The URL to be shown for this result.
- thumb (InputWebDocument, optional):
- The thumbnail to be shown for this result. For now it has to be a InputWebDocument if present.
- content (InputWebDocument, optional):
- The content to be shown for this result. For now it has to be a InputWebDocument if present.
- title (
- Example:
results = [ # Option with title and description sending a message. builder.article( title='First option', description='This is the first option', text='Text sent after clicking this option', ), # Option with title URL to be opened when clicked. builder.article( title='Second option', url='https://example.com', text='Text sent if the user clicks the option and not the URL', ), # Sending a message with buttons. # You can use a list or a list of lists to include more buttons. builder.article( title='Third option', text='Text sent with buttons below', buttons=Button.url('https://example.com'), ), ]
-
document
(file, title=None, *, description=None, type=None, mime_type=None, attributes=None, force_document=False, voice_note=False, video_note=False, use_cache=True, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None, include_media=True)¶ Creates a new inline result of document type.
use_cache
,mime_type
,attributes
,force_document
,voice_note
andvideo_note
are described inclient.send_file
.- Args:
- file (
obj
): - Same as
file
forclient.send_file()
. - title (
str
, optional): - The title to be shown for this result.
- description (
str
, optional): - Further explanation of what this result means.
- type (
str
, optional): - The type of the document. May be one of: article, audio,
contact, file, geo, gif, photo, sticker, venue, video, voice.
It will be automatically set if
mime_type
is specified, and default to'file'
if no matching mime type is found. you may need to passattributes
in order to usetype
effectively. - attributes (
list
, optional): - Optional attributes that override the inferred ones, like DocumentAttributeFilename and so on.
- include_media (
bool
, optional): - Whether the document file used to display the result should be included in the message itself or not. By default, the document is included, and the text parameter alters the caption.
- file (
- Example:
results = [ # Sending just the file when the user selects it. builder.document('/path/to/file.pdf'), # Including a caption with some in-memory file. file_bytesio = ... builder.document( file_bytesio, text='This will be the caption of the sent file', ), # Sending just the message without including the file. builder.document( photo, text='This will be a normal text message', include_media=False, ), ]
-
game
(short_name, *, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None)¶ Creates a new inline result of game type.
- Args:
- short_name (
str
): - The short name of the game to use.
- short_name (
-
photo
(file, *, id=None, include_media=True, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None)¶ Creates a new inline result of photo type.
- Args:
- include_media (
bool
, optional): - Whether the photo file used to display the result should be included in the message itself or not. By default, the photo is included, and the text parameter alters the caption.
- file (
obj
, optional): - Same as
file
forclient.send_file()
.
- include_media (
- Example:
results = [ # Sending just the photo when the user selects it. builder.photo('/path/to/photo.jpg'), # Including a caption with some in-memory photo. photo_bytesio = ... builder.photo( photo_bytesio, text='This will be the caption of the sent photo', ), # Sending just the message without including the photo. builder.photo( photo, text='This will be a normal text message', include_media=False, ), ]
- text (
InlineResult¶
-
class
telethon.tl.custom.inlineresult.
InlineResult
(client, original, query_id=None, *, entity=None)¶ Bases:
object
Custom class that encapsulates a bot inline result providing an abstraction to easily access some commonly needed features (such as clicking a result to select it).
Attributes:
- result (BotInlineResult):
- The original BotInlineResult object.
-
ARTICLE
= 'article'¶
-
AUDIO
= 'audio'¶
-
CONTACT
= 'contact'¶
-
DOCUMENT
= 'document'¶
-
GAME
= 'game'¶
-
GIF
= 'gif'¶
-
LOCATION
= 'location'¶
-
PHOTO
= 'photo'¶
-
VENUE
= 'venue'¶
-
VIDEO
= 'video'¶
-
VIDEO_GIF
= 'mpeg4_gif'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
click
(entity=None, reply_to=None, comment_to=None, silent=False, clear_draft=False, hide_via=False, background=None)¶ Clicks this result and sends the associated
message
.- Args:
- entity (
entity
): - The entity to which the message of this result should be sent.
- reply_to (
int
|Message
, optional): - If present, the sent message will reply to this ID or message.
- comment_to (
int
|Message
, optional): - Similar to
reply_to
, but replies in the linked group of a broadcast channel instead (effectively leaving a “comment to” the specified message). - silent (
bool
, optional): - Whether the message should notify people with sound or not.
Defaults to
False
(send with a notification sound unless the person has the chat muted). Set it toTrue
to alter this behaviour. - clear_draft (
bool
, optional): - Whether the draft should be removed after sending the
message from this result or not. Defaults to
False
. - hide_via (
bool
, optional): - Whether the “via @bot” should be hidden or not. Only works with certain bots (like @bing or @gif).
- background (
bool
, optional): - Whether the message should be send in background.
- entity (
-
document
¶ Returns either the WebDocument content for normal results or the Document for media results.
-
download_media
(*args, **kwargs)¶ Downloads the media in this result (if there is a document, the document will be downloaded; otherwise, the photo will if present).
This is a wrapper around
client.download_media
.
-
message
¶ The always-present BotInlineMessage that will be sent if
click
is called on this result.
-
photo
¶ Returns either the WebDocument thumbnail for normal results or the Photo for media results.
-
type
¶ The always-present type of this result. It will be one of:
'article'
,'photo'
,'gif'
,'mpeg4_gif'
,'video'
,'audio'
,'voice'
,'document'
,'location'
,'venue'
,'contact'
,'game'
.You can access all of these constants through
InlineResult
, such asInlineResult.ARTICLE
,InlineResult.VIDEO_GIF
, etc.
-
url
¶ The URL present in this inline results. If you want to “click” this URL to open it in your browser, you should use Python’s
webbrowser.open(url)
for such task.
InlineResults¶
-
class
telethon.tl.custom.inlineresults.
InlineResults
(client, original, *, entity=None)¶ Bases:
list
Custom class that encapsulates BotResults providing an abstraction to easily access some commonly needed features (such as clicking one of the results to select it)
Note that this is a list of
InlineResult
so you can iterate over it or use indices to access its elements. In addition, it has some attributes.- Attributes:
- result (BotResults):
- The original BotResults object.
- query_id (
int
): - The random ID that identifies this query.
- cache_time (
int
): - For how long the results should be considered
valid. You can call
results_valid
at any moment to determine if the results are still valid or not. - users (User):
- The users present in this inline query.
- gallery (
bool
): - Whether these results should be presented in a grid (as a gallery of images) or not.
- next_offset (
str
, optional): - The string to be used as an offset to get the next chunk of results, if any.
- switch_pm (InlineBotSwitchPM, optional):
- If presents, the results should show a button to switch to a private conversation with the bot using the text in this object.
-
__repr__
()¶ Return repr(self).
-
__str__
()¶ Return str(self).
-
__weakref__
¶ list of weak references to the object (if defined)
Message¶
-
class
telethon.tl.custom.message.
Message
(id: int, peer_id: Union[telethon.tl.types.PeerUser, telethon.tl.types.PeerChat, telethon.tl.types.PeerChannel] = None, date: Optional[datetime.datetime] = None, out: Optional[bool] = None, mentioned: Optional[bool] = None, media_unread: Optional[bool] = None, silent: Optional[bool] = None, post: Optional[bool] = None, from_id: Union[telethon.tl.types.PeerUser, telethon.tl.types.PeerChat, telethon.tl.types.PeerChannel, None] = None, reply_to: Union[telethon.tl.types.MessageReplyHeader, telethon.tl.types.MessageReplyStoryHeader, None] = None, ttl_period: Optional[int] = None, message: Optional[str] = None, fwd_from: Optional[telethon.tl.types.MessageFwdHeader] = None, via_bot_id: Optional[int] = None, media: Union[telethon.tl.types.MessageMediaEmpty, telethon.tl.types.MessageMediaPhoto, telethon.tl.types.MessageMediaGeo, telethon.tl.types.MessageMediaContact, telethon.tl.types.MessageMediaUnsupported, telethon.tl.types.MessageMediaDocument, telethon.tl.types.MessageMediaWebPage, telethon.tl.types.MessageMediaVenue, telethon.tl.types.MessageMediaGame, telethon.tl.types.MessageMediaInvoice, telethon.tl.types.MessageMediaGeoLive, telethon.tl.types.MessageMediaPoll, telethon.tl.types.MessageMediaDice, telethon.tl.types.MessageMediaStory, None] = None, reply_markup: Union[telethon.tl.types.ReplyKeyboardHide, telethon.tl.types.ReplyKeyboardForceReply, telethon.tl.types.ReplyKeyboardMarkup, telethon.tl.types.ReplyInlineMarkup, None] = None, entities: Optional[List[Union[telethon.tl.types.MessageEntityUnknown, telethon.tl.types.MessageEntityMention, telethon.tl.types.MessageEntityHashtag, telethon.tl.types.MessageEntityBotCommand, telethon.tl.types.MessageEntityUrl, telethon.tl.types.MessageEntityEmail, telethon.tl.types.MessageEntityBold, telethon.tl.types.MessageEntityItalic, telethon.tl.types.MessageEntityCode, telethon.tl.types.MessageEntityPre, telethon.tl.types.MessageEntityTextUrl, telethon.tl.types.MessageEntityMentionName, telethon.tl.types.InputMessageEntityMentionName, telethon.tl.types.MessageEntityPhone, telethon.tl.types.MessageEntityCashtag, telethon.tl.types.MessageEntityUnderline, telethon.tl.types.MessageEntityStrike, telethon.tl.types.MessageEntityBlockquote, telethon.tl.types.MessageEntityBankCard, telethon.tl.types.MessageEntitySpoiler, telethon.tl.types.MessageEntityCustomEmoji]]] = None, views: Optional[int] = None, edit_date: Optional[datetime.datetime] = None, post_author: Optional[str] = None, grouped_id: Optional[int] = None, from_scheduled: Optional[bool] = None, legacy: Optional[bool] = None, edit_hide: Optional[bool] = None, pinned: Optional[bool] = None, noforwards: Optional[bool] = None, reactions: Optional[telethon.tl.types.MessageReactions] = None, restriction_reason: Optional[telethon.tl.types.RestrictionReason] = None, forwards: Optional[int] = None, replies: Optional[telethon.tl.types.MessageReplies] = None, action: Union[telethon.tl.types.MessageActionEmpty, telethon.tl.types.MessageActionChatCreate, telethon.tl.types.MessageActionChatEditTitle, telethon.tl.types.MessageActionChatEditPhoto, telethon.tl.types.MessageActionChatDeletePhoto, telethon.tl.types.MessageActionChatAddUser, telethon.tl.types.MessageActionChatDeleteUser, telethon.tl.types.MessageActionChatJoinedByLink, telethon.tl.types.MessageActionChannelCreate, telethon.tl.types.MessageActionChatMigrateTo, telethon.tl.types.MessageActionChannelMigrateFrom, telethon.tl.types.MessageActionPinMessage, telethon.tl.types.MessageActionHistoryClear, telethon.tl.types.MessageActionGameScore, telethon.tl.types.MessageActionPaymentSentMe, telethon.tl.types.MessageActionPaymentSent, telethon.tl.types.MessageActionPhoneCall, telethon.tl.types.MessageActionScreenshotTaken, telethon.tl.types.MessageActionCustomAction, telethon.tl.types.MessageActionBotAllowed, telethon.tl.types.MessageActionSecureValuesSentMe, telethon.tl.types.MessageActionSecureValuesSent, telethon.tl.types.MessageActionContactSignUp, telethon.tl.types.MessageActionGeoProximityReached, telethon.tl.types.MessageActionGroupCall, telethon.tl.types.MessageActionInviteToGroupCall, telethon.tl.types.MessageActionSetMessagesTTL, telethon.tl.types.MessageActionGroupCallScheduled, telethon.tl.types.MessageActionSetChatTheme, telethon.tl.types.MessageActionChatJoinedByRequest, telethon.tl.types.MessageActionWebViewDataSentMe, telethon.tl.types.MessageActionWebViewDataSent, telethon.tl.types.MessageActionGiftPremium, telethon.tl.types.MessageActionTopicCreate, telethon.tl.types.MessageActionTopicEdit, telethon.tl.types.MessageActionSuggestProfilePhoto, telethon.tl.types.MessageActionRequestedPeer, telethon.tl.types.MessageActionSetChatWallPaper, telethon.tl.types.MessageActionSetSameChatWallPaper, None] = None)¶ Bases:
telethon.tl.custom.chatgetter.ChatGetter
,telethon.tl.custom.sendergetter.SenderGetter
,telethon.tl.tlobject.TLObject
This custom class aggregates both Message and MessageService to ease accessing their members.
Remember that this class implements
ChatGetter
andSenderGetter
which means you have access to all their sender and chat properties and methods.- Members:
- out (
bool
): Whether the message is outgoing (i.e. you sent it from another session) or incoming (i.e. someone else sent it).
Note that messages in your own chat are always incoming, but this member will be
True
if you send a message to your own chat. Messages you forward to your chat are not considered outgoing, just like official clients display them.- mentioned (
bool
): - Whether you were mentioned in this message or not. Note that replies to your own messages also count as mentions.
- media_unread (
bool
): - Whether you have read the media in this message or not, e.g. listened to the voice note media.
- silent (
bool
): - Whether the message should notify people with sound or not. Previously used in channels, but since 9 August 2019, it can also be used in private chats.
- post (
bool
): - Whether this message is a post in a broadcast channel or not.
- from_scheduled (
bool
): - Whether this message was originated from a previously-scheduled message or not.
- legacy (
bool
): - Whether this is a legacy message or not.
- edit_hide (
bool
): - Whether the edited mark of this message is edited should be hidden (e.g. in GUI clients) or shown.
- pinned (
bool
): - Whether this message is currently pinned or not.
- noforwards (
bool
): - Whether this message can be forwarded or not.
- id (
int
): - The ID of this message. This field is always present.
Any other member is optional and may be
None
. - from_id (Peer):
- The peer who sent this message, which is either
PeerUser, PeerChat or PeerChannel.
This value will be
None
for anonymous messages. - peer_id (Peer):
- The peer to which this message was sent, which is either PeerUser, PeerChat or PeerChannel. This will always be present except for empty messages.
- fwd_from (MessageFwdHeader):
- The original forward header if this message is a forward.
You should probably use the
forward
property instead. - via_bot_id (
int
): - The ID of the bot used to send this message through its inline mode (e.g. “via @like”).
- reply_to (MessageReplyHeader):
- The original reply header if this message is replying to another.
- date (
datetime
): - The UTC+0
datetime
object indicating when this message was sent. This will always be present except for empty messages. - message (
str
): - The string text of the message for
Message
instances, which will beNone
for other types of messages. - media (MessageMedia):
The media sent with this message if any (such as photos, videos, documents, gifs, stickers, etc.).
You may want to access the
photo
,document
etc. properties instead.If the media was not present or it was MessageMediaEmpty, this member will instead be
None
for convenience.- reply_markup (ReplyMarkup):
- The reply markup for this message (which was sent
either via a bot or by a bot). You probably want
to access
buttons
instead. - entities (List[MessageEntity]):
- The list of markup entities in this message, such as bold, italics, code, hyperlinks, etc.
- views (
int
): - The number of views this message from a broadcast channel has. This is also present in forwards.
- forwards (
int
): - The number of times this message has been forwarded.
- replies (
int
): - The number of times another message has replied to this message.
- edit_date (
datetime
): - The date when this message was last edited.
- post_author (
str
): - The display name of the message sender to show in messages sent to broadcast channels.
- grouped_id (
int
): - If this message belongs to a group of messages (photo albums or video albums), all of them will have the same value here.
- reactions (MessageReactions)
- Reactions to this message.
- restriction_reason (List[RestrictionReason])
- An optional list of reasons why this message was restricted.
If the list is
None
, this message has not been restricted. - ttl_period (
int
): - The Time To Live period configured for this message.
The message should be erased from wherever it’s stored (memory, a
local database, etc.) when
datetime.now() > message.date + timedelta(seconds=message.ttl_period)
. - action (MessageAction):
- The message action object of the message for MessageService
instances, which will be
None
for other types of messages.
- out (
-
action_entities
¶ Returns a list of entities that took part in this action.
Possible cases for this are MessageActionChatAddUser, types.MessageActionChatCreate, MessageActionChatDeleteUser, MessageActionChatJoinedByLink MessageActionChatMigrateTo and MessageActionChannelMigrateFrom.
If the action is neither of those, the result will be
None
. If some entities could not be retrieved, the list may contain someNone
items in it.
Returns the total button count (sum of all
buttons
rows).
Returns a list of lists of
MessageButton
, if any.Otherwise, it returns
None
.
-
click
(i=None, j=None, *, text=None, filter=None, data=None, share_phone=None, share_geo=None, password=None)¶ Calls SendVote with the specified poll option or
button.click
on the specified button.Does nothing if the message is not a poll or has no buttons.
- Args:
- i (
int
|list
): Clicks the i’th button or poll option (starting from the index 0). For multiple-choice polls, a list with the indices should be used. Will
raise IndexError
if out of bounds. Example:>>> message = ... # get the message somehow >>> # Clicking the 3rd button >>> # [button1] [button2] >>> # [ button3 ] >>> # [button4] [button5] >>> await message.click(2) # index
- j (
int
): Clicks the button at position (i, j), these being the indices for the (row, column) respectively. Example:
>>> # Clicking the 2nd button on the 1st row. >>> # [button1] [button2] >>> # [ button3 ] >>> # [button4] [button5] >>> await message.click(0, 1) # (row, column)
This is equivalent to
message.buttons[0][1].click()
.- text (
str
|callable
): Clicks the first button or poll option with the text “text”. This may also be a callable, like a
re.compile(...).match
, and the text will be passed to it.If you need to select multiple options in a poll, pass a list of indices to the
i
parameter.- filter (
callable
): Clicks the first button or poll option for which the callable returns
True
. The callable should accept a singleMessageButton
orPollAnswer
argument.If you need to select multiple options in a poll, pass a list of indices to the
i
parameter.- data (
bytes
): - This argument overrides the rest and will not search any
buttons. Instead, it will directly send the request to
behave as if it clicked a button with said data. Note
that if the message does not have this data, it will
raise DataInvalidError
. - share_phone (
bool
|str
| tl:InputMediaContact
): When clicking on a keyboard button requesting a phone number (KeyboardButtonRequestPhone), this argument must be explicitly set to avoid accidentally sharing the number.
It can be
True
to automatically share the current user’s phone, a string to share a specific phone number, or a contact media to specify all details.If the button is pressed without this,
ValueError
is raised.- share_geo (
tuple
|list
| tl:InputMediaGeoPoint
): When clicking on a keyboard button requesting a geo location (KeyboardButtonRequestGeoLocation), this argument must be explicitly set to avoid accidentally sharing the location.
It must be a
tuple
offloat
as(longitude, latitude)
, or a InputGeoPoint instance to avoid accidentally using the wrong roder.If the button is pressed without this,
ValueError
is raised.- password (
str
): - When clicking certain buttons (such as BotFather’s confirmation
button to transfer ownership), if your account has 2FA enabled,
you need to provide your account’s password. Otherwise,
teltehon.errors.PasswordHashInvalidError
is raised.
Example:
# Click the first button await message.click(0) # Click some row/column await message.click(row, column) # Click by text await message.click(text='👍') # Click by data await message.click(data=b'payload') # Click on a button requesting a phone await message.click(0, share_phone=True)
- i (
-
client
¶ Returns the
TelegramClient
that patched this message. This will only be present if you use the friendly methods, it won’t be there if you invoke raw API methods manually, in which case you should only access members, not properties.
-
contact
¶ The MessageMediaContact in this message, if it’s a contact.
-
delete
(*args, **kwargs)¶ Deletes the message. You’re responsible for checking whether you have the permission to do so, or to except the error otherwise. Shorthand for
telethon.client.messages.MessageMethods.delete_messages
withentity
andmessage_ids
already set.If you need to delete more than one message at once, don’t use this
delete
method. Use atelethon.client.telegramclient.TelegramClient
instance directly.
-
dice
¶ The MessageMediaDice in this message, if it’s a dice roll.
-
download_media
(*args, **kwargs)¶ Downloads the media contained in the message, if any. Shorthand for
telethon.client.downloads.DownloadMethods.download_media
with themessage
already set.
-
edit
(*args, **kwargs)¶ Edits the message if it’s outgoing. Shorthand for
telethon.client.messages.MessageMethods.edit_message
with bothentity
andmessage
already set.- Returns
- The edited
Message
, unlessentity
was a InputBotInlineMessageID or InputBotInlineMessageID64 in which case this method returns a boolean. - Raises
MessageAuthorRequiredError
if you’re not the author of the message but tried editing it anyway.MessageNotModifiedError
if the contents of the message were not modified at all.MessageIdInvalidError
if the ID of the message is invalid (the ID itself may be correct, but the message with that ID cannot be edited). For example, when trying to edit messages with a reply markup (or clear markup) this error will be raised.
Note
This is different from
client.edit_message
and will respect the previous state of the message. For example, if the message didn’t have a link preview, the edit won’t add one by default, and you should force it by setting it toTrue
if you want it.This is generally the most desired and convenient behaviour, and will work for link previews and message buttons.
-
file
¶ Returns a
File
wrapping thephoto
ordocument
in this message. If the media type is different (polls, games, none, etc.), this property will beNone
.This instance lets you easily access other properties, such as
file.id
,file.name
, etc., without having to manually inspect thedocument.attributes
.
-
forward_to
(*args, **kwargs)¶ Forwards the message. Shorthand for
telethon.client.messages.MessageMethods.forward_messages
with bothmessages
andfrom_peer
already set.If you need to forward more than one message at once, don’t use this
forward_to
method. Use atelethon.client.telegramclient.TelegramClient
instance directly.
Returns
buttons
when that property fails (this is rarely needed).
-
get_entities_text
(cls=None)¶ Returns a list of
(markup entity, inner text)
(like bold or italics).The markup entity is a MessageEntity that represents bold, italics, etc., and the inner text is the
str
inside that markup entity.For example:
print(repr(message.text)) # shows: 'Hello **world**!' for ent, txt in message.get_entities_text(): print(ent) # shows: MessageEntityBold(offset=6, length=5) print(txt) # shows: world
- Args:
- cls (
type
): Returns entities matching this type only. For example, the following will print the text for all
code
entities:>>> from telethon.tl.types import MessageEntityCode >>> >>> m = ... # get the message >>> for _, inner_text in m.get_entities_text(MessageEntityCode): >>> print(inner_text)
- cls (
-
get_reply_message
()¶ The
Message
that this message is replying to, orNone
.The result will be cached after its first use.
-
gif
¶ The Document media in this message, if it’s a “gif”.
“Gif” files by Telegram are normally
.mp4
video files without sound, the so called “animated” media. However, it may be the actual gif format if the file is too large.
-
invoice
¶ The MessageMediaInvoice in this message, if it’s an invoice.
-
is_reply
¶ True
if the message is a reply to some other message.Remember that you can access the ID of the message this one is replying to through
reply_to.reply_to_msg_id
, and theMessage
object withget_reply_message()
.
-
mark_read
()¶ Marks the message as read. Shorthand for
client.send_read_acknowledge()
with bothentity
andmessage
already set.
-
photo
¶ The Photo media in this message, if any.
This will also return the photo for MessageService if its action is MessageActionChatEditPhoto, or if the message has a web preview with a photo.
-
pin
(*, notify=False, pm_oneside=False)¶ Pins the message. Shorthand for
telethon.client.messages.MessageMethods.pin_message
with bothentity
andmessage
already set.
-
poll
¶ The MessageMediaPoll in this message, if it’s a poll.
-
raw_text
¶ The raw message text, ignoring any formatting. Will be
None
for MessageService.Setting a value to this field will erase the
entities
, unlike changing themessage
member.
-
reply
(*args, **kwargs)¶ Replies to the message (as a reply). Shorthand for
telethon.client.messages.MessageMethods.send_message
with bothentity
andreply_to
already set.
-
reply_to_msg_id
¶ Returns the message ID this message is replying to, if any. This is equivalent to accessing
.reply_to.reply_to_msg_id
.
-
respond
(*args, **kwargs)¶ Responds to the message (not as a reply). Shorthand for
telethon.client.messages.MessageMethods.send_message
withentity
already set.
-
text
¶ The message text, formatted using the client’s default parse mode. Will be
None
for MessageService.
-
to_id
¶ Returns the peer to which this message was sent to. This used to exist to infer the
.peer_id
.
-
unpin
()¶ Unpins the message. Shorthand for
telethon.client.messages.MessageMethods.unpin_message
with bothentity
andmessage
already set.
-
venue
¶ The MessageMediaVenue in this message, if it’s a venue.
MessageButton¶
Bases:
object
Note
Message.buttons
are instances of this type. If you want to define a reply markup for e.g. sending messages, refer toButton
instead.Custom class that encapsulates a message button providing an abstraction to easily access some commonly needed features (such as clicking the button itself).
Attributes:
- button (KeyboardButton):
- The original KeyboardButton object.
list of weak references to the object (if defined)
Emulates the behaviour of clicking this button.
If it’s a normal KeyboardButton with text, a message will be sent, and the sent
Message
returned.If it’s an inline KeyboardButtonCallback with text and data, it will be “clicked” and the BotCallbackAnswer returned.
If it’s an inline KeyboardButtonSwitchInline button, the StartBotRequest will be invoked and the resulting updates returned.
If it’s a KeyboardButtonUrl, the URL of the button will be passed to
webbrowser.open
and returnTrue
on success.If it’s a KeyboardButtonRequestPhone, you must indicate that you want to
share_phone=True
in order to share it. Sharing it is not a default because it is a privacy concern and could happen accidentally.You may also use
share_phone=phone
to share a specific number, in which case eitherstr
or InputMediaContact should be used.If it’s a KeyboardButtonRequestGeoLocation, you must pass a tuple in
share_geo=(longitude, latitude)
. Note that Telegram seems to have some heuristics to determine impossible locations, so changing this value a lot quickly may not work as expected. You may also pass a InputGeoPoint if you find the order confusing.
Returns the
telethon.client.telegramclient.TelegramClient
instance that created this instance.
The
bytes
data for KeyboardButtonCallback objects.
The query
str
for KeyboardButtonSwitchInline objects.
The text string of the button.
The url
str
for KeyboardButtonUrl objects.
ParticipantPermissions¶
-
class
telethon.tl.custom.participantpermissions.
ParticipantPermissions
(participant, chat: bool)¶ Bases:
object
Participant permissions information.
The properties in this objects are boolean values indicating whether the user has the permission or not.
- Example
permissions = ... if permissions.is_banned: "this user is banned" elif permissions.is_admin: "this user is an administrator"
-
__weakref__
¶ list of weak references to the object (if defined)
-
add_admins
¶ Whether the administrator can add new administrators with the same or less permissions than them.
-
anonymous
¶ Whether the administrator will remain anonymous when sending messages.
-
ban_users
¶ Whether the administrator can ban other users or not.
-
change_info
¶ Whether the administrator can change the information about the chat, such as title or description.
-
delete_messages
¶ Whether the administrator can delete messages from other participants.
-
edit_messages
¶ Whether the administrator can edit messages.
-
has_default_permissions
¶ Whether the user is a normal user of the chat (not administrator, but not banned either, and has no restrictions applied).
-
has_left
¶ Whether the user left the chat.
-
invite_users
¶ Whether the administrator can add new users to the chat.
-
is_admin
¶ Whether the user is an administrator of the chat or not. The creator also counts as begin an administrator, since they have all permissions.
-
is_banned
¶ Whether the user is banned in the chat.
-
is_creator
¶ Whether the user is the creator of the chat or not.
-
manage_call
¶ Whether the user will be able to manage group calls.
-
pin_messages
¶ Whether the administrator can pin messages or not.
-
post_messages
¶ Whether the administrator can post messages in the broadcast channel.
QRLogin¶
-
class
telethon.tl.custom.qrlogin.
QRLogin
(client, ignored_ids)¶ Bases:
object
QR login information.
Most of the time, you will present the
url
as a QR code to the user, and while it’s being shown, callwait
.-
__weakref__
¶ list of weak references to the object (if defined)
-
expires
¶ The
datetime
at which the QR code will expire.If you want to try again, you will need to call
recreate
.
-
recreate
()¶ Generates a new token and URL for a new QR code, useful if the code has expired before it was imported.
-
token
¶ The binary data representing the token.
It can be used by a previously-authorized client in a call to auth.importLoginToken to log the client that originally requested the QR login.
-
url
¶ The
tg://login
URI with the token. When opened by a Telegram application where the user is logged in, it will import the login token.If you want to display a QR code to the user, this is the URL that should be launched when the QR code is scanned (the URL that should be contained in the QR code image you generate).
Whether you generate the QR code image or not is up to you, and the library can’t do this for you due to the vast ways of generating and displaying the QR code that exist.
The URL simply consists of
token
base64-encoded.
-
wait
(timeout: float = None)¶ Waits for the token to be imported by a previously-authorized client, either by scanning the QR, launching the URL directly, or calling the import method.
This method must be called before the QR code is scanned, and must be executing while the QR code is being scanned. Otherwise, the login will not complete.
Will raise
asyncio.TimeoutError
if the login doesn’t complete on time.- Arguments
- timeout (float):
- The timeout, in seconds, to wait before giving up. By default the library will wait until the token expires, which is often what you want.
- Returns
- On success, an instance of User. On failure it will raise.
-
SenderGetter¶
-
class
telethon.tl.custom.sendergetter.
SenderGetter
(sender_id=None, *, sender=None, input_sender=None)¶ Bases:
abc.ABC
Helper base class that introduces the
sender
,input_sender
andsender_id
properties andget_sender
andget_input_sender
methods.-
__weakref__
¶ list of weak references to the object (if defined)
-
get_input_sender
()¶ Returns
input_sender
, but will make an API call to find the input sender unless it’s already cached.
-
get_sender
()¶ Returns
sender
, but will make an API call to find the sender unless it’s already cached.If you only need the ID, use
sender_id
instead.If you need to call a method which needs this sender, use
get_input_sender()
instead.
-
input_sender
¶ This InputPeer is the input version of the user/channel who sent the message. Similarly to
input_chat
, this doesn’t have things like username or similar, but still useful in some cases.Note that this might not be available if the library can’t find the input chat, or if the message a broadcast on a channel.
-
sender
¶ Returns the User or Channel that sent this object. It may be
None
if Telegram didn’t send the sender.If you only need the ID, use
sender_id
instead.If you need to call a method which needs this chat, use
input_sender
instead.If you’re using
telethon.events
, useget_sender()
instead.
-