-
Notifications
You must be signed in to change notification settings - Fork 0
Sending automatically messages #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements an automatic messaging system for a Telegram bot that sends personalized morning and evening messages to users based on their configured wake and sleep times.
- Adds scheduler functionality to send automated messages at user-defined times
- Implements job management for individual users when they update their wake/sleep times
- Creates message templates and delivery functions for morning and evening routines
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
telegram_bot_project/service/user.py | Adds method to retrieve all users with their wake/sleep times for scheduling |
telegram_bot_project/service/myday.py | Implements batch creation of daily stats for all users |
telegram_bot_project/messages.py | Adds message templates and functions for morning/evening automated messages |
telegram_bot_project/main.py | Integrates scheduler initialization and daily stats job setup |
telegram_bot_project/bot/scheduler.py | Core scheduler implementation for managing automated user messages |
telegram_bot_project/bot/handlers.py | Updates wake/sleep time handlers to register scheduler jobs |
telegram_bot_project/bot/commands.py | Minor import reorganization |
telegram_bot_project/main.py
Outdated
# Command Handlers | ||
@dp.message(Command("start")) | ||
async def start(message: Message): | ||
global USER_ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable USER_ID is declared but never defined or used in this function. This will cause a NameError if accessed elsewhere.
global USER_ID |
Copilot uses AI. Check for mistakes.
} | ||
|
||
# Buttons | ||
BUTTON_SETTINGS = "⚙️ Settings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BUTTON_SETTINGS variable is being redefined. The original definition on line 222 is being moved, but this creates inconsistency in the code structure. Consider maintaining the original order or using a single definition.
Copilot uses AI. Check for mistakes.
from apscheduler.triggers.cron import CronTrigger | ||
from messages import * | ||
|
||
from messages import send_morning_message, send_evening_message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is redundant since line 6 already imports everything from messages with 'from messages import *'. Remove this duplicate import.
from messages import send_morning_message, send_evening_message |
Copilot uses AI. Check for mistakes.
telegram_bot_project/main.py
Outdated
scheduler: AsyncIOScheduler = initialize_scheduler() | ||
scheduler.add_job( | ||
MyDayService.create_stats_for_all_users, | ||
'cron', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The string 'cron' should be passed as a keyword argument 'trigger' for better code readability and to match the explicit style used elsewhere in the codebase.
'cron', | |
trigger='cron', |
Copilot uses AI. Check for mistakes.
|
||
print(f"[INFO] - Sending morning routine to user with id, {user_id}") | ||
if not morning_routine: | ||
await bot.send_message( | ||
user_id, | ||
MESSAGES[language]['SEND_MORNING_MSG'].format("👤") + '\n' + MESSAGES[language]['NO_MORNING_ROUTINE'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded "👤" emoji should be replaced with a more meaningful placeholder or the actual username, as suggested by the message template parameter structure.
print(f"[INFO] - Sending morning routine to user with id, {user_id}") | |
if not morning_routine: | |
await bot.send_message( | |
user_id, | |
MESSAGES[language]['SEND_MORNING_MSG'].format("👤") + '\n' + MESSAGES[language]['NO_MORNING_ROUTINE'] | |
username = await UserService.get_username(user_id) or "Friend" | |
print(f"[INFO] - Sending morning routine to user with id, {user_id}") | |
if not morning_routine: | |
await bot.send_message( | |
user_id, | |
MESSAGES[language]['SEND_MORNING_MSG'].format(username) + '\n' + MESSAGES[language]['NO_MORNING_ROUTINE'] |
Copilot uses AI. Check for mistakes.
await bot.send_message( | ||
user_id, | ||
MESSAGES[language]['SEND_EVENING_MSG'].format("👤") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the morning message, the hardcoded "👤" emoji should be replaced with a more meaningful placeholder or the actual username.
await bot.send_message( | |
user_id, | |
MESSAGES[language]['SEND_EVENING_MSG'].format("👤") | |
username = await UserService.get_username(user_id) or "User" | |
await bot.send_message( | |
user_id, | |
MESSAGES[language]['SEND_EVENING_MSG'].format(username) |
Copilot uses AI. Check for mistakes.
No description provided.