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())