a session to be used to save the connection and auth key to. This can be a custom session that inherits MemorySession.
The API ID you obtained from https://my.telegram.org.
The API hash you obtained from https://my.telegram.org.
Used to handle all aspects of connecting to telegram.
This method will connect to the telegram servers and check if the user is already logged in.
in the case of a new connection this will sign in if the phone already exists or sign up otherwise
By using this method you are agreeing to Telegram's Terms of Service https://core.telegram.org/api/terms.
this method also calls getMe to tell telegram that we want to receive updates.
see UserAuthParams and BotAuthParams
nothing
Checks whether the current client is authorized or not. (logged in as a user)
boolean (true of authorized else false)
Logs in as a user. Should only be used when not already logged in.
This method will send a code when needed.
This will also sign up if needed.
credentials to be used.
user auth params.
logs the user using a QR code to be scanned.
this function generates the QR code that needs to be scanned by mobile.
credentials to be used.
user auth params.
Sends a telegram authentication code to the phone number.
credentials to be used.
the phone number to send the code to
whether to send it as an SMS or a normal in app message
the phone code hash and whether it was sent via app
Uses the 2FA password to sign in the account.
This function should be used after the user has signed in with the code they received.
credentials to be used.
user auth params.
the logged in user.
Used to sign in as a bot.
credentials to be used.
user auth params.
instance User of the logged in bot.
Changes the 2FA settings of the logged in user. Note that this method may be incredibly slow depending on the prime numbers that must be used during the process to make sure that everything is safe.
Has no effect if both current and new password are omitted.
Promise
Makes an inline query to the specified bot and gets the result list.
This is equivalent to writing @pic something
in clients
the bot entity to which the inline query should be made
the query string that should be made for that bot (up to 512 characters). can be empty
The entity where the inline query is being made from.
Certain bots use this to display different results depending on where it's used, such as private chats, groups or channels.
If specified, it will also be the default entity where the message will be sent after clicked.
Otherwise, the “empty peer” will be used, which some bots may not handle correctly.
String offset of the results to be returned. can be empty
The geo point location information to send to the bot for localised results. Available under some bots.
a list of InlineResults
Builds a ReplyInlineMarkup or ReplyKeyboardMarkup for the given buttons.
Does nothing if either no buttons are provided or the provided argument is already a reply markup.
this function is called internally when passing an array of buttons.
The button, array of buttons, array of array of buttons or markup to convert into a markup.
Whether the buttons must be inline buttons only or not.
Low-level method to download files from their input location. downloadMedia should generally be used over this.
The file location from which the file will be downloaded. See getInputLocation source for a complete list of supported types.
a Buffer downloaded from the inputFile.
Iterates over a file download, yielding chunks of the file. This method can be used to stream files in a more convenient way, since it offers more control (pausing, resuming, etc.)
a Buffer downloaded from the inputFile.
Downloads the profile photo from the given user,chat or channel.
This method will return an empty buffer in case of no profile photo.
where to download the photo from.
buffer containing the profile photo. can be empty in case of no profile photo.
Downloads the given media from a message or a media object.
this will return an empty Buffer in case of wrong or empty media.
instance of a message or a media.
a buffer containing the downloaded data if outputFile is undefined else nothing.
Setter for parseMode. parseMode
can be md,markdown for Markdown or html for html. can also pass a custom mode. pass undefined for no parsing.
Iterates over the messages for a given chat.
The default order is from newest to oldest but can be changed with the reverse param.
If either search
, filter
or fromUser
are provided this will use Api.messages.Search instead of Api.messages.GetHistory.
The entity from whom to retrieve the message history.
It may be undefined to perform a global search, or to get messages by their ID from no particular chat
Note that some of the offsets will not work if this is the case.
Note that if you want to perform a global search, you must set a non-empty search string, a filter. or fromUser.
Same as iterMessages() but returns a TotalList instead.
if the limit
is not set, it will be 1 by default unless both minId
and maxId
are set. in which case the entire range will be returned.
The entity from whom to retrieve the message history. see iterMessages.
see IterMessagesParams.
TotalList of messages.
Sends a message to the specified user, chat or channel.
The default parse mode is the same as the official applications (a custom flavour of markdown). bold, code
or italic are available.
In addition you can send links and mentions (or using IDs like in the Bot API: mention) and pre blocks with three backticks.
Sending a /start command with a parameter (like ?start=data) is also done through this method. Simply send '/start data' to the bot.
See also Message.respond() and Message.reply().
Who to sent the message to.
The sent custom Message.
Forwards the given messages to the specified entity.
If you want to "forward" a message without the forward header
(the "forwarded from" text), you should use sendMessage
with
the original message instead. This will send a copy of it.
See also Message.forwardTo`.
To which entity the message(s) will be forwarded.
The list of forwarded Message, Note.
if some messages failed to be forwarded the returned list will have them as undefined.
Used to edit a message by changing it's text or media
message refers to the message to be edited not what to edit
text refers to the new text
See also Message.edit()
Notes: It is not possible to edit the media of a message that doesn't contain media.
From which chat to edit the message.
This can also be the message to be edited, and the entity will be inferred from it, so the next parameter will be assumed to be the message text.
You may also pass a InputBotInlineMessageID, which is the only way to edit messages that were sent after the user selects an inline query result. Not supported yet!
see EditMessageParams.
The edited Message.
Deletes the given messages, optionally "for everyone".
See also Message.delete`.
From who the message will be deleted. This can actually be undefined
for normal chats, but must be present for channels and megagroups.
The IDs (or ID) or messages to be deleted.
Whether the message should be deleted for everyone or not. By default it has the opposite behaviour of official clients, and it will delete the message for everyone. Disabling this has no effect on channels or megagroups, since it will unconditionally delete the message for everyone.
A list of AffectedMessages, each item being the result for the delete calls of the messages in chunks of 100 each.
Pins a message in a chat.
See also Message.pin`.
The chat where the message should be pinned.
The message or the message ID to pin. If it's undefined
, all messages will be unpinned instead.
The pinned message. if message is undefined the return will be AffectedHistory
Unpins a message in a chat.
See also Message.unpin`.
The chat where the message should be unpinned.
The message or the message ID to unpin. If it's undefined
, all messages will be unpinned instead.
The pinned message. if message is undefined the return will be AffectedHistory
Marks messages as read and optionally clears mentions.
This effectively marks a message as read (or more than one) in the given conversation.
If a message or maximum ID is provided, all the messages up to and
including such ID will be marked as read (for all messages whose ID ≤ max_id).
See also {@link Message.markRead}`.
The chat where the message should be pinned.
The message or the message ID to pin. If it's undefined
, all messages will be unpinned instead.
see MarkAsReadParams.
boolean
Iterator over the dialogs (open conversations/subscribed channels) sequentially.
The order is the same as the one seen in official applications. (dialogs that had recent messages come first)
Same as iterDialogs but returns a TotalList instead of an iterator.
Iterates over the participants belonging to a specified chat , channel or supergroup.
Channels can return a maximum of 200 users while supergroups can return up to 10 000.
You must be an admin to retrieve users from a channel.
The entity from which to retrieve the participants list.
Exact same as iterParticipants but returns a TotalList instead.
This can be used if you want to retrieve a list instead of iterating over the users.
entity to get users from.
TODO
Registers a new event handler callback.
The callback will be called when the specified event occurs.
The callable function accepting one parameter to be used.
Note the event type passed in the callback will change depending on the eventBuilder.
-The event builder class or instance to be used,
for example new events.NewMessage({});
.
If left unspecified, {@link Raw} (the Api.TypeUpdate objects with no further processing) will be passed instead.
Inverse operation of addEventHandler().
the callback function to be removed.
the type of the event.
Lists all registered event handlers.
pair of [eventBuilder,CallableFunction]
Uploads a file to Telegram's servers, without sending it.
see UploadFileParams
Api.InputFileBig if the file size is larger than 10mb otherwise Api.InputFile
Sends message with the given file to the specified entity. This uses uploadFile internally so if you want more control over uploads you can use that.
who will receive the file.
invokes raw Telegram requests.
This is a low level method that can be used to call manually any Telegram API method.
Generally this should only be used when there isn't a friendly method that does what you need.
All available requests and types are found under the Api.
namespace.
The request to send. this should be of type request.
Optional dc id to use when sending.
The response from Telegram.
Gets the current logged in Api.User. If the user has not logged in this will throw an error.
Whether to return the input peer version Api.InputPeerUser or the whole user Api.User.
Your own Api.User
Return true if the signed-in user is a bot, false otherwise.
Returns true if the user is authorized (logged in).
Turns the given entity into a valid Telegram Api.User, Api.Chat or Api.Channel.
You can also pass a list or iterable of entities, and they will be efficiently fetched from the network.
If a username is given, the username will be resolved making an API call every time.
Resolving usernames is an expensive operation and will start hitting flood waits around 50 usernames in a short period of time.
Similar limits apply to invite links, and you should use their ID instead.
Using phone numbers (from people in your contact list), exact names, integer IDs or Peer rely on a getInputEntity first,
which in turn needs the entity to be in cache, unless a InputPeer was passed.
If the entity can't be found, ValueError will be raised.
Api.Chat,Api.Chat or Api.Channel corresponding to the input entity. A list will be returned if more than one was given.
Turns the given entity into its input entity version.
Almost all requests use this kind of InputPeer, so this is the most suitable call to make for those cases.
Generally you should let the library do its job and don't worry about getting the input entity first, but if you're going to use an entity often, consider making the call.
If a username or invite link is given, the library will use the cache.
This means that it's possible to be using a username that changed or an old invite link (this only happens if an invite link for a small group chat is used after it was upgraded to a mega-group).
Api.InputPeerUser , Api.InputPeerChat , Api.InputPeerChannel or Api.InputPeerSelf if the parameter is "me" or "self"
Gets the ID for the given entity.
This method needs to be async because peer supports usernames, invite-links, phone numbers (from people in your contact list), etc.
If addMark is false, then a positive ID will be returned instead. By default, bot-API style IDs (signed) are returned.
whether to return a bot api style id.
the ID of the entity.
Returns the DC ip in case of node or the DC web address in case of browser.
This will do an API request to fill the cache if it's the first time it's called.
The DC ID.
whether to use -1 DCs or not
if true this will get the web DCs. TODO, hardcode IPs. (These only support downloading/uploading and not creating a new AUTH key)
Disconnects all senders and removes all handlers Disconnect is safer as it will not remove your event handlers
This property is the default parse mode used when sending messages. Defaults to {@link MarkdownParser}.
It will always be either undefined or an object with parse and unparse methods.
When setting a different value it should be one of:
Small hack for using it in browsers
The current gramJS version.
Generated using TypeDoc
The TelegramClient uses several methods in different files to provide all the common functionality in a nice interface. In short, to create a client you must do:
You don't need to import any methods that are inside the TelegramClient class as they binding in it.