A Telegram bot to remotely control and monitor your Pi-hole setup from anywhere.
- ✨ Features
- 📋 Prerequisites
- 🛠️ Installation
- 🚀 Running the Bot
- 📱 Usage
- 🔐 Security
- 📄 License
- 🙏 Acknowledgements
- 🔐 User authentication
- 🚫 Enable/disable Pi-hole blocking
- 📊 Monitor Pi-hole status and view system messages
- 🔍 Check Pi-hole version information
- 🔄 Update Pi-hole subsystems and blocklists
- 🔒 Secure access limited to authorized users
- Raspberry Pi with Pi-hole installed
- Telegram account
- Node.js and npm installed on your Raspberry Pi
-
Clone this repository to your Raspberry Pi:
git clone https://github.com/AdrianoCng/pihole-telegram-bot.git cd pi-hole-telegram-bot
-
Install dependencies on your Raspberry Pi:
npm install
-
Create a Telegram bot:
- Open Telegram and search for @BotFather
- Send
/newbot
and follow the instructions - Copy the bot token provided by BotFather
-
Get your Telegram user ID:
- Search for @userinfobot on Telegram
- Start a conversation and it will display your ID
-
Create a
.env
file in the project directory on your Raspberry Pi with the following variables:BOT_TOKEN=your_telegram_bot_token_here PIHOLE_PASSWORD=your_pihole_admin_password_here PIHOLE_IP=your_pihole_ip_address_here ALLOWED_USER=your_telegram_user_id_here
Example:
BOT_TOKEN="1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" PIHOLE_PASSWORD="YourPiholePasswordHere" PIHOLE_IP="http://192.168.1.100" ALLOWED_USER="123456789"
NOTE: These commands must be run on your Raspberry Pi.
node index.js
-
Install PM2 globally on your Raspberry Pi:
npm install -g pm2
-
Start the bot with PM2 on your Raspberry Pi:
pm2 start index.js --name pi-hole-telegram-bot
-
Configure PM2 to start on boot (on your Raspberry Pi):
pm2 startup pm2 save
- Start a conversation with your bot on Telegram (from any device)
- Use the available commands to control your Pi-hole:
/authorize
or/a
- Authorize the bot/logout
or/logoff
- Logout the bot/messages
or/m
- Show messages from Pi-hole/status
or/s
- Display the running status of Pi-hole subsystems/enable
or/e
- Enable Pi-hole subsystems/disable
or/d
- Disable Pi-hole subsystems/version
or/v
- Show installed version of Pi-hole, Web Interface & FTL/update
or/up
- Update Pi-hole subsystems/upgravity
or/g
- Update the list of ad-serving domains/help
- Show available commands and descriptions
This bot restricts access to the authorized Telegram user ID specified in the .env
file.
Only user with ID listed in ALLOWED_USER
can interact with the bot.
MIT