Creating an automated Telegram bot for daily group messages - hosting requirements

I’m just starting with Python and bot development. I want to build a basic Telegram bot that automatically posts messages to a group chat every day at midnight.

Here’s my current working code:

def daily_post():
    API_TOKEN = '1234567890:ABCDEFghijklmnopQRSTuvwxyz123456789'  # Example token
    CHAT_GROUP_ID = "-1001234567890"  # Example group ID
    message_content = "Daily reminder message"
    
    api_url = f"https://api.telegram.org/bot{API_TOKEN}/sendMessage?chat_id={CHAT_GROUP_ID}&text={message_content}"
    response = requests.get(api_url)
    print(response.json())

The function works great when I test it manually. For scheduling, I’m thinking about using:

import schedule
schedule.every().day.at("00:01").do(daily_post)

My main question is about hosting requirements. If my laptop shuts down or goes to sleep, will the scheduled messages still get sent? Do I need to keep my computer running 24/7, or can Telegram bots work independently once deployed? Should I look into cloud hosting or a Raspberry Pi for this kind of automation?

yep, u need ur laptop on for scheduled stuff. if it sleeps or powers off, it won’t work. a cheap VPS like DigitalOcean or Vultr is a good idea, just like $5/month. way easier than keeping ur comp running all the time.

Yeah, you need always-on hosting since your script dies when your laptop sleeps. I learned this the hard way when I started with Telegram bots - missed tons of scheduled messages. Cloud hosting is your best bet. I’ve used Heroku for two years and it handles my daily bot tasks perfectly, though they killed the free tier recently. Google Cloud Platform works too and gives new users free credits. Once you move to cloud hosting, ditch the schedule library for a proper cron job - way more reliable in production. Setup looks scary at first, but once it’s running you don’t have to worry about your laptop killing your bot.

Your bot needs to run continuously to function as intended. The schedule library operates only while your Python script is active; if you shut it down, the automation ceases. I recommend utilizing cloud hosting. For instance, I’ve successfully used AWS EC2’s free tier for running similar bots without issues for several months. Alternatively, GitHub Actions offers a free option with scheduled workflows that can trigger your bot on a daily basis, though keep in mind that the free tier has its limitations if you plan to scale later. A Raspberry Pi could also be a viable option if you prefer local control, but ensure you have stable internet and a power backup.