Create and schedule personalized affirmations to be delivered as notifications directly to your smartwatch using this Telegram bot.
-
Create a Bot:
- Open Telegram and search for
BotFather. - Start a chat with BotFather and use the
/newbotcommand. - Provide a name and username for your bot. The username must end with "bot" (e.g.,
MyCustomBot). - BotFather will provide you with a bot token (e.g.,
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11).
- Open Telegram and search for
-
Save the Bot Token:
- Store the token securely. It will be used to send messages via the Telegram Bot API.
- Find Your User ID:
- Use the bot @userinfobot.
- Start a chat with this bot, and it will display your Telegram user ID.
-
Open the bot script file (
my_bot.py). -
Locate the following lines in the code:
BOT_TOKEN = "your_bot_token_here" CHAT_ID = "your_user_id_here"
-
Replace
your_bot_token_herewith the bot token you received from BotFather. -
Replace
your_user_id_herewith the Telegram user ID you received from @userinfobot.
This bot supports time zone localization for scheduling affirmations. The default time zone is set to Asia/Kolkata. If you need a different time zone:
- Locate the following line in the bot code:
TIMEZONE = pytz.timezone("Asia/Kolkata")
- Replace
"Asia/Kolkata"with your desired time zone. - A list of supported time zones can be found in the Python
pytzdocumentation.
Run the following commands to install the necessary Python packages (with break-system-packages to avoid permission issues):
pip install python-telegram-bot --break-system-packages
pip install "python-telegram-bot[job-queue]" --break-system-packagesThe author ran this bot on an AWS EC2 Ubuntu instance (Free Tier). AWS Free Tier provides a way to explore cloud computing for free.
-
Why AWS Free Tier?
AWS Free Tier includes 750 hours of t2.micro instances per month for 12 months, sufficient for small projects like this bot. -
Set Up Your EC2 Instance:
- Search for easy walkthroughs on platforms like AWS Documentation, YouTube, or Medium using keywords like:
- "Set up AWS Free Tier account"
- "Launch Ubuntu EC2 instance on AWS Free Tier"
- Search for easy walkthroughs on platforms like AWS Documentation, YouTube, or Medium using keywords like:
-
Update and Upgrade Your Machine:
After launching your EC2 instance, always run:sudo apt update && sudo apt upgrade -yThis ensures the machine has the latest software and prevents unexpected errors.
- Install
tmux:sudo apt install tmux
- Start a new tmux session:
tmux new -s affirmation_bot
- Run the bot script inside the tmux session:
python3 my_bot.py
- Detach from the session:
This keeps the bot running even if you close the terminal.
Ctrl+b, then press d
- Start the Bot: Use the
/startcommand to initialize the bot. - Add an Affirmation: Use the
/add <HH:MM> <message>command to schedule an affirmation (e.g.,/add 08:00 You are amazing!). The time is to be entered in 24 hour format. - List Affirmations: Use the
/listcommand to see all scheduled affirmations. - Remove an Affirmation: Use the
/remove <ID>command to delete an affirmation by its ID.
Note: The code was written with the assistance of ChatGPT and required nearly 30 iterations to achieve the desired functionality.
Timing Behavior: Please note that the affirmation appears exactly one minute later than the defined time. This behavior is intentional based on how the bot’s job queue scheduling is set up, and it should not be considered an error.
To receive the affirmation notifications on your smartwatch, please ensure the following:
- Active Internet and Bluetooth: Keep your smartphone's internet connection and Bluetooth enabled.
- Smartwatch Pairing: Ensure that your smartwatch is properly paired with your smartphone.
- Telegram Notifications: To ensure that only affirmation notifications are received, I recommend muting all other Telegram groups and chats, leaving only the bot unmuted. This strategy helps in avoiding interruptions and ensures that you get the affirmations as intended.