Install Telegram-CLI (OSX)

There exists a nice command line interface for the quite famous WhatsApp Alternative named Telegram. Here is a short blog entry describing how to install and use it.

Requirements

  • homebrew
  • git
  • Xcode

Install

Just run the following lines of code in a terminal. This will download all files, compile them and install it.

cd ~/Downloads
git clone --recursive https://github.com/vysheng/tg.git
cd tg
brew install libconfig readline lua python libevent jansson openssl
brew link --force openssl
brew link --force readline
export CFLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/6.3.8/include"
export LDFLAGS="-L/usr/local/lib -L/usr/local/Cellar/readline/6.3.8/lib"
./configure && make

Now you can call your binary like this bin/telegram-cli.

If you want to use it globally:

cd ~/Downloads
mkdir ~/.telegram-cli
mv tg/* ~/.telegram-cli
rm -rf tg

... and now add export PATH=$PATH:~/.telegram-cli/bin to your ~/.bash_rc or ~/.profile and source it. I am a happy zsh user, so I will append it to my ~/.zprofile:

echo -e "export PATH=$PATH:~/.telegram-cli/bin\nalias telegram=\"telegram-cli -k ~/.telegram-cli/server.pub\"\n" >> ~/.zprofile
source ~/.zprofile

Example

I had to extract the last registration code:

echo -e "search Telegram code\nsearch Telegram code\n" | telegram | egrep "Your login code: ([0-9]*)" | tail -n 1 | cut -c69-

Links