Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Telegram bot takes a photo using a pi camera and replies back running on Raspberry Pi
import sys
import asyncio
import telepot
from telepot.aio.delegate import per_chat_id, create_open
import picam
$ python3.5 <token>
Counts number of messages a user has sent. Starts over if silent for 10 seconds.
Illustrates the basic usage of `DelegateBot` and `ChatHandler`.
class MessageCounter(telepot.aio.helper.ChatHandler):
def __init__(self, seed_tuple, timeout):
super(MessageCounter, self).__init__(seed_tuple, timeout)
async def on_chat_message(self, msg):
content_type, chat_type, chat_id = telepot.glance(msg)
await bot.sendChatAction(chat_id, 'upload_photo')
temp_pic = picam.make_temp_image()
result = await bot.sendPhoto(chat_id, open(temp_pic, 'rb'))
#file_id = result['photo'][0]['file_id']
#await self.sender.sendMessage(self._count)
TOKEN = sys.argv[1] # get token from command-line
bot = telepot.aio.DelegatorBot(TOKEN, [
(per_chat_id(), create_open(MessageCounter, timeout=10)),
loop = asyncio.get_event_loop()
print('Listening ...')
import time
import picamera
import datetime
import os
def make_temp_image():
cur_time =
with picamera.PiCamera() as camera:
camera.resolution = (800, 600)
camera.rotation = 180
# Camera warm-up time
photo_path = 'data/{}.jpg'.format(str(cur_time))
return photo_path
def delete_file(path):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.