How to create automated notification system for Telegram bot in channels and groups

I’m working on a Telegram bot that tracks sports events and stores them in a database. The bot can respond to commands like /upcoming, /list, and /schedule when users ask for information. Right now everything works fine when people manually use commands, but I want to add automatic notifications.

My main issues:

  1. Automatic messaging doesn’t work - I can’t get my notification function to send messages automatically to channels or private chats
  2. Commands in channels - Users can use commands in groups but not in channels
  3. Daily reminders - I want the bot to check every morning if there’s an event today and automatically post to the channel
import sqlite3
import asyncio
from datetime import datetime
from telegram import Update
from telegram.ext import Application, CommandHandler, CallbackContext

db_connection = sqlite3.connect('sports_events.db')
cursor = db_connection.cursor()

async def fetch_today_event():
    today = datetime.today().strftime("%Y-%m-%d")
    cursor.execute("SELECT * FROM events WHERE date = ?", (today,))
    result = cursor.fetchone()
    return result

async def fetch_upcoming_event():
    cursor.execute("SELECT * FROM events ORDER BY date")
    all_events = cursor.fetchall()
    current_date = datetime.today().strftime("%Y-%m-%d")
    
    for event in all_events:
        if event[2] >= current_date:
            return event
    return None

async def send_notification(update: Update, context: CallbackContext):
    event = await fetch_today_event()
    if event:
        notification_text = f"🔔 <b>EVENT TODAY!</b> 🔔\n\n"
        notification_text += f"📋 <b>{event[0]}\n⚽ {event[1]}\n📅 {event[2]}\n⏰ {event[3]}</b>"
        
        await context.bot.send_message(
            chat_id=update.effective_chat.id, 
            text=notification_text, 
            parse_mode="HTML"
        )
    else:
        no_event_msg = "<b>❌ NO EVENTS SCHEDULED TODAY ❌</b>"
        await context.bot.send_message(
            chat_id=update.effective_chat.id, 
            text=no_event_msg, 
            parse_mode="HTML"
        )

def setup_bot():
    application = Application.builder().token("YOUR_BOT_TOKEN").build()
    
    application.add_handler(CommandHandler("notify", send_notification))
    application.add_handler(CommandHandler("upcoming", fetch_upcoming_event))
    
    application.run_polling()

if __name__ == "__main__":
    setup_bot()

The bot works great for manual commands but I need help making it send automatic reminders to channels and groups. How can I implement scheduled messaging that runs independently of user commands?

you cant pass update to scheduled tasks - it wont work. for auto notifications, just use context.bot.send_message(chat_id, text) directly without the update object. i use python’s schedule library for daily reminders instead of apscheduler - way simpler. dont forget to get channel permissions first and store subscriber ids in a separate table when users join.

Your main issue is trying to use the Update object for automatic notifications. Scheduled messages don’t have an update context - they’re not user-triggered. Store chat IDs separately and use a proper scheduler instead. I ran into the same thing building a weather bot. APScheduler worked great for timing, plus I kept a subscriber database. When users first hit your bot, save their chat_id to your database. For auto notifications, call context.bot.send_message() directly with the stored chat_id - don’t go through an update handler. For channels, your bot needs admin rights and you’ll need the channel’s chat_id (starts with -100). Commands don’t work in channels by design - only groups and private chats. Get the channel ID by forwarding a message to @userinfobot. Ditch your current notification function for a standalone async function that pulls from your subscriber database and sends to each stored chat_id. Schedule it daily with APScheduler’s AsyncIOScheduler.

You’re mixing manual commands with automatic scheduling - that’s the issue. Your notification function expects an Update object, but scheduled tasks don’t have one. I ran into this same problem building a trading alerts bot. Separate your notification logic from command handlers completely. Build a standalone function that only uses the bot instance - no update context needed. For scheduling, use asyncio.create_task() with asyncio.sleep() in a loop, or just integrate APScheduler’s BackgroundScheduler. Channels vs groups - channels are broadcast-only, so commands don’t work there. Users can only interact with your bot in groups or DMs. To send automated messages to channels, you need the numeric channel ID (not username) and posting permissions. For the database part, add a subscriptions table to track which chats want notifications. Store each user’s chat_id when they first interact with your bot. Then your scheduled function loops through subscribers and sends messages without any user input.