Documentation
¶
Index ¶
- func Retryable(err error) bool
- type Channel
- type Content
- type Destination
- type DestinationKind
- type DiscordProvider
- type Dispatcher
- func (d *Dispatcher) AddDiscordProvider(name string, p DiscordProvider) error
- func (d *Dispatcher) AddDiscordProviderFromConfig(name string, cfg discordprovider.Config) error
- func (d *Dispatcher) AddEmailProvider(name string, p EmailProvider) error
- func (d *Dispatcher) AddEmailSMTP(name string, cfg emailprovider.SMTPConfig) error
- func (d *Dispatcher) AddSlackProvider(name string, p SlackProvider) error
- func (d *Dispatcher) AddSlackProviderFromConfig(name string, cfg slackprovider.Config) error
- func (d *Dispatcher) AddSlackReaction(workspace, channelID, messageTS, emoji string) error
- func (d *Dispatcher) AddSlackReactionWithCtx(ctx context.Context, workspace, channelID, messageTS, emoji string) error
- func (d *Dispatcher) AddTelegramProvider(name string, p TelegramProvider) error
- func (d *Dispatcher) AddTelegramProviderFromConfig(name string, cfg telegramprovider.Config) error
- func (d *Dispatcher) AddWebhookProvider(name string, p WebhookProvider) error
- func (d *Dispatcher) AddWebhookProviderFromConfig(name string, cfg webhookprovider.Config) error
- func (d *Dispatcher) DisableIdempotency()
- func (d *Dispatcher) EnableIdempotency(ttl time.Duration) error
- func (d *Dispatcher) FindSlackUserByEmail(ctx context.Context, provider string, email string) (string, error)
- func (d *Dispatcher) FindSlackUsersByName(ctx context.Context, provider string, query string) ([]string, error)
- func (d *Dispatcher) RemoveDiscordProvider(name string)
- func (d *Dispatcher) RemoveEmailProvider(name string)
- func (d *Dispatcher) RemoveSlackProvider(name string) error
- func (d *Dispatcher) RemoveTelegramProvider(name string)
- func (d *Dispatcher) RemoveWebhookProvider(name string)
- func (d *Dispatcher) Send(ctx context.Context, n Notification, destinations []Destination) (err error)
- func (d *Dispatcher) SendMail(provider, to, subject, content string) error
- func (d *Dispatcher) SendMailWithCtx(ctx context.Context, provider, to, subject, content string) error
- func (d *Dispatcher) SendSlackChannelMessage(workspace, channelID, content string) error
- func (d *Dispatcher) SendSlackChannelMessageWithCtx(ctx context.Context, workspace, channelID, content string) error
- func (d *Dispatcher) SendSlackChannelRawMessage(workspace, channelID string, payload json.RawMessage) error
- func (d *Dispatcher) SendSlackChannelRawMessageWithCtx(ctx context.Context, workspace, channelID string, payload json.RawMessage) error
- func (d *Dispatcher) SendSlackChannelRichMessage(workspace, channelID string, message slackmsg.Message) error
- func (d *Dispatcher) SendSlackChannelRichMessageWithCtx(ctx context.Context, workspace, channelID string, message slackmsg.Message) error
- func (d *Dispatcher) SendSlackThreadReply(workspace, channelID, threadTS string, message slackmsg.Message) error
- func (d *Dispatcher) SendSlackThreadReplyWithCtx(ctx context.Context, workspace, channelID, threadTS string, ...) error
- func (d *Dispatcher) SendSlackUserByEmail(workspace, email, content string) error
- func (d *Dispatcher) SendSlackUserByEmailWithCtx(ctx context.Context, workspace, email, content string) error
- func (d *Dispatcher) SendSlackUserMP(workspace, username, content string) error
- func (d *Dispatcher) SendSlackUserMPRaw(workspace, username string, payload json.RawMessage) error
- func (d *Dispatcher) SendSlackUserMPRawWithCtx(ctx context.Context, workspace, username string, payload json.RawMessage) error
- func (d *Dispatcher) SendSlackUserMPWithCtx(ctx context.Context, workspace, username, content string) error
- func (d *Dispatcher) SendSlackUserRawMessage(workspace, userID string, payload json.RawMessage) error
- func (d *Dispatcher) SendSlackUserRawMessageWithCtx(ctx context.Context, workspace, userID string, payload json.RawMessage) error
- func (d *Dispatcher) SendTelegramMessage(provider, chatID, content string) error
- func (d *Dispatcher) SendTelegramMessageWithCtx(ctx context.Context, provider, chatID, content string) error
- func (d *Dispatcher) SendWebhook(provider, endpoint, content string) error
- func (d *Dispatcher) SendWebhookWithCtx(ctx context.Context, provider, endpoint, content string) error
- func (d *Dispatcher) SetLogFolder(path string) error
- func (d *Dispatcher) SetMockFile(path string) error
- func (d *Dispatcher) SetMockMode(channel Channel, provider string, enabled bool) error
- type EmailProvider
- type ErrKind
- type Logger
- type Mode
- type Notification
- type NotifyError
- type Option
- func WithDiscordConfig(name string, cfg discordprovider.Config) Option
- func WithDiscordProvider(name string, p DiscordProvider) Option
- func WithEmailProvider(name string, p EmailProvider) Option
- func WithEmailSMTP(name string, cfg emailprovider.SMTPConfig) Option
- func WithIdempotencyTTL(ttl time.Duration) Option
- func WithLogFolder(path string) Option
- func WithLogger(l Logger) Option
- func WithMockFile(path string) Option
- func WithMockMode(channel Channel, provider string, enabled bool) Option
- func WithMode(mode Mode) Option
- func WithSlackConfig(name string, cfg slackprovider.Config) Option
- func WithSlackProvider(name string, p SlackProvider) Option
- func WithTelegramConfig(name string, cfg telegramprovider.Config) Option
- func WithTelegramProvider(name string, p TelegramProvider) Option
- func WithWebhookConfig(name string, cfg webhookprovider.Config) Option
- func WithWebhookProvider(name string, p WebhookProvider) Option
- type SlackProvider
- type SlackRawProvider
- type SlackReactionProvider
- type SlackRichProvider
- type SlackUserLookupByEmailProvider
- type SlackUserLookupProvider
- type TelegramProvider
- type WebhookProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Destination ¶
type Destination struct {
Channel Channel
Kind DestinationKind
ID string
Provider string
Meta map[string]string
}
Destination selects where and how a notification is sent.
type DestinationKind ¶
type DestinationKind string
DestinationKind refines destination semantics per channel.
const ( DestinationEmailAddress DestinationKind = "email_address" DestinationSlackUser DestinationKind = "slack_user" DestinationSlackChannel DestinationKind = "slack_channel" DestinationDiscordUser DestinationKind = "discord_user" DestinationDiscordChannel DestinationKind = "discord_channel" DestinationWebhookURL DestinationKind = "webhook_url" DestinationTelegramChat DestinationKind = "telegram_chat" )
type DiscordProvider ¶
type DiscordProvider interface {
SendToUser(ctx context.Context, userID string, message string) error
SendToChannel(ctx context.Context, channelID string, message string) error
}
DiscordProvider sends Discord DMs and channel messages.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher orchestrates delivery across channels/providers.
func NewDispatcher ¶
func NewDispatcher(opts ...Option) (*Dispatcher, error)
NewDispatcher constructs a dispatcher from options.
func (*Dispatcher) AddDiscordProvider ¶
func (d *Dispatcher) AddDiscordProvider(name string, p DiscordProvider) error
AddDiscordProvider registers or replaces one named discord provider.
func (*Dispatcher) AddDiscordProviderFromConfig ¶
func (d *Dispatcher) AddDiscordProviderFromConfig(name string, cfg discordprovider.Config) error
AddDiscordProviderFromConfig builds and registers one named built-in Discord provider.
func (*Dispatcher) AddEmailProvider ¶
func (d *Dispatcher) AddEmailProvider(name string, p EmailProvider) error
AddEmailProvider registers or replaces one named email provider.
func (*Dispatcher) AddEmailSMTP ¶
func (d *Dispatcher) AddEmailSMTP(name string, cfg emailprovider.SMTPConfig) error
AddEmailSMTP builds and registers one named built-in SMTP email provider.
func (*Dispatcher) AddSlackProvider ¶
func (d *Dispatcher) AddSlackProvider(name string, p SlackProvider) error
AddSlackProvider registers or replaces one named Slack provider.
func (*Dispatcher) AddSlackProviderFromConfig ¶
func (d *Dispatcher) AddSlackProviderFromConfig(name string, cfg slackprovider.Config) error
AddSlackProviderFromConfig builds and registers one named Slack provider.
func (*Dispatcher) AddSlackReaction ¶ added in v1.0.1
func (d *Dispatcher) AddSlackReaction(workspace, channelID, messageTS, emoji string) error
AddSlackReaction adds one emoji reaction to an existing Slack message using context.Background().
func (*Dispatcher) AddSlackReactionWithCtx ¶ added in v1.0.1
func (d *Dispatcher) AddSlackReactionWithCtx(ctx context.Context, workspace, channelID, messageTS, emoji string) error
AddSlackReactionWithCtx adds one emoji reaction to an existing Slack message.
func (*Dispatcher) AddTelegramProvider ¶
func (d *Dispatcher) AddTelegramProvider(name string, p TelegramProvider) error
AddTelegramProvider registers or replaces one named telegram provider.
func (*Dispatcher) AddTelegramProviderFromConfig ¶
func (d *Dispatcher) AddTelegramProviderFromConfig(name string, cfg telegramprovider.Config) error
AddTelegramProviderFromConfig builds and registers one named built-in Telegram provider.
func (*Dispatcher) AddWebhookProvider ¶
func (d *Dispatcher) AddWebhookProvider(name string, p WebhookProvider) error
AddWebhookProvider registers or replaces one named webhook provider.
func (*Dispatcher) AddWebhookProviderFromConfig ¶
func (d *Dispatcher) AddWebhookProviderFromConfig(name string, cfg webhookprovider.Config) error
AddWebhookProviderFromConfig builds and registers one named built-in webhook provider.
func (*Dispatcher) DisableIdempotency ¶
func (d *Dispatcher) DisableIdempotency()
DisableIdempotency disables in-memory idempotency and clears in-memory keys.
func (*Dispatcher) EnableIdempotency ¶
func (d *Dispatcher) EnableIdempotency(ttl time.Duration) error
EnableIdempotency enables in-memory idempotency for Notification.IdempotencyKey.
func (*Dispatcher) FindSlackUserByEmail ¶ added in v1.0.3
func (d *Dispatcher) FindSlackUserByEmail(ctx context.Context, provider string, email string) (string, error)
FindSlackUserByEmail resolves the Slack user ID matching an exact email address for one provider.
Provider selection follows the same rules as Send: if provider is empty, the default Slack provider is used.
func (*Dispatcher) FindSlackUsersByName ¶
func (d *Dispatcher) FindSlackUsersByName(ctx context.Context, provider string, query string) ([]string, error)
FindSlackUsersByName resolves Slack user IDs matching query for one provider.
Provider selection follows the same rules as Send: if provider is empty, the default Slack provider is used.
func (*Dispatcher) RemoveDiscordProvider ¶
func (d *Dispatcher) RemoveDiscordProvider(name string)
RemoveDiscordProvider removes one named discord provider.
func (*Dispatcher) RemoveEmailProvider ¶
func (d *Dispatcher) RemoveEmailProvider(name string)
RemoveEmailProvider removes one named email provider.
func (*Dispatcher) RemoveSlackProvider ¶
func (d *Dispatcher) RemoveSlackProvider(name string) error
RemoveSlackProvider removes one named Slack provider.
func (*Dispatcher) RemoveTelegramProvider ¶
func (d *Dispatcher) RemoveTelegramProvider(name string)
RemoveTelegramProvider removes one named telegram provider.
func (*Dispatcher) RemoveWebhookProvider ¶
func (d *Dispatcher) RemoveWebhookProvider(name string)
RemoveWebhookProvider removes one named webhook provider.
func (*Dispatcher) Send ¶
func (d *Dispatcher) Send(ctx context.Context, n Notification, destinations []Destination) (err error)
Send dispatches one notification to every destination.
func (*Dispatcher) SendMail ¶
func (d *Dispatcher) SendMail(provider, to, subject, content string) error
SendMail sends one plain-text email notification using context.Background().
func (*Dispatcher) SendMailWithCtx ¶
func (d *Dispatcher) SendMailWithCtx(ctx context.Context, provider, to, subject, content string) error
SendMailWithCtx sends one plain-text email notification.
func (*Dispatcher) SendSlackChannelMessage ¶
func (d *Dispatcher) SendSlackChannelMessage(workspace, channelID, content string) error
SendSlackChannelMessage sends one message to a Slack channel ID on one workspace using context.Background(). If workspace is empty, the default Slack provider is used.
func (*Dispatcher) SendSlackChannelMessageWithCtx ¶
func (d *Dispatcher) SendSlackChannelMessageWithCtx(ctx context.Context, workspace, channelID, content string) error
SendSlackChannelMessageWithCtx sends one message to a Slack channel ID on one workspace. If workspace is empty, the default Slack provider is used.
func (*Dispatcher) SendSlackChannelRawMessage ¶ added in v1.0.2
func (d *Dispatcher) SendSlackChannelRawMessage(workspace, channelID string, payload json.RawMessage) error
SendSlackChannelRawMessage sends one raw Slack chat.postMessage payload to a channel ID using context.Background(). The library injects the final channel.
func (*Dispatcher) SendSlackChannelRawMessageWithCtx ¶ added in v1.0.2
func (d *Dispatcher) SendSlackChannelRawMessageWithCtx(ctx context.Context, workspace, channelID string, payload json.RawMessage) error
SendSlackChannelRawMessageWithCtx sends one raw Slack chat.postMessage payload to a channel ID. The library injects the final channel.
func (*Dispatcher) SendSlackChannelRichMessage ¶ added in v1.0.1
func (d *Dispatcher) SendSlackChannelRichMessage(workspace, channelID string, message slackmsg.Message) error
SendSlackChannelRichMessage sends one structured Slack message to a channel ID on one workspace using context.Background().
func (*Dispatcher) SendSlackChannelRichMessageWithCtx ¶ added in v1.0.1
func (d *Dispatcher) SendSlackChannelRichMessageWithCtx(ctx context.Context, workspace, channelID string, message slackmsg.Message) error
SendSlackChannelRichMessageWithCtx sends one structured Slack message to a channel ID on one workspace.
func (*Dispatcher) SendSlackThreadReply ¶ added in v1.0.1
func (d *Dispatcher) SendSlackThreadReply(workspace, channelID, threadTS string, message slackmsg.Message) error
SendSlackThreadReply sends one structured Slack reply in an existing thread using context.Background().
func (*Dispatcher) SendSlackThreadReplyWithCtx ¶ added in v1.0.1
func (d *Dispatcher) SendSlackThreadReplyWithCtx(ctx context.Context, workspace, channelID, threadTS string, message slackmsg.Message) error
SendSlackThreadReplyWithCtx sends one structured Slack reply in an existing thread.
func (*Dispatcher) SendSlackUserByEmail ¶ added in v1.0.3
func (d *Dispatcher) SendSlackUserByEmail(workspace, email, content string) error
SendSlackUserByEmail resolves a Slack user by exact email address and sends a DM message using context.Background(). If workspace is empty, the default Slack provider is used.
func (*Dispatcher) SendSlackUserByEmailWithCtx ¶ added in v1.0.3
func (d *Dispatcher) SendSlackUserByEmailWithCtx(ctx context.Context, workspace, email, content string) error
SendSlackUserByEmailWithCtx resolves a Slack user by exact email address and sends a DM message. If workspace is empty, the default Slack provider is used.
func (*Dispatcher) SendSlackUserMP ¶
func (d *Dispatcher) SendSlackUserMP(workspace, username, content string) error
SendSlackUserMP resolves Slack users by name and sends a DM message to every match using context.Background(). If workspace is empty, the default Slack provider is used.
func (*Dispatcher) SendSlackUserMPRaw ¶ added in v1.0.2
func (d *Dispatcher) SendSlackUserMPRaw(workspace, username string, payload json.RawMessage) error
SendSlackUserMPRaw resolves Slack users by name and sends one raw Slack chat.postMessage payload as a DM to every match using context.Background().
func (*Dispatcher) SendSlackUserMPRawWithCtx ¶ added in v1.0.2
func (d *Dispatcher) SendSlackUserMPRawWithCtx(ctx context.Context, workspace, username string, payload json.RawMessage) error
SendSlackUserMPRawWithCtx resolves Slack users by name and sends one raw Slack chat.postMessage payload as a DM to every match.
func (*Dispatcher) SendSlackUserMPWithCtx ¶
func (d *Dispatcher) SendSlackUserMPWithCtx(ctx context.Context, workspace, username, content string) error
SendSlackUserMPWithCtx resolves Slack users by name and sends a DM message to every match. If workspace is empty, the default Slack provider is used.
func (*Dispatcher) SendSlackUserRawMessage ¶ added in v1.0.4
func (d *Dispatcher) SendSlackUserRawMessage(workspace, userID string, payload json.RawMessage) error
SendSlackUserRawMessage sends one raw Slack chat.postMessage payload as a DM to a known Slack user ID using context.Background(). Unlike SendSlackUserMPRaw, this does not perform any user lookup.
func (*Dispatcher) SendSlackUserRawMessageWithCtx ¶ added in v1.0.4
func (d *Dispatcher) SendSlackUserRawMessageWithCtx(ctx context.Context, workspace, userID string, payload json.RawMessage) error
SendSlackUserRawMessageWithCtx sends one raw Slack chat.postMessage payload as a DM to a known Slack user ID. Unlike SendSlackUserMPRawWithCtx, this does not perform any user lookup — the caller must already know the target's Slack user ID.
func (*Dispatcher) SendTelegramMessage ¶
func (d *Dispatcher) SendTelegramMessage(provider, chatID, content string) error
SendTelegramMessage sends one message to a Telegram chat using context.Background().
func (*Dispatcher) SendTelegramMessageWithCtx ¶
func (d *Dispatcher) SendTelegramMessageWithCtx(ctx context.Context, provider, chatID, content string) error
SendTelegramMessageWithCtx sends one message to a Telegram chat.
func (*Dispatcher) SendWebhook ¶
func (d *Dispatcher) SendWebhook(provider, endpoint, content string) error
SendWebhook sends one message to a webhook endpoint using context.Background().
func (*Dispatcher) SendWebhookWithCtx ¶
func (d *Dispatcher) SendWebhookWithCtx(ctx context.Context, provider, endpoint, content string) error
SendWebhookWithCtx sends one message to a webhook endpoint.
func (*Dispatcher) SetLogFolder ¶
func (d *Dispatcher) SetLogFolder(path string) error
SetLogFolder enables per-provider file logs in the provided folder.
func (*Dispatcher) SetMockFile ¶
func (d *Dispatcher) SetMockFile(path string) error
SetMockFile is a legacy helper kept for compatibility. It enables provider logs in the parent folder of the given path.
func (*Dispatcher) SetMockMode ¶
func (d *Dispatcher) SetMockMode(channel Channel, provider string, enabled bool) error
SetMockMode enables/disables mock behavior for one channel/provider pair. Provider name is required.
type EmailProvider ¶
EmailProvider sends notification content to an email address.
type ErrKind ¶
ErrKind classifies dispatch errors for caller-side retry decisions.
const ( ErrInvalidInput ErrKind = notifyerr.KindInvalidInput ErrAuth ErrKind = notifyerr.KindAuth ErrNotFound ErrKind = notifyerr.KindNotFound ErrRateLimited ErrKind = notifyerr.KindRateLimited ErrTemporary ErrKind = notifyerr.KindTemporary )
type Logger ¶
type Logger interface {
Debug(msg string, kv ...any)
Info(msg string, kv ...any)
Warn(msg string, kv ...any)
Error(msg string, kv ...any)
}
Logger is an optional structured logger used by the dispatcher.
type Notification ¶
type Notification struct {
Name string
Content Content
Slack *slackmsg.Message
Data map[string]any
TraceID string
// IdempotencyKey is optional. When dispatcher idempotency is enabled,
// duplicate successful sends with the same key are rejected during TTL.
IdempotencyKey string
}
Notification is the payload sent to providers.
type NotifyError ¶
type NotifyError struct {
Kind ErrKind
Channel Channel
Provider string
Dest Destination
RetryAfter time.Duration
Cause error
}
NotifyError describes a channel/provider aware error returned by Send.
func (*NotifyError) Error ¶
func (e *NotifyError) Error() string
func (*NotifyError) Unwrap ¶
func (e *NotifyError) Unwrap() error
type Option ¶
type Option func(*Dispatcher) error
Option configures a Dispatcher.
func WithDiscordConfig ¶
func WithDiscordConfig(name string, cfg discordprovider.Config) Option
WithDiscordConfig builds and registers one named built-in Discord provider.
func WithDiscordProvider ¶
func WithDiscordProvider(name string, p DiscordProvider) Option
WithDiscordProvider registers one named discord provider.
func WithEmailProvider ¶
func WithEmailProvider(name string, p EmailProvider) Option
WithEmailProvider registers one named email provider.
func WithEmailSMTP ¶
func WithEmailSMTP(name string, cfg emailprovider.SMTPConfig) Option
WithEmailSMTP builds and registers one named built-in SMTP email provider.
func WithIdempotencyTTL ¶
WithIdempotencyTTL enables in-memory idempotency for Notification.IdempotencyKey. Duplicate successful sends are rejected for the configured TTL.
func WithLogFolder ¶
WithLogFolder enables per-provider file logs in the provided folder.
func WithLogger ¶
WithLogger configures a logger used by dispatcher internals.
func WithMockFile ¶
WithMockFile is a legacy helper kept for compatibility. It enables provider logs in the parent folder of the given path.
func WithMockMode ¶
WithMockMode enables/disables mock behavior for one channel/provider pair. Provider name is required.
func WithSlackConfig ¶
func WithSlackConfig(name string, cfg slackprovider.Config) Option
WithSlackConfig builds and registers one named Slack provider.
func WithSlackProvider ¶
func WithSlackProvider(name string, p SlackProvider) Option
WithSlackProvider registers one named Slack provider.
func WithTelegramConfig ¶
func WithTelegramConfig(name string, cfg telegramprovider.Config) Option
WithTelegramConfig builds and registers one named built-in Telegram provider.
func WithTelegramProvider ¶
func WithTelegramProvider(name string, p TelegramProvider) Option
WithTelegramProvider registers one named telegram provider.
func WithWebhookConfig ¶
func WithWebhookConfig(name string, cfg webhookprovider.Config) Option
WithWebhookConfig builds and registers one named built-in webhook provider.
func WithWebhookProvider ¶
func WithWebhookProvider(name string, p WebhookProvider) Option
WithWebhookProvider registers one named webhook provider.
type SlackProvider ¶
type SlackProvider interface {
SendToUser(ctx context.Context, userID string, message string) error
SendToChannel(ctx context.Context, channelID string, message string) error
}
SlackProvider sends Slack DMs and channel messages.
type SlackRawProvider ¶ added in v1.0.2
type SlackRawProvider interface {
SendToUserRawMessage(ctx context.Context, userID string, payload json.RawMessage) error
SendToChannelRawMessage(ctx context.Context, channelID string, payload json.RawMessage) error
}
SlackRawProvider is an optional capability for Slack providers that can send raw chat.postMessage payloads after the library injects the final channel.
type SlackReactionProvider ¶ added in v1.0.1
type SlackReactionProvider interface {
AddReaction(ctx context.Context, channelID, messageTS, emoji string) error
}
SlackReactionProvider is an optional capability for Slack providers that can add emoji reactions to existing messages.
type SlackRichProvider ¶ added in v1.0.1
type SlackRichProvider interface {
SendToUserMessage(ctx context.Context, userID string, message slackmsg.Message) error
SendToChannelMessage(ctx context.Context, channelID string, message slackmsg.Message) error
}
SlackRichProvider is an optional capability for Slack providers that can send structured Slack payloads, including attachments.
type SlackUserLookupByEmailProvider ¶ added in v1.0.3
type SlackUserLookupByEmailProvider interface {
FindUserByEmail(ctx context.Context, email string) (string, error)
}
SlackUserLookupByEmailProvider is an optional capability for Slack providers that can resolve a user ID by exact email address.
type SlackUserLookupProvider ¶
type SlackUserLookupProvider interface {
FindUsersByName(ctx context.Context, query string) ([]string, error)
}
SlackUserLookupProvider is an optional capability for Slack providers that can resolve user IDs by a username/display-name query.