notification

package
v0.1.37 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package notification delivers a message to a channel named by a connection.

Dispatch is by connection type, not by URL scheme: Slack has a native API client, every other chat and push channel has a small HTTP sender, and SMTP and the generic webhook are reached by URL when no typed connection applies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSlackBlocksJSON

func IsSlackBlocksJSON(message string) bool

IsSlackBlocksJSON reports whether a message is a JSON object with a top-level blocks array, which is what distinguishes a Block Kit message from text that merely happens to be JSON.

func PropertiesForChannel

func PropertiesForChannel(channel string, properties map[string]string) map[string]string

PropertiesForChannel resolves namespaced properties for one channel: bare keys pass through, and a `channel.key` key is un-prefixed for its own channel and dropped for every other. It is what lets a single delivery carry per-channel overrides without a separate block for each.

func SendSlack

func SendSlack(ctx context.Context, apiToken, channel string, message Message) error

SendSlack posts to a channel with a bot token. It is separate from the webhook senders because Slack's API is the only one that takes structured blocks, and flattening them to text would throw away the formatting a template built.

func SendWebhook

func SendWebhook(ctx context.Context, conn *models.Connection, message Message) error

SendWebhook posts a message as JSON to an arbitrary URL. It is the fallback for connection types with no sender of their own, and for the explicit generic_webhook and webhook types.

The payload is deliberately flat — title, message, then every property — so a receiver can read it without knowing this repo's types.

Types

type ErrAttachmentsUnsupported

type ErrAttachmentsUnsupported struct {
	Channel string
}

ErrAttachmentsUnsupported is returned when a message carries an attachment to a channel that cannot deliver one. It is an error rather than a silent drop because a report that never arrived is indistinguishable from one that was never sent.

func (ErrAttachmentsUnsupported) Error

type Message

type Message struct {
	Title string
	Body  string

	// Properties are per-channel options. A key may be namespaced with the
	// channel it applies to (`slack.icon`), and is un-prefixed for that channel
	// and dropped for the others.
	Properties map[string]string

	// Attachments are carried by SMTP only. Sending them anywhere else is
	// refused rather than silently dropped — see ErrAttachmentsUnsupported.
	Attachments []mail.Attachment
}

Message is what gets delivered.

type Result

type Result struct {
	Connection string
	Channel    string
	Attached   bool
}

Result records what one delivery did.

type Sender

type Sender struct {
	// SystemSMTP is the connection name used for email when a delivery names
	// no connection of its own. Empty means there is no system mailer.
	SystemSMTP string
}

Sender delivers messages through resolved connections.

func NewSender

func NewSender() *Sender

NewSender creates a sender.

func (*Sender) Send

func (s *Sender) Send(ctx dbcontext.Context, connectionName string, message Message) (Result, error)

Send delivers a message through the named connection.

The connection is resolved and hydrated by the caller's context, so secrets are already materialised by the time a sender sees them.

Directories

Path Synopsis
Package senders delivers a notification to one channel, chosen by the type of the connection addressing it.
Package senders delivers a notification to one channel, chosen by the type of the connection addressing it.

Jump to

Keyboard shortcuts

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