[Python] Get telegram's chat's history

Discussão em 'Python' iniciado por Stack, Julho 27, 2025.

  1. Stack

    Stack Membro Participativo

    I want to get some previoius messages from chat with Python telegram bot's library.

    Here is my bot's handler:

    class BotController:
    def __init__(self) -> None:
    self.token = os.getenv("TELEGRAM_BOT_TOKEN")
    self.application = ApplicationBuilder().token(self.token).connection_pool_size(20).build()

    def launch(self) -> None:
    self.add_handlers()
    self.application.run_polling()
    logger.info("BOT LAUNCHED")

    def add_handlers(self):
    self.application.add_handler(MessageHandler(filters=filters.TEXT, callback=menu_callback))


    Menu callback:

    ...
    async def menu_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
    client = await get_client(update)
    logger.error(client.stage)

    match client.stage:
    case Stage.some_stage:
    logger.error(update.message.text)
    logger.error(update.message)
    updates = await update._bot.get_updates()

    for update in updates:
    logger.error(update)
    logger.error(update.message)
    last_update_id = update.update_id
    ...


    But here I got


    telegram.error.TimedOut: All connections in the connection pool are occupied. Request was not sent to Telegram. Consider adjusting the connection pool size or the pool timeout.
    ​

    How can I get chat history? Is it possible?

    Continue reading...

Compartilhe esta Página