gotification

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 18 Imported by: 0

README

gotification

gotification is a reusable Go package that sends notifications through:

  • Email (SMTP)
  • Slack DMs
  • Slack channel messages
  • Discord DMs
  • Discord channel messages
  • Telegram bot messages
  • Generic webhook messages

It is designed for queue workers and background jobs. The library does not implement retries. Instead, it returns typed errors so callers can decide whether an error is retryable.

Installation

go get github.com/TheKrainBow/gotification

Quick Start

package main

import (
    "log"

    "github.com/TheKrainBow/gotification"
    "github.com/TheKrainBow/gotification/providers/discord"
    "github.com/TheKrainBow/gotification/providers/email"
    "github.com/TheKrainBow/gotification/providers/slack"
    "github.com/TheKrainBow/gotification/providers/telegram"
    "github.com/TheKrainBow/gotification/providers/webhook"
)

func main() {
    d, err := gotification.NewDispatcher()
    if err != nil {
        log.Fatal(err)
    }
    _ = d.AddEmailSMTP("default", email.SMTPConfig{
        Host: "smtp.internal.local",
        Port: 587,
        From: "noreply@example.com",
        TLSMode: email.TLSModeStartTLS,
    })
    _ = d.AddSlackProviderFromConfig("workspace-a", slack.Config{BotToken: "xoxb-a"})
    _ = d.AddDiscordProviderFromConfig("default", discord.Config{BotToken: "discord-token"})
    _ = d.AddTelegramProviderFromConfig("default", telegram.Config{BotToken: "telegram-token"})
    _ = d.AddWebhookProviderFromConfig("default", webhook.Config{})

    _ = d.SendSlackChannelMessage("workspace-a", "C123", "Release 1.2.3 completed.")
    _ = d.SendSlackChannelRichMessage("workspace-a", "C123", slackmsg.Message{
        Text: "USB receiver unplugged",
        Attachments: []slackmsg.Attachment{{
            Color: "#7B2CBF",
            Fields: []slackmsg.AttachmentField{
                {Title: "Host", Value: "maagosti", Short: true},
                {Title: "User", Value: "alice", Short: true},
            },
        }},
    })
    _ = d.SendSlackUserMP("workspace-a", "heinz", "Release 1.2.3 completed.")
    _ = d.SendMail("default", "ops@example.com", "Deploy done", "Release 1.2.3 completed.")
    _ = d.SendTelegramMessage("default", "123456789", "Release 1.2.3 completed.")
    err = d.SendWebhook("default", "https://example.com/hooks/deploy", "Release 1.2.3 completed.")

    if err != nil {
        log.Printf("send failed: %v", err)
        log.Printf("retryable: %v", gotification.Retryable(err))
    }
}

Add the import when using structured Slack payloads:

import "github.com/TheKrainBow/gotification/slackmsg"

Structured Slack Messages

Slack messages can carry top-level blocks and attachment-level blocks through slackmsg.Message.

n := gotification.Notification{
    Slack: &slackmsg.Message{
        Text: "USB receiver unplugged",
        Attachments: []slackmsg.Attachment{{
            Color: "#7B2CBF",
            Fields: []slackmsg.AttachmentField{
                {Title: "Host", Value: "c2r10p3.42nice.fr", Short: true},
                {Title: "Users", Value: "cngogang", Short: true},
            },
        }},
    },
}

err := d.Send(ctx, n, []gotification.Destination{{
    Channel:  gotification.ChannelSlack,
    Kind:     gotification.DestinationSlackChannel,
    ID:       "C123",
    Provider: "workspace-a",
}})

err = d.SendSlackChannelRichMessage("workspace-a", "C123", slackmsg.Message{
    Text: "📁 Un dossier est en attente de validation",
    Attachments: []slackmsg.Attachment{{
        Color: "#ffcc00",
        Blocks: []slackmsg.Block{
            {
                "type": "header",
                "text": map[string]any{
                    "type": "plain_text",
                    "text": "📁 Un dossier est en attente de validation",
                },
            },
            {
                "type": "actions",
                "elements": []any{
                    map[string]any{
                        "type": "button",
                        "text": map[string]any{
                            "type": "plain_text",
                            "text": "Voir le dossier",
                        },
                        "url":   "https://adm.example.com/admin/dossiers/42",
                        "style": "primary",
                    },
                },
            },
        },
    }},
})

Thread replies use the same payload:

err := d.SendSlackThreadReply("workspace-a", "C123", "1741256640.123456", slackmsg.Message{
    Text:           "Acknowledged",
    ReplyBroadcast: true,
})

Emoji reactions are sent separately:

err := d.AddSlackReaction("workspace-a", "C123", "1741256640.123456", ":eyes:")

Destination Model

Destination fields:

  • Channel: email, slack, discord, telegram, webhook
  • Kind:
    • email_address
    • slack_user
    • slack_channel
    • discord_user
    • discord_channel
    • telegram_chat
    • webhook_url
  • ID: email address, Slack ID, or Discord numeric ID
  • Provider: selects provider instance (mainly Slack workspaces)
  • Meta: optional extensibility map

