How can I ensure my Telegram bot remains active on Render?

I developed a Telegram bot with Python and deployed it on Render, utilizing Amazon S3 for data storage. Its functionality includes sending automated messages to numerous groups based on a schedule. However, I face a significant challenge: Render automatically puts the bot to sleep every 15 minutes. Consequently, it misses sending messages at predetermined times. To circumvent this, I have to manually interact with the bot about 10 minutes prior to each scheduled message to wake it up, which is unmanageable since I handle around 50 groups weekly with varying message timings.

Despite my efforts to tackle this issue through the following code, I have not achieved the desired outcome:

import asyncio
import aiohttp

async def initialize_webhook():
    # Your webhook initialization code here
    pass

async def keep_bot_active():
    while True:
        try:
            async with aiohttp.ClientSession() as session:
                async with session.get(f"{WEBHOOK_URL}/check") as response:
                    if response.status == 200:
                        print("Bot is active.")
                    else:
                        print(f"Unexpected response status: {response.status}")
        except Exception as error:
            print(f"Failed to maintain bot activity: {error}")

        await asyncio.sleep(600)

if __name__ == "__main__":
    asyncio.run(initialize_webhook())
    asyncio.run(keep_bot_active())

try looking into pinging ur bot regularly to keep it active. Some free services like uptime robot can ping ur URL every few mins to avoid it sleeping. This way, you won’t have to manually interact everytime. Hope it helps!

Ensuring your bot remains active on Render can also be addressed by considering the possibility of upgrading your plan or using a service designed to run uninterrupted. Render’s free tier often puts applications to sleep to conserve resources, which might not suit your needs. Another strategy you might employ is to implement a worker or scheduler within your code logic that periodically runs necessary checks or actions to keep the app active. Additionally, explore using external CRON jobs that invoke a lightweight function to keep things alive. Tailoring these approaches to suit your specific schedule can significantly reduce downtime.