webhook

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

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

View Source
const MaxTemplate = 8 << 10

MaxTemplate is the largest body template accepted, in bytes.

View Source
const Name = "webhook"

Name is the channel name in channel_links.

Variables

View Source
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

func DefaultBody(m actions.Message, link string) ([]byte, error)

DefaultBody is the JSON sent when the destination has no template.

func Render

func Render(tmpl string, vars map[string]string) ([]byte, error)

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

func ValidateTemplate(tmpl string) error

ValidateTemplate checks a template a member typed by filling it with a sample reminder. An empty template (the default body) is valid.

func Vars

func Vars(m actions.Message, link string) map[string]string

Vars returns the value of every template variable for a message. link is "" when the instance has no public address.

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.

func (*Channel) Name

func (c *Channel) Name() string

func (*Channel) Send

func (c *Channel) Send(ctx context.Context, url string, m actions.Message) (string, error)

Send posts the message to a URL. Any answer outside 2xx is an error, so the outbox retries. Errors name the host only: the rest of a webhook URL is a secret.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL