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!

EasyFull instructions provided1 hour21,664
Telegram Bot With Raspberry Pi

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

Conncection between pi and LED

Simpl iza7zc8bch

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

10 projects • 213 followers
Maker | Hardware Hacker | Electronics Enthusiast
Contact

Comments