Documentation
¶
Overview ¶
Package webhook sends each reminder as one HTTP POST with a JSON body to an address the member chooses. With a body template it speaks to Discord, Slack incoming webhooks, Gotify, Home Assistant and anything else that takes JSON. It is a notify-only channel.
Index ¶
Constants ¶
const MaxTemplate = 8 << 10
MaxTemplate is the largest body template accepted, in bytes.
const Name = "webhook"
Name is the channel name in channel_links.
Variables ¶
var Variables = []string{
"event", "title", "emoji", "message", "text", "subscription", "amount", "currency",
"dueDate", "daysUntil", "paymentMethod", "category", "link",
}
Variables are the names a body template can use as {{name}}, in the order the docs list them.
Functions ¶
func DefaultBody ¶
DefaultBody is the JSON sent when the destination has no template.
func Render ¶
Render fills a body template. Each {{name}} becomes the variable's value escaped for a JSON string, so it can be written inside quotes ("content": "{{title}}") whatever the value contains; numbers such as {{daysUntil}} also work without quotes. The result must be valid JSON.
func ValidateTemplate ¶
ValidateTemplate checks a template a member typed by filling it with a sample reminder. An empty template (the default body) is valid.
Types ¶
type Channel ¶
type Channel struct {
notify.OneWay
// Client must come from a netguard.Guard: any member can add a URL.
Client *http.Client
// Template returns the body template of a destination ("" for the
// default body).
Template func(ctx context.Context, url string) string
// PublicURL is the instance's public address ("" if unknown).
PublicURL string
UserAgent string
}
Channel is the webhook channel. Its chat id is the destination URL.
type Payload ¶
type Payload struct {
Event string `json:"event"`
Title string `json:"title"`
Message string `json:"message"`
Subscription string `json:"subscription,omitempty"`
Amount string `json:"amount,omitempty"`
Currency string `json:"currency,omitempty"`
DueDate string `json:"dueDate,omitempty"`
DaysUntil *int `json:"daysUntil,omitempty"`
PaymentMethod string `json:"paymentMethod,omitempty"`
Category string `json:"category,omitempty"`
Link string `json:"link,omitempty"`
}
Payload is the default body.