Mobile instant messaging from the Pi

Lead Image © ELlena Kozlova,


What's cool about the Telegram messaging app is that – more than just a WhatsApp clone – you can use it to send and receive messages from your Raspberry Pi and even program it as an autoresponder.

The Telegram app [1] is taking the techie community by storm. Maybe not all your friends use it, but it has enough cool features to make it fascinating for people who like to tinker.

Apart from regular features, like chatting, groups, and being able to send pics and short video or audio files, Telegram boasts end-to-end encrypting (no more NSA spying on your chats), cloud-distributed servers (more reliable connections), secret chats, and auto-destructing messages (set a time limit, e.g., 1 minute, and the message disappears from your device and your friend's device).

As if that were not enough, Telegram is open source, uses an open protocol, and has a public API, which means that any developer can create new clients for different platforms. Although it's officially intended for iOS and Android, unofficial ports have been made to Windows Phone, Windows, the web, and the Raspberry Pi's Linux command line (Figure  1), which I will talk about in this article.

Figure 1: You can text from the Raspberry Pi directly to your friends' mobile phones.


If you have an Android handset or an iPhone, you can get Telegram from Google Play or the Apple App Store. If you haven't done so already, I would advise doing so and setting up an account from your phone before proceeding. To run Telegram from your Raspberry Pi, you are going to have to download the source code and compile it.

To do so, click the Download ZIP button on the right side of the web page [2], or you can clone the directory directly onto your Pi:

$ git clone

This will probably take a while.

Before you start the compile proper, you're going to need some packages to satisfy Telegram's dependencies:

$ sudo libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev

If you downloaded the ZIP, unzip it and enter the resulting directory:

$ unzip
$ cd tg-master

If, on the other hand, you decided to clone the directory from source, once it has finished downloading, you can enter the directory right away:

$ cd tg

Regardless of how you decided to get the source, the next step is configuring the makefile for the compile:

$ ./configure

Then, start the compile proper:

$ make

Once finished, you should have an executable program called telegram in the tg directory.


Before you start texting from the command line, you have to connect your Pi to your Telegram account and associate it with your mobile phone number. To do this, run Telegram with the -k option and point it to the public key in the tg directory:

$ ./telegram -k

The program then asks you for a code that is sent to your phone via SMS and which you receive in a few seconds after registering (Figure 2).

Figure 2: On your first start, you need to associate the CLI client with your account using a code Telegram sends you.

After entering the code, your connected contacts show up, as shown in Figure 3. You will also see a > at the bottom. This is the Telegram command-line prompt, and what you type shows up here.

Figure 3: Your connected contacts show up in red when you connect to your account.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Host a secret chat using Mesh

    With Mesh, an unlimited number of Scratch projects can interact by using variables and broadcasts over a local network. We show how to communicate across Mesh by building a multiuser chat program.

  • Waking the Raspberry Pi with a wireless command

    If you want to power your Pi solely with batteries, then it makes sense for the Pi to only be turned on when you need it. The Pi can boot when called remotely via radio signal sent over the European 868 MHz band.

  • Tracking airplanes in real time with ADS-B

    Airplanes continuously broadcast signals that identify the aircraft and its current flight path. With a moderately priced receiver and a Raspberry Pi, users can receive ADS-B transponder data in real time.

  • Working with the Raspberry Pi camera module

    The amazing Raspberry Pi camera module opens into a whole new world of useful projects. We'll show you how to use the Pi camera for time-lapse photography, and we'll even help you set up a motion-detecting surveillance camera.

  • DIY body cam with a Raspberry Pi

    Make your own body cam with a Raspberry Pi, a cannibalized webcam, a WiFi module, and some Python.