from collections import defaultdict import dotenv import os import io import tempfile from datetime import datetime from flask import Flask from telegram import Update, PhotoSize, File, BotCommand from telegram.ext import Updater, MessageHandler, CommandHandler, Filters, CallbackContext, ConversationHandler app = Flask("rafael") RAFAEL_UA = "RAFAEL/0.1" from rafael.bookmarks import RafaelBookmarkPlugin from rafael.journal import JournalPlugin def handle(update: Update, context: CallbackContext): print("args:", context.args) print(f"Received a message: {update.message.text}") update.message.reply_text(f"You said: {update.message.text}") print(update.message.to_json()) if update.message.document is not None: print("Document", update.message.document.get_file()) elif update.message.effective_attachment: for att in update.message.effective_attachment: if isinstance(att, PhotoSize): print(att.get_file()) else: print("unknown attachment:", att) update.message.reply_text("done m8") class RafaelBot: def __init__(self): self.updater = Updater(os.getenv("TELEGRAM_API_KEY")) self.dispatcher = self.updater.dispatcher bh = RafaelBookmarkPlugin() bh.register(self.updater) jp = JournalPlugin() jp.register(self.updater) #self.updater.dispatcher.add_handler(CommandHandler("journal", handle)) #self.updater.dispatcher.add_handler(MessageHandler(Filters.attachment, handle)) def run(self): self.updater.start_polling() @app.route("/", methods=['GET']) def index(): return "hello" def main(): dotenv.load_dotenv() print("run bot") bot = RafaelBot() bot.run() print("bot run") # app.run() if __name__ == "__main__": main()