Expected IDs:

  • Email: address like user@example.com
  • Slack user: ID like U...
  • Slack channel: ID like C...
  • Discord user/channel: numeric snowflake IDs
  • Telegram chat: numeric chat id (for example 123456789 or -100123...) or @channel_username
  • Webhook: full http:// or https:// URL

Multiple Slack Providers

Register multiple Slack providers with names:

gotification.WithSlackProvider("workspace-a", slackA)
gotification.WithSlackProvider("workspace-b", slackB)

Route per destination using Destination.Provider (required).

Error Handling

Send returns error and may return errors.Join(...) for multi-destination sends. The core typed error is NotifyError:

  • Kind: invalid_input, auth, not_found, rate_limited, temporary
  • Channel
  • Provider
  • Dest
  • RetryAfter (for rate limits)
  • Cause

Use gotification.Retryable(err) to detect whether retry makes sense. Only rate_limited and temporary are retryable.

Retry Policy

This library intentionally does not retry or sleep. Caller code (worker/queue) is responsible for retry strategy.

Optional Idempotency (In-Memory)

You can enable a process-local idempotency safety net:

d, _ := gotification.NewDispatcher(gotification.WithIdempotencyTTL(10 * time.Minute))

Then set Notification.IdempotencyKey. A successful send with the same key is rejected during TTL. Failed sends do not lock the key, so caller retries still work.

This is an in-memory safeguard only; strong idempotency should still be handled by caller infrastructure (DB/Redis/queue dedupe).

Runtime Mock Mode (Per Provider)

You can keep the same dispatcher setup and toggle mock behavior per channel/provider:

d, _ := gotification.NewDispatcher(
    gotification.WithLogFolder("./notifications-logs"),
)
_ = d.SetMockMode(gotification.ChannelSlack, "workspace-a", true) // mock only Slack workspace-a
_ = d.SetMockMode(gotification.ChannelDiscord, "default", false)  // keep Discord real

Every send is logged to stdout. When WithLogFolder is configured, one file per provider is also appended in a channel subfolder in that folder:

<log-folder>/
  slack/
    workspace-a.log
  discord/
    default.log
  email/
    default.log

Provider name is mandatory. Use:

  • Slack: your workspace key (for example workspace-a)
  • Email/Discord/Telegram/Webhook: default

When mock mode is enabled for a target, gotification skips the remote API call and prints [MOCKED] in the stdout/file log line.

Examples

Each provider has a dedicated runnable example with its own .env.example:

  • examples/email
  • examples/slack
  • examples/discord
  • examples/telegram
  • examples/webhook
  • examples/mock

To run one:

cp examples/slack/.env.example examples/slack/.env
go run ./examples/slack

Mocking Behavior

Use dispatcher mock mode flags (SetMockMode / WithMockMode) to skip real API calls per channel/provider while keeping the same send code paths.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retryable

func Retryable(err error) bool

Retryable reports whether err contains at least one retryable notification error.

Types

type Channel

type Channel string

Channel identifies a notification transport.

const (
	ChannelEmail    Channel = "email"
	ChannelSlack    Channel = "slack"
	ChannelDiscord  Channel = "discord"
	ChannelWebhook  Channel = "webhook"
	ChannelTelegram Channel = "telegram"
)

type Content

type Content struct {
	Subject string
	Text    string
	HTML    string
}

Content contains textual and HTML representations.

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

type EmailProvider interface {
	Send(ctx context.Context, to string, content Content) error
}

EmailProvider sends notification content to an email address.

type ErrKind

type ErrKind = notifyerr.Kind

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 Mode

type Mode int

Mode controls dispatch behavior when multiple destinations are passed.

const (
	SendBestEffort Mode = iota
	SendFailFast
)

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

func WithIdempotencyTTL(ttl time.Duration) Option

WithIdempotencyTTL enables in-memory idempotency for Notification.IdempotencyKey. Duplicate successful sends are rejected for the configured TTL.

func WithLogFolder

func WithLogFolder(path string) Option

WithLogFolder enables per-provider file logs in the provided folder.

func WithLogger

func WithLogger(l Logger) Option

WithLogger configures a logger used by dispatcher internals.

func WithMockFile

func WithMockFile(path string) Option

WithMockFile is a legacy helper kept for compatibility. It enables provider logs in the parent folder of the given path.

func WithMockMode

func WithMockMode(channel Channel, provider string, enabled bool) Option

WithMockMode enables/disables mock behavior for one channel/provider pair. Provider name is required.

func WithMode

func WithMode(mode Mode) Option

WithMode sets send behavior across multiple destinations.

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.

type TelegramProvider

type TelegramProvider interface {
	SendToChat(ctx context.Context, chatID string, message string) error
}

TelegramProvider sends Bot API messages to one chat.

type WebhookProvider

type WebhookProvider interface {
	Send(ctx context.Context, endpoint string, message string) error
}

WebhookProvider sends JSON payloads to an HTTP endpoint.

Directories

Path Synopsis
examples
basic command
discord command
email command
mock command
slack command
telegram command
webhook command
internal
providers

Jump to

Keyboard shortcuts

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