webhook

package
v0.0.0-...-c08403a Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageProvider

type MessageProvider interface {
	// GetPlainMessage must return the message for the webhook in plain-text format
	GetPlainMessage() (string, error)
	// GetSlackMessage must return the message for the webhook in Slack-compatible format
	GetSlackMessage() (SlackMessage, error)
}

MessageProvider is the interface provided by the webhook message data provider

type NewWebhookOpts

type NewWebhookOpts struct {
	// URL is the webhook endpoint (required)
	URL string
	// Key is the optional key for the webhook
	// This is passed as-is in the Authorization header, so make sure to include amy prefix (like "Bearer" or "APIKey") if needed
	Key string
	// AuthorizationHeader is the name of the header that includes the authorization key
	// This is ignored when format is "discord" or "slack"
	// If empty, defaults to "Authorization"
	AuthorizationHeader string
	// Format is the webhook format
	// If empty, defaults to "plain"
	Format WebhookFormat
	// Optional logger to use instead of the default slog instance
	Logger *slog.Logger
	// contains filtered or unexported fields
}

type SlackMessage

type SlackMessage struct {
	Text string `json:"text"`
}

SlackMessage is the type for a Slack-compatible message

type StringMessage

type StringMessage string

StringMessage is a MessageProvider that wraps a simple string

func (StringMessage) GetPlainMessage

func (s StringMessage) GetPlainMessage() (string, error)

func (StringMessage) GetSlackMessage

func (s StringMessage) GetSlackMessage() (SlackMessage, error)

type Webhook

type Webhook interface {
	// SendWebhook sends the notification
	SendWebhook(ctx context.Context, data MessageProvider) error
}

Webhook client interface

func NewWebhook

func NewWebhook(opts NewWebhookOpts) (Webhook, error)

NewWebhook creates a new Webhook

type WebhookFormat

type WebhookFormat string

WebhookFormat is the type for the webhook format

const (
	FormatSlack   WebhookFormat = "slack"
	FormatDiscord WebhookFormat = "discord"
	FormatPlain   WebhookFormat = "plain"
)

Jump to

Keyboard shortcuts

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