Telegram bot for MikroTik: WireGuard, WoL, device & resource monitoring (TR/EN)
1.9K
Manage your MikroTik router from Telegram โ WireGuard peers, Wake-on-LAN, live device & resource monitoring, firewall, all from your phone.
.conf and a scannable QR right in chat/diag, /find, /active, per-interface traffic, one-shot device health/lang| Need | How |
|---|---|
BOT_TOKEN | Telegram โ @BotFather โ /newbot (or /mybots โ API Token) |
ADMIN_ID | Telegram โ @userinfobot โ start โ copy your numeric Id |
docker run -d --name mt-bot --restart unless-stopped \
-e BOT_TOKEN="123456:AA..." \
-e ADMIN_ID="123456789" \
-e ROUTER_IP="192.168.88.1" \
-e ROUTER_USER="api-user" \
-e ROUTER_PASS="api-password" \
-e ROUTER_PORT="8728" \
-e TZ="Europe/Istanbul" \
-v mt-bot-data:/app/data \
enesilhaydin/mt-telegram-bot:latest
services:
mt-bot:
image: enesilhaydin/mt-telegram-bot:latest
restart: unless-stopped
environment:
BOT_TOKEN: "123456:AA..."
ADMIN_ID: "123456789"
ROUTER_IP: "192.168.88.1"
ROUTER_USER: "api-user"
ROUTER_PASS: "api-password"
ROUTER_PORT: "8728"
TZ: "Europe/Istanbul"
volumes:
- bot-data:/app/data
volumes:
bot-data:
See MikroTik Container Deploymentโ below โ the bot runs as a container on the router, reaching the API over the internal container network.
Then open Telegram and send /start.
| Command | Description |
|---|---|
/system | Router status (CPU, RAM, uptime, health, version) |
/health | Instant resource snapshot (CPU per-core, RAM, HDD, uptime) |
/profile | 2-second CPU profile โ which subsystem uses CPU |
/jobs | Currently running RouterOS script jobs |
/firewall | Firewall rules summary |
/dns | DNS info (servers, DoH, cache) |
/backup | Create router backup |
/run <api/path> | Run any RouterOS API command |
| Command | Description |
|---|---|
/wg_add <name> | Create a peer (auto keys/IP/endpoint) โ sends .conf + QR |
/wg_list | List all peers |
/wg_del [name] | Delete a peer (no arg โ buttons) |
/qr [name] | Resend config + QR for a peer (no arg โ buttons) |
/peers | Peer status (handshake, RX/TX, endpoint) |
| Command | Description |
|---|---|
/clients | DHCP clients (๐ static ยท โ trusted ยท ๐ซ blacklist ยท ๐ note) |
/static | DHCP static reservations only |
/active | Devices currently on the network (ARP + DHCP). /active scan runs an ARP scan to find devices with manual static IPs |
/find <q> | Search hostname/IP/MAC/comment |
/diag <ip|mac|name> | One-shot diagnosis: ping + ARP + lease + flags |
/forget <mac> | Clean device traces (DHCP lease + ARP + history) |
/traffic | Per-interface RX/TX |
/scan | Reset new-device alerts |
/notify [on|off] | Toggle new-device alerts |
/note <mac> <text> | Name/note a device (saved to bot DB and DHCP lease comment) |
/notes | List device notes |
| Command | Description |
|---|---|
/trust <mac> [name] | Mark trusted (suppress alerts) |
/untrust <mac> ยท /trust_list | Remove / list |
/blacklist <mac> [name] | Block: bridge filter drop + DHCP block |
/unblacklist <mac> ยท /blacklist_list | Unblock / list |
| Command | Description |
|---|---|
/wol [name] | Wake a device (no arg โ buttons). Pings first; skips if already on |
/wol_add <name> <mac> [interface] | Register a device (no arg โ lists interfaces) |
/wol_del <name> ยท /wol_list | Remove / list |
| Command | Description |
|---|---|
/lang | Switch language (Turkish / English) |
โ
Trust ยท ๐ซ Blacklist ยท โ๏ธ Name/Note buttons. The Name/Note button starts a reply flow and saves to the bot DB and the router's DHCP lease comment. Reported only once per MAC. Toggle with /notify off./tool profile) + running jobs, 10-minute cooldown, plus a recovery notice.| Variable | Required | Default | Description |
|---|---|---|---|
BOT_TOKEN | โ | โ | Telegram bot token (@BotFather) |
ADMIN_ID | โ | โ | Your Telegram user ID (@userinfobot) |
ROUTER_PASS | โ | โ | RouterOS API password |
ROUTER_IP | 172.17.0.1 | RouterOS API host | |
ROUTER_USER | admin | RouterOS API user (read,write,api) | |
ROUTER_PORT | 8728 | RouterOS API port | |
TZ | UTC | Timezone | |
WG_INTERFACE | wg1 | WireGuard interface name | |
WG_SUBNET | 192.168.2 | WireGuard subnet prefix | |
WG_DNS | auto | DNS pushed to WG clients (set to your LAN gateway) | |
WG_ENDPOINT | auto | WAN IP/host for WG endpoint | |
LAN_SUBNET | 192.168.1.0/24 | LAN subnet | |
MONITOR_INTERVAL | 60 | Device scan interval (s) | |
DB_PATH | /app/data/bot.db | SQLite path | |
CPU_THRESHOLD | 85 | CPU % alert threshold | |
RAM_FREE_MIN_MB | 50 | Free RAM (MB) alert floor | |
HDD_FREE_MIN_MB | 10 | Free disk (MB) alert floor | |
RESOURCE_INTERVAL | 60 | Resource sample interval (s) | |
RESOURCE_COOLDOWN | 600 | Min seconds between repeat alerts |
A RouterOS API user with only read,write,api (no shell/ssh) is recommended:
/user group add name=botapi policy=read,write,api,test
/user add name=api-user group=botapi password=strong-password
read,write,api# 1. Environment
/container envs add list=mt-bot key=BOT_TOKEN value="123456:AA..."
/container envs add list=mt-bot key=ADMIN_ID value="123456789"
/container envs add list=mt-bot key=ROUTER_IP value="172.17.0.1"
/container envs add list=mt-bot key=ROUTER_USER value="api-user"
/container envs add list=mt-bot key=ROUTER_PASS value="api-password"
/container envs add list=mt-bot key=ROUTER_PORT value="8728"
/container envs add list=mt-bot key=TZ value="Europe/Istanbul"
/container envs add list=mt-bot key=WG_DNS value="192.168.88.1" # your LAN gateway
# 2. Mounts: persistent DB + (optional) live-code mount โ see "Updating code"
/container mounts add name=mt-bot-data src=usb1/container/data/mt-bot dst=/app/data
/container mounts add name=mt-bot-code src=usb1/container/data/mt-bot-code dst=/app/app
# 3. Container (interface = your container veth)
/container add remote-image=enesilhaydin/mt-telegram-bot:latest \
interface=veth1 envlist=mt-bot mounts=mt-bot-data,mt-bot-code \
root-dir=usb1/container/mt-bot start-on-boot=yes \
hostname=mt-bot logging=yes dns=172.17.0.1
# 4. Allow API + internet for the container subnet
/ip service set api address+=172.17.0.0/24
/interface list add name=CONTAINER
/interface list member add list=CONTAINER interface=containers
/ip firewall filter add chain=input action=accept in-interface-list=CONTAINER protocol=udp dst-port=53 comment="IN: CONTAINER DNS"
/ip firewall filter add chain=input action=accept in-interface-list=CONTAINER protocol=tcp dst-port=8728 comment="IN: CONTAINER API"
/ip firewall filter add chain=input action=drop in-interface-list=CONTAINER comment="IN: CONTAINER drop rest"
/ip firewall filter add chain=forward action=accept src-address=172.17.0.0/24 out-interface-list=WAN comment="FWD: Container -> WAN"
# 5. Start
/container start [find name~"mt-telegram"]
Security: keep the container in its own
CONTAINERinterface list (not yourLANlist) so a compromised container can't reach every router service. Keep172.17.0.0/24in the API service's allowed addresses.
On low-power routers (dual-core ARM, USB storage), re-pulling and re-extracting
the full image on every code change is slow and can wedge the RouterOS container
daemon. Solution: the Python package (app/) is volume-mounted from USB into
/app/app, so the image only carries the runtime + dependencies (which rarely
change). Updating code = copy .py files to USB + restart the container (~10s).
No pull, no extract, no reboot.
mt-bot-data โ /app/data (SQLite, persists)mt-bot-code โ /app/app (Python code, overrides the image copy)Copy deploy.sh.example โ deploy.sh, fill in your credentials, then:
./deploy.sh
It uploads app/*.py over FTP (LAN-only, auto-disabled) and restarts the container.
Only when requirements.txt changes:
docker buildx build --platform linux/arm/v5 -t <repo>/mt-telegram-bot:latest --push .
Then remove + re-add the container (full re-pull). That's why code lives in a volume mount, not the image.
# Import + i18n integrity (no router needed)
python3 test_smoke.py
# + live read-only router checks
ROUTER_IP=192.168.88.1 ROUTER_USER=api-user ROUTER_PASS=... python3 test_smoke.py
deploy.sh also runs a syntax check on every deploy.
# ARM/v5 (hEX S, hAP acยฒ) ARM64 (RB5009, CCR2xxx) x86_64 (CHR, x86)
docker buildx build --platform linux/arm/v5 -t <repo>/mt-telegram-bot:latest --push .
docker buildx build --platform linux/arm64 -t <repo>/mt-telegram-bot:latest --push .
docker buildx build --platform linux/amd64 -t <repo>/mt-telegram-bot:latest --push .
Turkish & English, toggled with /lang. Strings live in app/i18n.py (TR/EN key parity is verified by test_smoke.py).
CC BY-NC-SA 4.0 โ Creative Commons Attribution-NonCommercial-ShareAlike 4.0.
This is source-available, non-commercial software โ not OSI "open source" (which requires permitting commercial use). See
LICENSEโ for the full text.
Content type
Image
Digest
sha256:e3361d2aaโฆ
Size
52.7 MB
Last updated
4 months ago
docker pull enesilhaydin/mt-telegram-bot