The Acme Systems shipping office will be closed for holidays from 14 august to 22 august

Create a Telegram Bot with Arietta G25

# apt-get update
# apt-get install python-pip
# pip install python-telegram-bot

Examples

Hello World !

from telegram.ext import Updater, CommandHandler

def start(bot, update):
    update.message.reply_text("Hello World ! I'm a Bot\n")

updater = Updater('insert-your-token-here')

updater.dispatcher.add_handler(CommandHandler('start', start))

updater.start_polling()
updater.idle()

Hello World with active led

This is the same Hello World example but using the on board Arietta led to show the command acknoledge. It uses the acmepins library no manage the on board red led.

from telegram.ext import Updater, CommandHandler
from acmepins import ARIETTA_LED

arietta_led=ARIETTA_LED()

def start(bot, update):
    arietta_led.on()
    update.message.reply_text("Hello World !\n I'm a Bot\n")
    arietta_led.off()

updater = Updater('insert-your-token-here')

updater.dispatcher.add_handler(CommandHandler('start', start))

updater.start_polling()
updater.idle()

Send an alert message

from telegram.ext import Updater, CommandHandler
from acmepins import ARIETTA_LED,GPIO

job_queue=None
chat_ids=[]

def button_handler():
    global job_queue
    global jchat_ids
     
    if len(chat_ids)>=0:
        for chat_id in chat_ids:
            job_queue.bot.sendMessage(chat_id, "Button pressed")

def cmd_start(bot, update):
    global chat_ids
    update.message.reply_text('Command list:\n/start, /stop')
    chat_ids+=[update.message.chat_id]
    
def cmd_stop(bot, update):  
    global chat_ids

    try:
        chat_ids.remove(update.message.chat_id) 
        return
    except ValueError:
        pass

updater = Updater('insert-your-token-here')
job_queue = updater.job_queue

updater.dispatcher.add_handler(CommandHandler('start', cmd_start))
updater.dispatcher.add_handler(CommandHandler('stop', cmd_stop))

button=GPIO('PC17','INPUT')
button.set_edge('falling',button_handler)

updater.start_polling()
updater.idle()

Send a photo

from telegram.ext import Updater, CommandHandler

def start(bot, update):
    update.message.reply_text(" \
        Help:\n \
        /start\n \
        /photo\n \
    ")

def photo(bot, update):
    update.message.reply_text('This is me...')
    bot.sendPhoto(update.message.chat_id, photo=open('me.jpg'))

updater = Updater('insert-your-token-here')

updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CommandHandler('photo', photo))

updater.start_polling()
updater.idle()

Related Links

Buy