$put_perv_real = "/home/www/dvakompa-ru/dopol/"; ?>
This article contains a collection of useful information and commands for working with Telegram CLI.
Note: for installation instructions, refer to the README of the
The executable of Telegram CLI is called
telegram-cli. It starts up an interactive command interpreter in which you type Telegram commands.
Note that you can also execute all of these commands in a one-off fashion without entering the interactive mode of Telegram CLI. For this, use the
-e option when you start Telegram CLI:
telegram-cli -e "<command>"
It is advised to also specify the
-W option when you execute commands via the
-e option, in order to make sure all the required data has been loaded before executing your commands:
telegram-cli -W -e "<command>"
You can also get all the output in JSON format with the
telegram-cli --json -W -e "<command>"
A list with all the command-line options for the Telegram CLI executable can be printed with:
Here are some things that you need to know about Telegram CLI to better understand the subsequent commands of the cheatsheet.
As explained in my other article about
Furthermore, users can be private or public, bots are always public, groups are divided into basic groups and supergroups, where basic groups are always private and supergroups can be private or public, and finally, channels can be private or public.
Remember that public vs. private comes down to having or not having a username. A username makes a peer publicly accessible.
Now, Telegram CLI looks at these peer types a bit differently. Namely:
Here is an overview:
The Telegram CLI has commands that are specific to these three types of peers (user, chat, and channel). So, the thing to get used to is that you have to use the
user_* commands for users and bots, the
chat_* commands only for basic groups, and the
channel_* commands for channels and supergroups.
In Telegram, when you upgrade a group from a basic group to a supergroup (remember that every group is by default a basic group, as explained in
This means, if you create a group called MyGroup, use it for a bit, and then decide to upgrade to a supergroup, then you will actually have two MyGroup in the output of
dialog_list (see below), one reported as a Chat, and one reported as a Channel.
The Chat version of MyGroup remains in the state immediately before the group was upgraded to a supergroup. This version is usually not accessed anymore, but it just sticks around as its own peer. The Channel version, on the other hand, is the new supergroup version of MyGroup, and it will contain all the new messages and members. This is the version that you will usually use from now on.
One consequence of this is that if you fetch all the messages from the Channel version of MyGroup with the
history command, you get only the messages up to the point where the group has been upgraded to a supergroup. The remaining messages (from creation of the group until the upgrade to a supergroup) are present only in the Chat version of MyGroup.
This issue is described
The old Chat version of a group is usually accessible in Telegram CLI by appending
#1 to the group name. That is, for example,
In the following cheatsheet commands, the
<peer> option identifies the user, bot, group, or channel to which the command applies.
The value of
<peer> can be one of the following:
These two options are equivalent.
For example, if you have a supergroup with a display name of Crypto Bay Toronto and a username of
cryptobayto,then the following two commands are equivalent:
channel_info Crypto_Bay_Toronto channel_info @cryptobayto
Just remember this:
crypto_bay_torontowould not work)
Best is, to just use the auto-complete feature of Telegram CLI.
You can use the auto-complete feature to get an overview of all the available display names and usernames. The following lists the display names of all the known users and bots:
And to display all the corresponding usernames, type:
You can do the same with
channel_info for supergroups and channels, and
chat_info for basic groups. The auto-complete feature is smart enough to suggest only completions for the peer category to which the preceding command applies (note that with
chat_info @<TAB><TAB> there will be no output, as basic groups cannot have a username).
This lists the peer display names, and some other information, of the most recently active conversations (most recently active conversation at the bottom).
This is more or less what you see on the home screen of most Telegram apps, but in reverse order (newest conversation at the bottom, and oldest on top).
You can also specify the number of conversations to list like this:
The default value for
limit is 100.
msg <peer> <text>
<text> parameter is the text to send. It may or may not be enclosed in single or double quotes. The following values for
<text> are equivalent.
"Hi there, how are you?" 'Hi there, how are you?' Hi there, how are you?
However, if you use single or double quotes, you can also insert newlines with
\n. For example, you can do something like this:
msg @santa "Hi Santa,\n\nThanks for the presents.\n\nBest,\nDaniel"
This sends the following message:
Hi Santa,Thanks for the presents.Best, Daniel
Note: you can send messages like this to any user and bot, and to any group that you are a member of, but not to channels in which you are merely a subscriber, but not an admin. This is because only admins of a channel can send messages to this channel.
history <peer> [limit]
This prints the last chunk of messages that have been sent to/from this peer. The
limit option defines the number of messages to be printed (the default seems to be 40).
Important: this also marks all the messages with this peer as read.
resolve_username <username> channel_join @<username>
resolve_username command fixes what seems to be a glitch in Telegram CLI. If you omit it, you will likely get a
FAIL: 38: can not parse arg #1 error.
channel_join seems to also work with the display name (with spaces replaced by underscores). So, the following example would be valid too:
> resolve_username theprogrammingart The Art of Programming > channel_join The_Art_of_Programming
The following options also work:
import_channel_link t.me/joinchat/Gx1BvRIu_lGsZE4A21EwRQ import_channel_link Gx1BvRIu_lGsZE4A21EwRQ
The last option (using only the hash) is probably the preferred one.
Note that this is the only way to join a basic group other than being added by somebody else, as joining via username is not available for basic groups (because basic groups are always private and cannot have a username).
The rest is the same as above (join a basic group via an invite link).
Note that this works for both, private and public, supergroups and channels, as long as the supergroup or channel has generated an invite link.
This invalidates any previously created invite link for this basic group.
This invalidates any previously created invite link for this supergroup or channel.
This outputs the same information as
user_info <peer>, but about yourself.
This outputs the information displayed
You can also do:
This prints only the line corresponding to the specified command.
This is the equivalent of “How to get out of Vim” for Telegram CLI.