Salman Faris
Published © GPL3+

Telegram Bot With Raspberry Pi

Host a Telegram Bot on your Raspberry Pi and chat with your brand new IoT device!

BeginnerFull instructions provided1 hour69,213
Telegram Bot With Raspberry Pi

Things used in this project

Story

Read more

Schematics

Conncection between pi and LED

Code

telegrambot.py

Python
#coder :- Salman Faris

import sys
import time
import random
import datetime
import telepot
import RPi.GPIO as GPIO

#LED
def on(pin):
        GPIO.output(pin,GPIO.HIGH)
        return
def off(pin):
        GPIO.output(pin,GPIO.LOW)
        return
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(11, 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(11))
    elif command =='off':
       bot.sendMessage(chat_id, off(11))

bot = telepot.Bot('Bot Token')
bot.message_loop(handle)
print 'I am listening...'

while 1:
     time.sleep(10)

Credits

Salman Faris

Salman Faris

26 projects • 409 followers
Maker | Hardware Hacker | Electronics Enthusiast

Comments