This script allows a bot to send a message to a Telegram channel without storing the IDs of all users.
This Python script utilizes the aiogram and apscheduler libraries to send scheduled messages to a Telegram channel based on the day of the week. It can be used to send daily reminders or periodic messages to a specific Telegram channel.
Before running the script, make sure to install the following dependencies:
pip install aiogram==3.17 apscheduler pytz- Telegram Bot Token: Replace ID Bot Telegram with the token of your Telegram bot. You can obtain a token by registering a new bot on BotFather .
bot = Bot(token='ID Bot Telegram')- Telegram Channel ID: Replace @ID Canale with the ID of your Telegram channel, where you want to send the messages.
channel_id = "@Channel ID"- Daily Messages: Modify the messages dictionary to customize the messages that will be sent each day of the week.
messages = {
"Monday": "Today is Monday",
"Tuesday": "Today is Tuesday",
"Wednesday": "Today is Wednesday",
"Thursday": "Today is Thursday",
"Friday": "Today is Friday",
"Saturday": "Today is Saturday",
"Sunday": "Today is Sunday",
}- Sending Time: Configure the time when you want to send the messages by modifying the scheduler.add_job function. In the example, messages are sent every day at 19:00 (UTC).
scheduler.add_job(lambda: asyncio.run(send_scheduled_message()), 'cron', day_of_week='mon-sun', hour=19, minute=0)Run the Python script, and the bot will automatically start sending scheduled messages to your Telegram channel.
python bot.py