Published on June 1st, 2014 | by Sunit Nandi13
Chat with Telegram buddies the geeky way with Telegram CLI
Telegram has grabbed the headlines for being a non-profit and open alternative to the existing mobile messengers. It is often touted as the service which has the capability to replace WhatsApp, given the features it provides:
- Telegram messages are heavily encrypted and can self-destruct.
- Telegram lets you access your messages from multiple devices.
- Telegram delivers messages faster than any other application.
- Telegram servers are spread worldwide for security and speed.
- Telegram has an open API and protocol free for everyone.
- Telegram is free forever. No ads. No subscription fees.
- Telegram keeps your messages safe from hacker attacks.
- Telegram has no limits on the size of your media and chats.
Okay, so that was the whole point of using Telegram messenger in a gist. What we’ll be focussing on now, is its ability to be used on multiple devices, even devices (or computers) that have no GUI.
If you are one of those guys who are referred to as a developer, a hacker, an administrator or you simply need to spend a lot of time in the command-line, you know how much of a pain it is to switch between windows with the mouse to use a GUI application all of a sudden. So you’d prefer using the terminal for almost everything you can do. Your choice of messaging would definitely be irssi for IRC, and some of you might be familiar with BitlBee, which is an IRC-to-IM gateway which eliminates your need to install multiple IM software. If this is your case, read on to know how to use Telegram in the command-line.
Introducing Telegram CLI
Oh yes, you heard it right. Telegram CLI is a command-line client for Telegram, made by Vitaly Valtman. It uses the readline interface to take input from the user to perform requested actions. This client runs on Linux, BSD and Mac.
Lets us proceed with the installation.
Installing from distribution repositories
On Fedora type the following into the terminal:
yum install telegram-cli
Make sure you have the latest version of Fedora (i.e. Fedora 20 at the time of writing this post).
On Ubuntu 13.04 and 13.10 type the following into the terminal:
sudo apt-add-repository ppa:miry/ppa
sudo apt-get update && sudo apt-get install telegram-cli
On Ubuntu 14.04 64-bit type the following into the terminal command by command:
sudo dpkg -i ./telegram-cli_0.0.20140125-1_amd64.deb
sudo apt-get -f install
On Ubuntu 14.04 32-bit type the following into the terminal command by command:
sudo dpkg -i ./telegram-cli_0.0.20140125-1_i386.deb
sudo apt-get -f install
I would like to thank Miriam Ruiz for the PPA, and hence making our lives easier.
yaourt -S telegram-git
Gentoo users can use this EBUILD: http://gpo.zugaina.org/net-im/telegram-cli
All the above methods take care of the dependencies automatically.
Installing from source
If your distribution is not listed above or if you prefer to manually compile from source, try this method.
First of all, lets install the dependencies.
On Ubuntu and Debian use:
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev
On Gentoo use:
sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua
On Fedora use:
sudo yum install lua-devel openssl-devel libconfig-devel readline-devel
On Arch Linux use:
pacman -S libconfig lua
On FreeBSD use:
pkg install libconfig libexecinfo lua52
On OpenBSD use:
pkg_add libconfig libexecinfo lua
After that we need to clone the Telegram CLI GitHub repository. Make sure git is installed. Then type the following:
git clone https://github.com/vysheng/tg.git && cd tg
Alternatively you can download and extract the zip:
wget https://github.com/vysheng/tg/archive/master.zip -O tg-master.zip
Then, we need to run the compile process:
Telegram CLI will be compiled in current directory itself.
brew install libconfig
brew install readline
brew install lua
export CFLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/6.2.4/include"
export LDFLAGS="-L/usr/local/lib -L/usr/local/Cellar/readline/6.2.4/lib"
./configure && make
Then install these ports:
After that, compile Telegram CLI this way:
env CC=clang CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib LUA=/usr/local/bin/lua52 LUA_INCLUDE=-I/usr/local/include/lua52 LUA_LIB=-llua-5.2
Telegram CLI will be compiled in current directory itself.
Now, lets try using it.
Running the application
If you installed Telegram CLI from your distribution’s repositories, launch the application by:
telegram -k /etc/telegram/tg.pub
Otherwise, if you compiled from source, run it from its directory with:
./telegram -k tg-server.pub
It will ask for your phone number. Type in the number and press ENTER. After that, a code will be generated which will be sent to your phone via SMS or chat. Type that code into the terminal when it asks for it.
The application supports TAB completion and command history.
Also, the official documentation states the definition of ‘peers’ :
“Peer refers to the name of the contact or dialog and can be accessed by TAB completion. For user contacts peer name is Name Lastname with all spaces changed to underscores. For chats it is it’s title with all spaces changed to underscores For encrypted chats it is Name Lastname with all spaces changed to underscores.
If two or more peers have same name, number is appended to the name. (for example A_B, A_B#1, A_B#2 and so on)”
The supported commands are (from ‘help’ command):
- 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> – mark read all received messages with peer
- send_photo <peer> <photo-file-name> – sends photo to peer
- send_video <peer> <video-file-name> – sends video to peer
- send_text <peer> <text-file-name> – sends text file as plain messages
- load_photo/load_video/load_video_thumb <msg-seqno> – loads photo/video to download dir
- view_photo/view_video/view_video_thumb <msg-seqno> – loads photo/video to download dir and starts system default viewer
Group chat options
- chat_info <chat> – prints info about chat
- chat_add_user <chat> <user> – add user to chat
- chat_del_user <chat> <user> – remove user from chat
- rename_chat <chat> <new-name>
- create_group_chat <user> <chat topic> – creates a groupchat with user, use chat_add_user to add more users
- search <peer> pattern – searches pattern in messages with peer
- global_search pattern – searches pattern in all messages
- create_secret_chat <user> – creates secret chat with this user
- visualize_key <secret_chat> – prints visualization of encryption key. You should compare it to your partner’s one
Stats and various info
- user_info <user> – prints info about user
- history <peer> [limit] – prints history (and marks it as read). Default limit = 40
- dialog_list – prints info about your dialogs
- contact_list – prints info about users in your contact list
- suggested_contacts – print info about contacts, you have max common friends
- stats – just for debugging
- show_license – prints contents of GPLv2
- help – prints this help
Telegram CLI is pretty full-featured even though it is marked as ‘beta’. It does everything what the official mobile client does. Multimedia sending and secret chats work as expected. Chatting with buddies makes one nostalgic of the good ol’ CLI (read DOS) days.
The client is a bit too verbose with status messages while chatting, which I think could have been reduced to a certain extent, which in turn, will make the output look a lot cleaner.
Nevertheless, it works perfectly and I do not have any more complaints.
Telegram CLI is a pretty handy tool if you are use the terminal a lot and too often. It frees you from having to move the mouse to switch windows or lifting your phone from your pocket to reply to your friends in the midst of work. Combined with the GNU screen utility, you’ll have the ability to chat with your friends and develop/administer at the same time. Such is the convenience of having an open mobile messenger platform that WhatsApp, Hike, WeChat, Line, etc. cannot offer.
If setting up a CLI client is too hard for you, you can give Webogram a try. It works right inside a browser and is also available as a Chrome app. However, it lacks support for secret chats and many other features.
I hope that this guide has helped you. If you have anything to suggest, feel free to leave a comment.
Don’t have the requirements to try out this guide? You can use a really cheap Linux/Unix virtual machine on the DigitalOcean cloud to try Telegram CLI out.
Thank you for reading this article. Make a great day!