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 ¶
- func IsSlackBlocksJSON(message string) bool
- func PropertiesForChannel(channel string, properties map[string]string) map[string]string
- func SendSlack(ctx context.Context, apiToken, channel string, message Message) error
- func SendWebhook(ctx context.Context, conn *models.Connection, message Message) error
- type ErrAttachmentsUnsupported
- type Message
- type Result
- type Sender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSlackBlocksJSON ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (e ErrAttachmentsUnsupported) Error() string
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 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 (*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.