With over 100 million monthly active users, Telegram is undoubtedly one of the most popular messaging apps today. The application’s unique selling point is that it’s cloud-based and offers strong encryption as well as the ability for messages to self-destruct.
Telegram’s official app is available on all popular platforms, be it mobile (Android, iOS, and Windows Phone) or desktop (Windows, MacOS, and Linux). Talking about Telegram for Linux, we’ve already covered how to install the official app on the platform, as well as a third-party Telegram client called Cutegram.
Now, both the official Telegram app as well as Cutegram are GUI-based, and as many of you’d be aware, Linux can be configured to remove the graphical part – there are even some distributions that do not come with a GUI out of the box. So, in this article, we will discuss how you can access Telegram through the command line in Linux.
Note: please note that all the commands and instructions mentioned in this article have been tested on Ubuntu 16.04.
Access Telegram from command line
To access the messaging service from the command line, you need to first download and install (from source) a tool named telegram-cli, which you can do by executing the following commands:
After the above mentioned commands are successful, you’ll be able to find the telegram-cli binary in the “bin” sub-directory. To launch the tool, execute the following commands:
It’s worth mentioning that when I tried launching the tool for the first time, I got the following error:
It’s quite likely that you’ll get this error as well.
I tried googling the error and learned that “assertion “0” failed” is a known issue. After going through the details as well as user comments on the page where the issue is logged, I decided to comment the line number 101 in the “tgl/mtproto-utils.c” file, compile the binary again, and give it another try.
This time the tool launched successfully.
Given that the app works with phone numbers, you’ll be asked to enter yours, following which you’ll get a numeric code on your phone which you’ll have to enter on the command line. Once that is done, you are all set to use Telegram on the command line.
To use the service on terminal, you’ll have to keep in mind a list of commands that telegram-cli offers. For example, to send a message to one of your Telegram contacts, use the following command:
msg [peer] [text]
Replace [peer] with the name of the contact (just start typing the name and hit the TAB key; the name will be auto-completed), and [text] with the text you want to send. The following screen-shot shows the message I sent to one of my contacts and their reply.
Here is an exhaustive list of messaging-related telegram-cli commands:
- msg [peer] [text] – sends message to this peer
- fwd [user] [msg-seqno] – forward message to user. You can see message numbers starting client with -N
- chat_with_peer [peer] – starts one-on-one chat session with this peer. /exit or /quit to end this mode
- add_contact [phone-number] [first-name] [last-name] – tries to add contact to contact list by phone
- rename_contact [user] [first-name] [last-name] – tries to rename contact. If you have another device it will be a fight
- mark_read [peer] – marks all received messages with peer as read
- delete_msg [msg-seqno] – deletes message (not completly, though)
- restore_msg [msg-seqno] – restores delete message. Impossible for secret chats. Only possible short time (one hour, I think) after deletion
For the complete list of commands that the tool offers, head here.
Agreed, the installation process described here isn’t straightforward, and once that is done you need to remember a lot of commands to use the messaging service. But all that doesn’t take away the fact that you CAN access your Telegram account via the command line which holds significance given that not every major/popular service can be accessed from terminal.
Installation is a one time process, so that shouldn’t be a big issue, and as far as commands are concerned, you’ll get used to them over time, just like you learned the Linux command line basics in general.