telegram logoAll weekend I’ve been itching to write about telegram-cli, a command-line interface to—faux gasp of surprise—the Telegram messaging service.

Naturally, because I have something I’m keen to write about, the Wi-Fi in the coffee shop is acting up. As I’m relying on a ropey 3G tether (complete with 750MB data cap) I haven’t actually been able to try this app out.

As I’ve already bought a large latte and a bus ticket today, I need to get a return on my ‘investment’. So, apologies up front, I’m going to try and write about it anyway…

Back home I’ve tried the app out and it works just dandy!

Telegram Isn’t For Everyone

Telegram is a sort of open, secure messaging service that runs in the cloud. It provides a robust open API, puts a lot of emphasis on privacy, and offers a slate of mobile, web and desktop clients. These points alone have seen the service become incredibly popular with open-source, privacy and Linux enthusiasts.

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 the fully-fledged clients, Telegram-cli lets you send, receive and read messages 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, and other visual fluff.

How To Install Telegram CLI on Ubuntu

screen-shot-2016-10-23-at-18-57-20

If you’re running Ubuntu 16.04 LTS or Ubuntu 16.10 you 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

screen-shot-2016-10-23-at-18-53-49

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:

screen-shot-2016-10-23-at-18-46-29

You’ll find a comprehensive list of all the commands supported by telegram-cli on the project’s GitHub wiki:

View a List of Telegram-CLI Commands

Or, while using the client, by running help.