Deploy telegram bot on webhooks
08:07 11 Aug 2023

I wrote a telegram bot on webhooks, used the aiogram library version 3.0.0rc2. While writing the bot, I used ngrok to create a base url and wrote an application on aiohttp.

async def on_startup(bot: Bot) -> None:
    await bot.set_webhook(f"{BASE_WEBHOOK_URL}{WEBHOOK_PATH}")


def main():
    bot = Bot(TOKEN, parse_mode='HTML')
    dp = Dispatcher()

    dp.startup.register(on_startup)

    app = web.Application()

    webhook_requests_handler = SimpleRequestHandler(
        dispatcher=dp,
        bot=bot
    )

    webhook_requests_handler.register(app, path=WEBHOOK_PATH)
    setup_application(app, dp, bot=bot)
    web.run_app(app, host=WEB_SERVER_HOST, port=WEB_SERVER_PORT)


if __name__ == "__main__":
    main()

Now I have a problem - I have no idea how to deploy all this, I wrote a tg bot before, but I used polling and hosted on Railway, now my subscription has ended there and I can't buy, although I sort of figured out this particular service. Apart from this, I have no experience. I've tried many different services, but I can't launch the bot in any way. Also I do not know which IP and Port I should use I tried Render but it doesn't support aioram 3 maybe I can manually upload aiogram there Render on python 3.7 i need python 3.11

python deployment hosting webhooks aiohttp