-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
36 lines (25 loc) · 912 Bytes
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import io
import picamera as pc
from dotenv import load_dotenv, find_dotenv
from telegram.ext import Updater
from telegram.ext import CommandHandler
load_dotenv(find_dotenv())
camera = pc.PiCamera()
token = os.environ.get('BOT_ACCESS_TOKEN')
print(token)
updater = Updater(token=token)
dispatcher = updater.dispatcher
def start(bot, update):
bot.send_message(chat_id=update.message.chat_id, text="Welcome to Kiltiskahvi bot. ")
def send_pic(bot, update):
stream = io.BytesIO()
stream.name = 'image.jpg'
camera.capture(stream, 'jpeg') #todo: put this as file like object instead of writing
stream.seek(0)
bot.send_photo(chat_id=update.message.chat_id, photo=stream)
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
send_pic_handler = CommandHandler('pic', send_pic)
dispatcher.add_handler(send_pic_handler)
updater.start_polling()