TelePi – Control your pi with Telegram Bot


As a Developer and IT guy I always looking for new things to do. Trying to find new ways of doing thing, whilie doing this i came across this thing called “Telebot” which is a Python based Telegram bot. this project allows me to control my Raspberry pi from anywhare and in any time using simple Commands. in this article i’ll will show how easy it is to set it up.

Step 1 – install telegram on your phone

Telegram App
Go to App Store (iPhone) or Play Store (Android), download and install Telegram on your phone.
If you already have an account log in, if not create new account.
now you can use Telegram on your phone but not yet on your Pi.

Setp 2 – Creating new bot

Open Telegram on your phone, search for a user called BotFather. As the name implies, he is the Father of All Bots.

Click the “START” button and follow the instructions.
first you will see a list of all the command needed to communicate with BotFather.

BotFather Command list

Now, click on the “/newbot” link on the top of the list to create the new bot. now you will be asked to give your bot a name:

Name your bot


on the next step you will be asked to choose a Username for youe newly created bot. the username must be ended with “bot”, like “TetrisBot” or “tetrisbot”.

Set the bot UserName

The new bot will now be created and in the Success message @Botfather will create an API Access Token. wirte it down, we will need it for the next step.

Bot Access Token


Step 3 – Install, Configure and test Telebot on Your pi

In this step we will install “Telepot” which is Python based Telegram bot Library. In order to do this connect to your Raspberry pi and type in the following commands:

Now we will test Telepot in order to ensure everything is working as expected befor we continue with the setup process. to do so, type in the following commands:
first type “python” to enter the Python interpreter, and then type in these three lines. (as you can see in the screenshot)

import telepot
bot = telepot.Bot(‘*** enter the token from step 2 ***’)

f the last command, getMe(), returns a dictionary describing the bot account (as in the screenshot), all is good. Type exit() to leave the Python interpreter.

Step 4 – Create bot commands script

In this step we will create a Python script the will use to communicate with the raspberry pi. this script will include all the command the we want the pi to execute.

On the pi command line, type the following commands:

then paste in the following text:

now type Ctrl+x and then y and Enter to save and close the file.

Step 5 – startup script

So now, the only thing we got left to do is to create a service that loads telepi at system start up.

in order to do this, run the following command from in the terminal:

and then paste the following code:

now run the following commands to enable and run the service:

Be the first to comment

Leave a Reply

Your email address will not be published.