Customizable Webhook Body Templating #158
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Pull Request: Customizable Webhook Body Templating
This PR introduces the ability to use Go's
text/templatesyntax to define the JSON body of outgoing webhooks, replacing the previous static body or simple JSON object.This feature is inspired by the highly flexible and customizable webhook payloads found in professional monitoring and visualization tools like Uptime Kuma and Grafana, ensuring
pgbackwebcan integrate seamlessly with virtually any external notification system.This change required a comprehensive refactoring of the webhook data flow to ensure all necessary event context is correctly built and passed down to the rendering layer.
✨ Key Changes & Features
1. Customizable Webhook Body
Bodyfield for a webhook now accepts a Gotext/templatestring.formatTime,formatFileSize) are exposed in the template context for easy data formatting.2. Standardized Event Payloads
To support templating, the webhook data flow was standardized using three new structs:
internal/service/webhooks/payload.go: Defines the new payload structures:DatabaseStatusDestinationStatusExecutionDetailsWebhookPayload: The main struct passed to the template, containing the above three structs plusEventTypeandMsg.3. Refactored Service Runners
RunDatabaseHealthy,RunDestinationUnhealthy,RunExecutionSuccess, etc.) are updated across the application to pre-build and pass the detailedDatabaseStatus,DestinationStatus, or fullWebhookPayload.4. Improved UI Documentation
.Database.Name,.Execution.FileSize, etc.), provides syntax examples, and documents the available helper functions.💻 Code Changes & Technical Notes
internal/service/webhooks/payload.go(NEW)internal/service/webhooks/utils.go(NEW)ParsePostgresURL,RenderWebhookBody, andbuildMessage. Registers template functions likeformatFileSize.internal/service/{databases, destinations, executions}internal/service/webhooks/run_webhook.gorunWebhookto accept and use theWebhookPayload.internal/service/webhooks/send_webhook_request.goRenderWebhookBodyto transform the template string into the final HTTP body.internal/view/web/dashboard/webhooks/common.go💬 Maintainer Feedback and Review Notes ⚙️
This feature represents a massive and necessary improvement to the maintainability and flexibility of the webhook system.
The core motivation for this refactor—to eliminate the burden of configuring and maintaining separate, hard-coded JSON payloads for every database and status change—has been successfully addressed by introducing centralized templating. This vastly reduces overhead for administrators.