Python-Telegram-Bot
Posted: Sunday 22 October 2017 19:08
Ciao,
in the process to continue the automation and integration of my home, @bigpea and myself jumped into the python-telegram-bot library for which I did not see any reference in the wiki.
I would like to share with you my experience about... in order to let you know there is a new simple way to interact with
let me tell you that I found this extreamely easy to use (I'm not a real programmer and I have low knowledge in python) and really fast!
you need to have a python script working as a service and you can interact with domoticz using the http json method (unless someone wouldn't like to create a pluging with it
)
for example, once you have created your bot in telegram, to get the camera snapshot in a faster way, here is the code:
now you can run it (don't forget to sudo chmod +x yourFileName.py), go into your telegram app and start a conversation with your bot..
issue a /cam and you'll get it!...
that's only an example but there are a lots of possibile integration!
I have a generic status report for my entire home, camera screenshor selection and a help screen... and more will come!
in the process to continue the automation and integration of my home, @bigpea and myself jumped into the python-telegram-bot library for which I did not see any reference in the wiki.
I would like to share with you my experience about... in order to let you know there is a new simple way to interact with

let me tell you that I found this extreamely easy to use (I'm not a real programmer and I have low knowledge in python) and really fast!
you need to have a python script working as a service and you can interact with domoticz using the http json method (unless someone wouldn't like to create a pluging with it


for example, once you have created your bot in telegram, to get the camera snapshot in a faster way, here is the code:
Code: Select all
import os
import telegram
import urllib.request
from telegram.ext import Updater, CommandHandler
APIKEY = 'put here your telegram BOT Token'
bot = telegram.Bot(token=APIKEY)
updater=Updater(token=APIKEY)
dispatcher = updater.dispatcher
def sendSnap(bot, update):
os.system('wget -O /home/pi/snap1.jpg http://127.0.0.1:8080/camsnapshot.jpg?idx=1')
bot.send_photo(chat_id=update.message.chat_id, photo=open('/home/pi/snap1.jpg', 'rb'), text="Ecco l'immagine che mi hai richiesto")
dispatcher.add_handler(CommandHandler('cam', sendSnap))
updater.start_polling()
updater.idle()
issue a /cam and you'll get it!...
that's only an example but there are a lots of possibile integration!
I have a generic status report for my entire home, camera screenshor selection and a help screen... and more will come!