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, CallbackContext, Application 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.application = Application.builder().token(os.getenv("TELEGRAM_API_KEY")).build() bh = RafaelBookmarkPlugin() bh.register(self.application) jp = JournalPlugin() jp.register(self.application) #self.updater.dispatcher.add_handler(CommandHandler("journal", handle)) #self.updater.dispatcher.add_handler(MessageHandler(Filters.attachment, handle)) def run(self): self.application.run_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()