All weekend I’ve been itching to write about telegram-cli, a command-line interface to the Telegram messaging service.
It’s something I’m keen to write about because the Wi-Fi in the coffee shop I regularly visit is a bit… Well, it’s a big like coffee shop Wi-Fi!
I rely on a ropey 4G tether (complete with 750MB data cap) which means data-nimble tools help me stay connected, even when the connection isn’t great.
UPDATE 2024: This tool no longer works :(
Telegram – What Is It?
Telegram is a sort of open, secure messaging service that runs in the cloud. Think of it like WhatsApp meets Slack.
The service has a robust open API and puts a lot of emphasis on privacy, and offers a slate of mobile, web and desktop clients. These factors have helped to make the service incredibly popular with open-source, privacy and Linux enthusiasts in particular.
Telegram lets you send regular text messages, photos, videos and other files to other Telegram users, as well as initiate so-called ‘secret chats’ which are encrypted.
For the avoidance of doubt please note that I am not writing this post to persuade anyone that Telegram is ‘the best’ messaging service around. Nor am I going to say that it is the most secure, or that using it through a Terminal app makes any sense when various mobile and desktop GUI apps are freely available.
Nope, I’m just here to highlight an alternative way to use something that you may already use. If you find it helpful, fantastic. If you don’t, no worries.
Telegram CLI Features
Like fully-fledged GUI clients, Telegram-cli lets you send, receive and read messages to/from your contacts, channels and groups.
It offers the following features:
- Colored terminal messages
- Message management, including message history
- Create/join/manage group chats
- Start secure encrypted one-on-one conversations
- Add/edit/remove contacts
- Send/load photos and videos
Telegram-CLI rather helpfully supports tab completion. If you’re the sort of person who regularly forget commands, or simple like to speed up your workflow, you only need to remember the first few characters of any command, and the tab key will do the rest.
Features that aren’t supported in telegram-cli include stickers, emoji, custom backgrounds, voice messages, and other visual fluff.
How To Install Telegram CLI on Ubuntu
If you’re running Ubuntu 16.04 LTS or later can install telegram-cli through the Snap store by searching for ‘telegram-cli’ in the Ubuntu Software app or running:
sudo snap install telegram-cli
Logging In
Like WhatsApp, Telegram is a service centred around your mobile number as your identity. You’ll need to have already signed up to Telegram from a mobile app before you can “log in” and use the service through the Terminal.
Assuming you have, just run the app using the following command:
telegram-cli
This will prompt you for your phone number. Type it in to the terminal, then double-check that it’s correct. Press Enter.
A code will be sent to your mobile device. You simply need to enter this code into the Terminal when prompted to do so to authenticate.
After that, you’re good to go!
Using Telegram-CLI
Telegram works on the basis of “peers” rather than phone numbers. To see a list of people in your contacts list who you can message, type:
contact_list
To view a list of all current chats, groups and unread messages type:
dialog_list
To message a contact or group, type msg
followed by their name (remember that you can use tab to autocomplete) and then your message:
msg <name> <message>
To view a conversation or chat history type history
followed by the name of the contact or group and the number of lines you wish to see:
history <peer> <number of lines>
E.g.: history Liam 10
will print the 10 most recent messages in my conversation with Liam:
You’ll find a comprehensive list of all the commands supported by telegram-cli on the project’s GitHub wiki:
Or, while using the client, by running help
.