You are on page 1of 15

Set Up Telegram Bot on

Raspberry Pi
Er. Manoj S. Kavedia
www.kaizenfuturetech.com
www.kavediasir.yolasite.com
9324258878 / 8329988738
Raspberry Pi Pin Out
About Telegram Bot
• On 24 June, 2015, Telegram published the Bot
API, enabling machines to talk Telegram.

• From that day on, not only can human use


Telegram, so can machines.
Install Telegram on Cell Phone
Search for BotFather
Click on BotFather
To Start BotFather
Type /start in Message
Text /newbot to BotFather
Give Name and User Name
Obtain Access Token copy it or Mail it
Setup on RPi
Setup on Raspberry Pi
Install “Python Package Index and “Telepot” using
$ sudo apt-get install python-pip
$ sudo pip install telepot
Python Code
import sys
import time
import random
import datetime
import telepot
import RPi.GPIO as GPIO

chat_id=""
#LED

def on(pin):
GPIO.output(pin,GPIO.HIGH)
#bot.sendMessage (chat_id, "device On")
return

def off(pin):
GPIO.output(pin,GPIO.LOW)
#bot.sendMessage (chat_id, "device Off")
return
Python Code
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)

#Turn off the warning Messges


GPIO.setwarnings(False)

# set up GPIO output channel


GPIO.setup(3, GPIO.OUT)

def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']

print ('Got command: %s' % command)

if command == 'on':
bot.sendMessage(chat_id, on(3))

elif command =='off':


bot.sendMessage(chat_id, off(3))
Python Code
bot = telepot.Bot('Token U Recevied')
bot.message_loop(handle)
print ('I am listening...')

while 1:
time.sleep(10)
Run Child Bot and Give Command
Er. Manoj S. Kavedia

Contact on Watsapp to join Students Forum : 9324258878

You might also like