This telegram bot allows you to wake up any computer on your network by sending a magic packet. Simply setup this bot on a raspberry pi (or any SBC) and add your Telegram user id to the whitelist.
custom_filters.py
from pyrogram import filters
whitelist_user_ids = [] # Put whitelisted user ids here
def f_func(__, _, msg):
if msg.from_user.id in whitelist_user_ids:
return True
else:
return False
whitelist_filter = filters.create(f_func)
...
...
Only whitelisted users will be allowed to wake up computers on your network. To get your telegram user id you can use GetMyID bot on Telegram.
Get your API hash and ID from Telegram.
Login and create an application to get the API hash and ID.
Get your bot token by creating a bot on BotFather.
The following commands should work for debian based systems.
Python 3 should be installed on your system.
sudo apt-get install python3-pip python3-venv git
python3 -m venv venv
source venv/bin/activate
git clone https://github.com/c0dn/telegram_wakeonlan_bot.git
cd telegram_wakeonlan_bot
pip install -r requirements.txt
Ensure your virtual env is active.
source venv/bin/activate
Set the required enviroment variables.
export API_HASH=<your api hash>
export API_ID=<your api id>
export BOT_TOKEN=<your bot token>
Run the bot.
cd telegram_wakeonlan_bot
python3 main.py
The bot will quit after printing a session string. Save this string, you will need it to setup the bot.
Create a systemd service file. (example is provided below)
sudo vi /etc/systemd/system/wol_bot.service
Creating the overide folder and conf. (example is provided below)
sudo mkdir /etc/systemd/system/wol_bot.service.d
sudo vi /etc/systemd/system/wol_bot.service.d/override.conf
sudo systemctl daemon-reload
sudo systemctl start wol_bot
sudo systemctl enable wol_bot
[Unit]
Description=Telegram WOL bot
After=multi-user.target
[Service]
Type=simple
ExecStart=/home/pi/venv/bin/python3 /home/pi/telegram_wakeonlan_bot/main.py
[Install]
WantedBy=multi-user.target
[Service]
Environment="API_HASH=<YOUR_API_HASH>"
Environment="API_ID=<YOUR_API_ID>"
Environment="SESSION_STR=<YOUR_SESSION_STR>"