Telegram Bot - mako

Go to content
Raspberry > Projects

Telegram Bot

About Telegram
Telegram is a very popular instant messaging platform around the world. It is similar to Whatsapp or Facebook Messanger, but with many more functions. In addition to sending messages, images, audio and video files and creating groups, it is possible to create bots - automated programs that perform functions and tasks requested by users. Bots are really useful. There are many bots which can facilitate your life. TrakBot can trak your packages, ExchangeRates can canvert values, TempMail provides a temporary email, PollBot, WeatherInfo and many other. Tens or hundred apps concentrated in one.

But what are the applications of Telegram on Raspberry Pi? How can these platforms work together?
Let's start with a simple but really intresting project: turn on and off a LED using a Telegram bot. It sounds trivial, but it will be very useful for future applications in the Raspberry Pi world. Telegram is an easy and smart app and kowing how to combine it with your micro computer will give you a great start point.
How the project works? Sending a message to a Telegram bot on your smartphone will turn on and off a led connected to your Raspberry Pi.

First: create a bot. Open your Telegram app and search BotFather, it is a bot made to create other bots. Follow the instruction of BotFather, type "/newbot", give your new bot a name and a username. Once created BotFather will give you a token (API), don't lose it.

Instal packages
Now is need to install some packages, first of all a python package index.

sudo apt-get install python-pip

if this package is already installed on your Raspberry Pi, the terminal returns you this following lines:

Telepot is a framework written in Python. It helps to build applications on the Telegram Bot API. The framework is installed via the following command:

sudo pip install telepot

Repository git
You have to clone the git repository. Using the following command will created a locally copy:

git clone
Edit python sketch
In the first step you created a bot (with BotFather), and it gave you a token. Now you have to put this token in the github python sketch. Then, open the File Manager on your Raspberry Pi. You'll find a folder called "TelegramBot", inside it, a .py file called "".
Open the .py file with your python IDE (Thonny Python IDE in the image), and find the bot token line.
This is the line:

bot = telepot.Bot('BOT TOKEN')

now delete BOT TOKEN and replace it with the token of your bot, then click ond "save". The new command line should look like this:

bot = telepot.Bot('1603220979:AAE7O-ibv*************pCwzqqXqPKY0k')

Run the code
Almost done, go back to the terminal and run the code:


with this line the sketch in uploaded to your Raspberry Pi. The last step is to connect the LED to your Raspberry Pi.

There are no reviews yet.
Back to content