INNER CODE UNIT · Python

telegram_executor

thevickypedia/Jarvis · jarvis/api/background_task/bot.py:76

async def telegram_executor() -> None:
    """Poll for new Telegram messages.

    Handles:
        - BotWebhookConflict: Handles dead webhook connection and restarts loop.
        - BotInUse: Conflicting bot usage on webhook vs long polling.
        - BotTokenInvalid: Handles invalid auth token by terminating session.
        - EgressErrors: Dynamically handles failed connections.
        - Exception: Broad exception handler to terminate loop for unknown errors.
    """
    try:
        offset = bot.poll_for_messages(telegram_beat.offset)
        if offset is not None:
            telegram_beat.offset = offset
    except BotWebhookConflict as error:
        # At this point, its be safe to remove the dead webhook
        logger.error(error)
        webhook.delete_webhook(base_url=bot.BASE_URL, logger=logger)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…