Skip to content

About

Receive webhooks and forward them to Telegram or Mailgun. Config-driven, Docker + Caddy, local or HTTPS.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Webhook Forwarder

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.

Features

  • 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.js and .env

Quick Start

1. Clone and install

git clone https://github.com/dixydo/webhook-forwarder.git
cd webhook-forwarder
pnpm install

2. Configure environment

cp .env.example .env
# Edit .env — set variables for the handlers you use

3. Edit configuration

In config.js, specify which handlers to run for each endpoint:

routes: {
  '/alert': ['telegram', 'mailgun'],  // both handlers
  // '/critical': ['telegram'],     // Telegram only
}

4. Run

pnpm start

Endpoint: POST http://localhost:3000/alert

Caddy reverse proxy (local + production)

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_DOMAIN in .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).

Production (Docker + Caddy)

# 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 (or http://<host>:8081/alert).
  • Production: after setting WEBHOOK_DOMAIN and DNS, webhook at https://<WEBHOOK_DOMAIN>/alert.

Manual Caddy run (without docker compose)

# 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-alpine

Note: For Caddy to reach the service, the container name must be webhook (or in the compose network — the service name webhook). Then reverse_proxy webhook:3000 correctly proxies to the app.

Configuration

config.js

Field Description
handlers Registry of handlers and their options (including enabled)
routes For each endpoint — list of handlers to invoke

Environment variables (.env)

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).

Beszel integration

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.

Adding a custom handler

  1. 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 }
  // ...
}
  1. Register it in src/handler-registry.js:
import { slackHandler } from './handlers/slack.js';
handlers.set('slack', slackHandler);
  1. Add config in config.js and reference in routes.

License

MIT

About

Receive webhooks and forward them to Telegram or Mailgun. Config-driven, Docker + Caddy, local or HTTPS.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages