Page 1 of 1

Python-Telegram-Bot

Posted: Sunday 22 October 2017 19:08
by emme
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 :P

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 :P :P)

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()
       
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!

Re: Python-Telegram-Bot

Posted: Friday 19 October 2018 22:05
by papoo
do you use other scripts that can help us get started?