import logging import picamera import time from telegram import ForceReply, Update from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters import secrets logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO ) logging.getLogger('httpx').setLevel(logging.WARNING) logger = logging.getLogger(__name__) async def start(update, context): user = update.effective_user await update.message.reply_html( rf'Hi {user.mention_html()}!', reply_markup=ForceReply(selective=True), ) async def campcam(update, context): print('Got campcam command') with picamera.PiCamera() as camera: camera.resolution = (2592, 1944) camera.start_preview() time.sleep(5) filename = 'data/' + str(int(time.time())) + '.jpg' camera.capture(filename) print('Saved file to', filename) await update.message.reply_photo(photo=open(filename, 'rb'), connect_timeout=300, write_timeout=300, read_timeout=300) print('Sent to chat') def main(): application = Application.builder().token(secrets.API_TOKEN).build() application.add_handler(CommandHandler('start', start)) application.add_handler(CommandHandler('campcam', campcam)) application.run_polling(allowed_updates=Update.ALL_TYPES) if __name__ == '__main__': main()