Install and Configure the Telegram client on a Raspberry Pi
Today we will discuss how to install the Telegram command line client on a Raspberry Pi. While we will mainly focus on the Debian based Raspbian distribution, since we will build the client from source this procedure can be used on many other Linux distributions.
To start off with we need to install various development library packages, to do so run the following command:
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev libgcrypt11-dev make
Note: You can adapt this command as needed for your Linux distribution.
Once those packages have installed we need to get the source code from GitHub with the following command. Note this will create a subdirectory named "tg" and put the source code below that:
git clone --recursive https://github.com/vysheng/tg.git
Note: If you don't have git installed already run: apt-get install git
Once that completes, cd into the tg directory:
As of this writing there are issues with the latest versions of OpenSSL and this code. So we will make some tweaks to the code then in the next step we will disable openssl and use gcrypt.
Edit the file tgl/mtproto-utils.c with your favorite text editor (for example vi or nano): vi tgl/mtproto-utils.c
Find lines 101 (in the function BN2ull) and 115 (in the function ull2BN) that contain: assert (0);
Comment these lines out by adding // to the front of the lines.
Save the file and exit.
We will then configure the build. We will also disable openssl and use gcrypt with the following command:
Once the config script completes we will run the make command (this may take a while):
At this point the telegram client should have compiled and you can now run it.
You can launch the client with the following command: bin/telegram-cli -k tg-server.pub -W
The first time you run it it will use a lot of CPU for about 10 min or so. In the process it will ask you for your telegram account info. Once it get's done processing (10-15 min) then any successive launches will quickly execute the client.
You can see the readme here: https://github.com/vysheng/tg for more usage information.
Thank you and have fun!
The command line options for the telegram-cli are not well documented, so I'm including some info on the usage here:
--phone/-u specify username (would not be asked during authorization)
--rsa-key/-k specify location of public key (possible multiple entries)
--verbosity/-v increase verbosity (0-ERROR 1-WARNIN 2-NOTICE 3+-DEBUG-levels)
--enable-msg-id/-N message num mode
--config/-c config file name
--profile/-p use specified profile
--log-level/-l log level
--sync-from-start/-f during authorization fetch all messages since registration
--disable-auto-accept/-E disable auto accept of encrypted chats
--lua-script/-s lua script file
--wait-dialog-list/-W send dialog_list query and wait for answer before reading input
--disable-colors/-C disable color output
--disable-readline/-R disable readline
--alert/-A enable bell notifications
--daemonize/-d daemon mode
--logname/-L <log-name> log file name
--username/-U <user-name> change uid after start
--groupname/-G <group-name> change gid after start
--disable-output/-D disable output
--tcp-port/-P <port> port to listen for input commands
--udp-socket/-S <socket-name> unix socket to create
--exec/-e <commands> make commands end exit
--disable-names/-I use user and chat IDs in updates instead of names
--enable-ipv6/-6 use ipv6 (may be unstable)
--help/-h prints this help
--accept-any-tcp accepts tcp connections from any src (only loopback by default)
--disable-link-preview disables server-side previews to links
--bot/-b bot mode
--json prints answers and values in json format
--permanent-msg-ids use permanent msg ids
--permanent-peer-ids use permanent peer ids
I've found that I generally have to use the -W option for the client to work as expected when running interactively, however I don't use -W for scripted procedures. Also the -e option is great of you want to have one line that launches the client and runs a command then exits. I use this for scripting. For example: <full path>/telegram-cli -k <full path to tg-server.pub> -e "msg Foo_Bar Hello World"
Note, the quotes are needed when using the -e option. This command will launch the client send the contact Foo Bar the message "Hello World" then exit the client.