A simple service for proxying various webhooks to Telegram or Mailgun. Receive alerts from Beszel, monitoring tools, CI/CD pipelines, or any system that sends HTTP callbacks — and get them delivered as Telegram messages or email notifications.
Key idea: One endpoint receives webhooks, configurable handlers forward them to the destinations you choose.
- Plugin architecture — handlers are pre-registered; each route chooses which ones to run
- Telegram — forward to private messages via grammY
- Mailgun — send to any address via Mailgun API
- Config-driven — everything is defined in
config.jsand.env
git clone https://github.com/dixydo/webhook-forwarder.git
cd webhook-forwarder
pnpm installcp .env.example .env
# Edit .env — set variables for the handlers you useIn config.js, specify which handlers to run for each endpoint:
routes: {
'/alert': ['telegram', 'mailgun'], // both handlers
// '/critical': ['telegram'], // Telegram only
}pnpm startEndpoint: POST http://localhost:3000/alert
Caddy forwards requests to the Node.js service. One Caddyfile works for both environments:
| Environment | Set WEBHOOK_DOMAIN |
URL | HTTPS |
|---|---|---|---|
| Local | Leave empty | http://localhost:8081/alert |
No |
| Production | Your domain (e.g. webhook.example.com) |
https://webhook.example.com/alert |
Yes (Let's Encrypt) |
- Local: Caddy listens on port
WEBHOOK_PORT(default 8081), HTTP only. Use this when developing or when you don't need a domain. - Production: Set
WEBHOOK_DOMAINin.env. Caddy listens on 80/443, obtains a certificate automatically, and serves HTTPS. Point your DNS (A/AAAA) at the server and expose ports 80 and 443.
When using docker compose, Caddy’s config is generated by caddy-entrypoint.sh: only the :8081 block is written when WEBHOOK_DOMAIN is empty; the domain block is added when WEBHOOK_DOMAIN is set (avoids Caddy errors for an empty site key).
# 1. Fill in .env
cp .env.example .env
# For production: set WEBHOOK_DOMAIN=your.domain.com and ensure DNS points to this host.
# Set TELEGRAM_*, MAILGUN_*, etc.
# 2. Run
docker compose up -d --build- Local: webhook at
http://localhost:8081/alert(orhttp://<host>:8081/alert). - Production: after setting
WEBHOOK_DOMAINand DNS, webhook athttps://<WEBHOOK_DOMAIN>/alert.
# Build and run webhook-forwarder
docker build -t webhook-forwarder .
docker run -d --name webhook --env-file .env -p 3000:3000 webhook-forwarder
# Run Caddy (local: 8081; production: pass WEBHOOK_DOMAIN=your.domain.com and use 80/443)
docker run -d --name caddy \
-e PORT=3000 \
-e WEBHOOK_PORT=8081 \
-e WEBHOOK_DOMAIN= \
-v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
-v caddy_data:/data \
-v caddy_config:/config \
-p 8081:8081 -p 80:80 -p 443:443 \
--link webhook:webhook \
caddy:2-alpineNote: For Caddy to reach the service, the container name must be
webhook(or in the compose network — the service namewebhook). Thenreverse_proxy webhook:3000correctly proxies to the app.
| Field | Description |
|---|---|
handlers |
Registry of handlers and their options (including enabled) |
routes |
For each endpoint — list of handlers to invoke |
Core / Caddy
| Variable | Description |
|---|---|
PORT |
Internal Node.js port inside the container (default 3000). |
WEBHOOK_PORT |
HTTP port for local / no-domain use (default 8081). |
WEBHOOK_DOMAIN |
Leave empty for local; set to your domain (e.g. webhook.example.com) for production HTTPS. Caddy will obtain a Let's Encrypt certificate. |
Telegram
| Variable | Description |
|---|---|
TELEGRAM_BOT_TOKEN |
Token from @BotFather |
TELEGRAM_CHAT_ID |
Recipient chat ID (via getUpdates) |
Mailgun
| Variable | Description |
|---|---|
MAILGUN_API_KEY |
Mailgun API key |
MAILGUN_DOMAIN |
Sending domain (e.g. mg.example.com) |
MAILGUN_FROM |
Sender address (e.g. alerts@mg.example.com) |
MAILGUN_TO |
Recipient email |
IS_EUROPE_DOMAIN |
Set to true for EU domains (uses https://api.eu.mailgun.net). |
In Beszel notifications, add a Generic webhook:
generic://your-server.com/alert?template=json
Beszel JSON format:
{
"title": "Foo CPU above threshold",
"message": "CPU averaged 63.53% for the previous 10 minutes."
}Alternative keys are supported: subject/content, name/body.
- Create a file in
src/handlers/, e.g.src/handlers/slack.js:
export async function slackHandler(options, payload) {
// options — from config.handlers.slack
// payload — { title, message }
// ...
}- Register it in
src/handler-registry.js:
import { slackHandler } from './handlers/slack.js';
handlers.set('slack', slackHandler);- Add config in
config.jsand reference inroutes.
MIT