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
- 🔌 Reboot Raspberry Pi remotely
- Raspberry Pi with Pi-hole installed
- Telegram account
- Node.js and npm installed on your Raspberry Pi - Installation instructions here
-
Clone this repository to your Raspberry Pi:
git clone https://github.com/AdrianoCng/pihole-telegram-bot.git cd pihole-telegram-bot -
Install dependencies on your Raspberry Pi:
npm install
-
Create a Telegram bot:
- Open Telegram and search for @BotFather
- Send
/newbotand 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
.envfile 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_hereExample:
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.jsOr using npm:
npm start-
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
Or using npm:
npm run start:prod
-
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:
/authorizeor/a- Authorize the bot/logoutor/logoff- Logout the bot/messagesor/m- Show messages from Pi-hole/statusor/s- Display the running status of Pi-hole subsystems/enableor/e- Enable Pi-hole subsystems/disableor/d- Disable Pi-hole subsystems/versionor/v- Show installed version of Pi-hole, Web Interface & FTL/updateor/up- Update Pi-hole subsystems/upgravityor/g- Update the list of ad-serving domains/upgradeor/upg- Upgrade host system/rebootor/r- Reboot the Raspberry Pi/botor/bv- Show the version of the bot/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