notifications

package
v0.0.0-...-5baff64 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package notifications provides notification delivery for blockchain events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyWebhookSignature

func VerifyWebhookSignature(payload []byte, signature, secret string) bool

VerifyWebhookSignature verifies a webhook signature. This can be used by webhook recipients to verify the authenticity of the request.

Types

type BlockEventData

type BlockEventData struct {
	Number        uint64      `json:"number"`
	Hash          common.Hash `json:"hash"`
	ParentHash    common.Hash `json:"parent_hash"`
	Miner         string      `json:"miner"`
	GasUsed       uint64      `json:"gas_used"`
	GasLimit      uint64      `json:"gas_limit"`
	TxCount       int         `json:"tx_count"`
	BaseFeePerGas *string     `json:"base_fee_per_gas,omitempty"`
}

BlockEventData contains block-specific event data.

type Config

type Config struct {
	// Enabled determines if the notification service is active.
	Enabled bool `yaml:"enabled" json:"enabled"`

	// Webhook configuration
	Webhook WebhookConfig `yaml:"webhook" json:"webhook"`

	// Email configuration
	Email EmailConfig `yaml:"email" json:"email"`

	// Slack configuration
	Slack SlackConfig `yaml:"slack" json:"slack"`

	// Retry configuration
	Retry RetryConfig `yaml:"retry" json:"retry"`

	// Queue configuration
	Queue QueueConfig `yaml:"queue" json:"queue"`

	// Storage configuration
	Storage StorageConfig `yaml:"storage" json:"storage"`
}

Config holds the notification service configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a configuration with sensible defaults.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

type ConfigError

type ConfigError struct {
	Field   string
	Message string
}

ConfigError represents a configuration validation error.

func (*ConfigError) Error

func (e *ConfigError) Error() string

type DeliveryHistory

type DeliveryHistory struct {
	NotificationID string          `json:"notification_id"`
	SettingID      string          `json:"setting_id"`
	Attempt        int             `json:"attempt"`
	Result         *DeliveryResult `json:"result"`
	Timestamp      time.Time       `json:"timestamp"`
}

DeliveryHistory tracks notification delivery attempts.

type DeliveryResult

type DeliveryResult struct {
	Success      bool      `json:"success"`
	StatusCode   int       `json:"status_code,omitempty"`
	ResponseBody string    `json:"response_body,omitempty"`
	Error        string    `json:"error,omitempty"`
	DeliveredAt  time.Time `json:"delivered_at"`
	Duration     int64     `json:"duration_ms"`
}

DeliveryResult contains the result of a notification delivery attempt.

type DeliveryStatus

type DeliveryStatus string

DeliveryStatus represents the status of a notification delivery.

const (
	DeliveryStatusPending   DeliveryStatus = "pending"
	DeliveryStatusSent      DeliveryStatus = "sent"
	DeliveryStatusFailed    DeliveryStatus = "failed"
	DeliveryStatusRetrying  DeliveryStatus = "retrying"
	DeliveryStatusCancelled DeliveryStatus = "cancelled"
)

type Destination

type Destination struct {
	// Webhook settings
	WebhookURL     string            `json:"webhook_url,omitempty"`
	WebhookHeaders map[string]string `json:"webhook_headers,omitempty"`
	WebhookSecret  string            `json:"webhook_secret,omitempty"`

	// Email settings
	EmailTo      []string `json:"email_to,omitempty"`
	EmailCC      []string `json:"email_cc,omitempty"`
	EmailSubject string   `json:"email_subject,omitempty"`

	// Slack settings
	SlackWebhookURL string `json:"slack_webhook_url,omitempty"`
	SlackChannel    string `json:"slack_channel,omitempty"`
	SlackUsername   string `json:"slack_username,omitempty"`
}

Destination contains channel-specific delivery settings.

type EmailConfig

type EmailConfig struct {
	// Enabled determines if email notifications are available.
	Enabled bool `yaml:"enabled" json:"enabled"`

	// SMTPHost is the SMTP server hostname.
	SMTPHost string `yaml:"smtp_host" json:"smtp_host"`

	// SMTPPort is the SMTP server port.
	SMTPPort int `yaml:"smtp_port" json:"smtp_port"`

	// SMTPUsername for authentication.
	SMTPUsername string `yaml:"smtp_username" json:"smtp_username"`

	// SMTPPassword for authentication.
	SMTPPassword string `yaml:"smtp_password" json:"smtp_password"`

	// FromAddress is the sender email address.
	FromAddress string `yaml:"from_address" json:"from_address"`

	// FromName is the sender display name.
	FromName string `yaml:"from_name" json:"from_name"`

	// UseTLS enables TLS for SMTP connection.
	UseTLS bool `yaml:"use_tls" json:"use_tls"`

	// MaxRecipients per email.
	MaxRecipients int `yaml:"max_recipients" json:"max_recipients"`

	// RateLimitPerMinute limits emails per minute.
	RateLimitPerMinute int `yaml:"rate_limit_per_minute" json:"rate_limit_per_minute"`

	// TemplateDir is the directory containing email templates.
	TemplateDir string `yaml:"template_dir" json:"template_dir"`
}

EmailConfig holds email-specific configuration.

type EmailHandler

type EmailHandler struct {
	// contains filtered or unexported fields
}

EmailHandler handles email notification delivery.

func NewEmailHandler

func NewEmailHandler(config *EmailConfig, logger *zap.Logger) *EmailHandler

NewEmailHandler creates a new email handler.

func (*EmailHandler) Deliver

func (h *EmailHandler) Deliver(ctx context.Context, notification *Notification, setting *NotificationSetting) (*DeliveryResult, error)

Deliver delivers an email notification.

func (*EmailHandler) LoadTemplate

func (h *EmailHandler) LoadTemplate(name, templateStr string) error

LoadTemplate loads an email template from string.

func (*EmailHandler) Type

func (h *EmailHandler) Type() NotificationType

Type returns the notification type.

func (*EmailHandler) Validate

func (h *EmailHandler) Validate(setting *NotificationSetting) error

Validate validates an email notification setting.

type EventPayload

type EventPayload struct {
	ChainID     uint64          `json:"chain_id"`
	BlockNumber uint64          `json:"block_number"`
	BlockHash   common.Hash     `json:"block_hash"`
	Timestamp   time.Time       `json:"timestamp"`
	EventType   EventType       `json:"event_type"`
	Data        json.RawMessage `json:"data"`
}

EventPayload contains the blockchain event data.

type EventType

type EventType string

EventType represents blockchain event types that can trigger notifications.

const (
	EventTypeBlock            EventType = "block"
	EventTypeTransaction      EventType = "transaction"
	EventTypeLog              EventType = "log"
	EventTypeContractCreation EventType = "contract_creation"
	EventTypeTokenTransfer    EventType = "token_transfer"
)

type Handler

type Handler interface {
	Type() NotificationType
	Deliver(ctx context.Context, notification *Notification, setting *NotificationSetting) (*DeliveryResult, error)
	Validate(setting *NotificationSetting) error
}

Handler defines the interface for notification delivery handlers.

type LogEventData

type LogEventData struct {
	Address     common.Address `json:"address"`
	Topics      []common.Hash  `json:"topics"`
	Data        string         `json:"data"`
	BlockNumber uint64         `json:"block_number"`
	TxHash      common.Hash    `json:"tx_hash"`
	TxIndex     uint           `json:"tx_index"`
	LogIndex    uint           `json:"log_index"`
	Removed     bool           `json:"removed"`
}

LogEventData contains log-specific event data.

type Notification

type Notification struct {
	ID         string           `json:"id"`
	SettingID  string           `json:"setting_id"`
	Type       NotificationType `json:"type"`
	EventType  EventType        `json:"event_type"`
	Payload    *EventPayload    `json:"payload"`
	Status     DeliveryStatus   `json:"status"`
	RetryCount int              `json:"retry_count"`
	NextRetry  *time.Time       `json:"next_retry,omitempty"`
	CreatedAt  time.Time        `json:"created_at"`
	SentAt     *time.Time       `json:"sent_at,omitempty"`
	Error      string           `json:"error,omitempty"`
}

Notification represents a notification to be delivered.

type NotificationService

type NotificationService struct {
	// contains filtered or unexported fields
}

NotificationService implements the Service interface.

func NewService

func NewService(
	config *Config,
	storage Storage,
	eventBus *events.EventBus,
	logger *zap.Logger,
) *NotificationService

NewService creates a new notification service.

func (*NotificationService) CancelNotification

func (s *NotificationService) CancelNotification(ctx context.Context, id string) error

CancelNotification cancels a pending notification.

func (*NotificationService) CreateSetting

CreateSetting creates a new notification setting.

func (*NotificationService) DeleteSetting

func (s *NotificationService) DeleteSetting(ctx context.Context, id string) error

DeleteSetting deletes a notification setting.

func (*NotificationService) GetDeliveryHistory

func (s *NotificationService) GetDeliveryHistory(ctx context.Context, notificationID string) ([]*DeliveryHistory, error)

GetDeliveryHistory returns delivery history for a notification.

func (*NotificationService) GetNotification

func (s *NotificationService) GetNotification(ctx context.Context, id string) (*Notification, error)

GetNotification returns a notification by ID.

func (*NotificationService) GetSetting

GetSetting returns a notification setting by ID.

func (*NotificationService) GetStats

func (s *NotificationService) GetStats(ctx context.Context, settingID string) (*NotificationStats, error)

GetStats returns statistics for a notification setting.

func (*NotificationService) ListNotifications

func (s *NotificationService) ListNotifications(ctx context.Context, filter *NotificationsFilter) ([]*Notification, error)

ListNotifications returns notifications matching the filter.

func (*NotificationService) ListSettings

func (s *NotificationService) ListSettings(ctx context.Context, filter *SettingsFilter) ([]*NotificationSetting, error)

ListSettings returns notification settings matching the filter.

func (*NotificationService) RegisterHandler

func (s *NotificationService) RegisterHandler(handler Handler)

RegisterHandler registers a notification handler.

func (*NotificationService) RetryNotification

func (s *NotificationService) RetryNotification(ctx context.Context, id string) error

RetryNotification retries a failed notification.

func (*NotificationService) Start

func (s *NotificationService) Start(ctx context.Context) error

Start starts the notification service.

func (*NotificationService) Stop

Stop gracefully stops the notification service.

func (*NotificationService) TestSetting

func (s *NotificationService) TestSetting(ctx context.Context, id string) (*DeliveryResult, error)

TestSetting tests a notification setting with a sample event.

func (*NotificationService) UpdateSetting

UpdateSetting updates an existing notification setting.

type NotificationSetting

type NotificationSetting struct {
	ID          string           `json:"id"`
	Name        string           `json:"name"`
	Type        NotificationType `json:"type"`
	Enabled     bool             `json:"enabled"`
	CreatedAt   time.Time        `json:"created_at"`
	UpdatedAt   time.Time        `json:"updated_at"`
	EventTypes  []EventType      `json:"event_types"`
	Filter      *NotifyFilter    `json:"filter,omitempty"`
	Destination Destination      `json:"destination"`
}

NotificationSetting represents a user's notification configuration.

type NotificationStats

type NotificationStats struct {
	SettingID     string     `json:"setting_id"`
	TotalSent     int64      `json:"total_sent"`
	TotalFailed   int64      `json:"total_failed"`
	TotalPending  int64      `json:"total_pending"`
	LastSentAt    *time.Time `json:"last_sent_at,omitempty"`
	LastFailedAt  *time.Time `json:"last_failed_at,omitempty"`
	AvgDeliveryMs float64    `json:"avg_delivery_ms"`
	SuccessRate   float64    `json:"success_rate"`
}

NotificationStats contains statistics for a notification setting.

type NotificationType

type NotificationType string

NotificationType represents the type of notification channel.

const (
	NotificationTypeWebhook NotificationType = "webhook"
	NotificationTypeEmail   NotificationType = "email"
	NotificationTypeSlack   NotificationType = "slack"
)

type NotificationsFilter

type NotificationsFilter struct {
	SettingID  string
	Status     []DeliveryStatus
	EventTypes []EventType
	FromTime   *time.Time
	ToTime     *time.Time
	Limit      int
	Offset     int
}

NotificationsFilter for listing notifications.

type NotifyFilter

type NotifyFilter struct {
	Addresses     []common.Address `json:"addresses,omitempty"`
	Topics        [][]common.Hash  `json:"topics,omitempty"`
	ContractTypes []string         `json:"contract_types,omitempty"`
	MinValue      *string          `json:"min_value,omitempty"`
}

NotifyFilter defines conditions for triggering notifications.

type PebbleStorage

type PebbleStorage struct {
	// contains filtered or unexported fields
}

PebbleStorage implements the Storage interface using PebbleDB.

func NewPebbleStorage

func NewPebbleStorage(store storage.KVStore) *PebbleStorage

NewPebbleStorage creates a new PebbleStorage.

func (*PebbleStorage) CleanupOldHistory

func (s *PebbleStorage) CleanupOldHistory(ctx context.Context, before time.Time) (int64, error)

CleanupOldHistory removes delivery history older than the given time.

func (*PebbleStorage) DeleteSetting

func (s *PebbleStorage) DeleteSetting(ctx context.Context, id string) error

DeleteSetting deletes a notification setting.

func (*PebbleStorage) GetDeliveryHistory

func (s *PebbleStorage) GetDeliveryHistory(ctx context.Context, notificationID string) ([]*DeliveryHistory, error)

GetDeliveryHistory returns delivery history for a notification.

func (*PebbleStorage) GetNotification

func (s *PebbleStorage) GetNotification(ctx context.Context, id string) (*Notification, error)

GetNotification returns a notification by ID.

func (*PebbleStorage) GetPendingNotifications

func (s *PebbleStorage) GetPendingNotifications(ctx context.Context, limit int) ([]*Notification, error)

GetPendingNotifications returns pending notifications ready for retry.

func (*PebbleStorage) GetSetting

func (s *PebbleStorage) GetSetting(ctx context.Context, id string) (*NotificationSetting, error)

GetSetting returns a notification setting by ID.

func (*PebbleStorage) GetStats

func (s *PebbleStorage) GetStats(ctx context.Context, settingID string) (*NotificationStats, error)

GetStats returns notification statistics for a setting.

func (*PebbleStorage) IncrementStats

func (s *PebbleStorage) IncrementStats(ctx context.Context, settingID string, success bool, deliveryMs int64) error

IncrementStats increments notification statistics.

func (*PebbleStorage) ListNotifications

func (s *PebbleStorage) ListNotifications(ctx context.Context, filter *NotificationsFilter) ([]*Notification, error)

ListNotifications returns notifications matching the filter.

func (*PebbleStorage) ListSettings

func (s *PebbleStorage) ListSettings(ctx context.Context, filter *SettingsFilter) ([]*NotificationSetting, error)

ListSettings returns notification settings matching the filter.

func (*PebbleStorage) SaveDeliveryHistory

func (s *PebbleStorage) SaveDeliveryHistory(ctx context.Context, history *DeliveryHistory) error

SaveDeliveryHistory saves delivery history.

func (*PebbleStorage) SaveNotification

func (s *PebbleStorage) SaveNotification(ctx context.Context, notification *Notification) error

SaveNotification saves a notification.

func (*PebbleStorage) SaveSetting

func (s *PebbleStorage) SaveSetting(ctx context.Context, setting *NotificationSetting) error

SaveSetting saves a notification setting.

func (*PebbleStorage) UpdateNotificationStatus

func (s *PebbleStorage) UpdateNotificationStatus(ctx context.Context, id string, status DeliveryStatus, errMsg string) error

UpdateNotificationStatus updates a notification's status.

type QueueConfig

type QueueConfig struct {
	// BufferSize is the size of the notification queue buffer.
	BufferSize int `yaml:"buffer_size" json:"buffer_size"`

	// Workers is the number of concurrent delivery workers.
	Workers int `yaml:"workers" json:"workers"`

	// BatchSize is the maximum batch size for processing.
	BatchSize int `yaml:"batch_size" json:"batch_size"`

	// FlushInterval is how often to flush pending notifications.
	FlushInterval time.Duration `yaml:"flush_interval" json:"flush_interval"`
}

QueueConfig holds notification queue configuration.

type RetryConfig

type RetryConfig struct {
	// InitialDelay is the initial delay before first retry.
	InitialDelay time.Duration `yaml:"initial_delay" json:"initial_delay"`

	// MaxDelay is the maximum delay between retries.
	MaxDelay time.Duration `yaml:"max_delay" json:"max_delay"`

	// Multiplier for exponential backoff.
	Multiplier float64 `yaml:"multiplier" json:"multiplier"`

	// MaxAttempts is the maximum total attempts (including initial).
	MaxAttempts int `yaml:"max_attempts" json:"max_attempts"`
}

RetryConfig holds retry behavior configuration.

type Service

type Service interface {
	// Start starts the notification service.
	Start(ctx context.Context) error

	// Stop gracefully stops the notification service.
	Stop(ctx context.Context) error

	// Settings management
	CreateSetting(ctx context.Context, setting *NotificationSetting) (*NotificationSetting, error)
	UpdateSetting(ctx context.Context, setting *NotificationSetting) (*NotificationSetting, error)
	DeleteSetting(ctx context.Context, id string) error
	GetSetting(ctx context.Context, id string) (*NotificationSetting, error)
	ListSettings(ctx context.Context, filter *SettingsFilter) ([]*NotificationSetting, error)

	// Notification operations
	GetNotification(ctx context.Context, id string) (*Notification, error)
	ListNotifications(ctx context.Context, filter *NotificationsFilter) ([]*Notification, error)
	RetryNotification(ctx context.Context, id string) error
	CancelNotification(ctx context.Context, id string) error

	// Statistics
	GetStats(ctx context.Context, settingID string) (*NotificationStats, error)
	GetDeliveryHistory(ctx context.Context, notificationID string) ([]*DeliveryHistory, error)

	// Testing
	TestSetting(ctx context.Context, id string) (*DeliveryResult, error)
}

Service defines the notification service interface.

type SettingsFilter

type SettingsFilter struct {
	Types      []NotificationType
	EventTypes []EventType
	Enabled    *bool
	Limit      int
	Offset     int
}

SettingsFilter for listing notification settings.

type SlackAttachment

type SlackAttachment struct {
	Color      string       `json:"color,omitempty"`
	Pretext    string       `json:"pretext,omitempty"`
	AuthorName string       `json:"author_name,omitempty"`
	AuthorLink string       `json:"author_link,omitempty"`
	AuthorIcon string       `json:"author_icon,omitempty"`
	Title      string       `json:"title,omitempty"`
	TitleLink  string       `json:"title_link,omitempty"`
	Text       string       `json:"text,omitempty"`
	Fields     []SlackField `json:"fields,omitempty"`
	ImageURL   string       `json:"image_url,omitempty"`
	ThumbURL   string       `json:"thumb_url,omitempty"`
	Footer     string       `json:"footer,omitempty"`
	FooterIcon string       `json:"footer_icon,omitempty"`
	Ts         int64        `json:"ts,omitempty"`
}

SlackAttachment represents a Slack message attachment.

type SlackBlock

type SlackBlock struct {
	Type     string      `json:"type"`
	Text     *SlackText  `json:"text,omitempty"`
	Elements interface{} `json:"elements,omitempty"`
}

SlackBlock represents a Slack Block Kit block.

type SlackConfig

type SlackConfig struct {
	// Enabled determines if Slack notifications are available.
	Enabled bool `yaml:"enabled" json:"enabled"`

	// Timeout for Slack API requests.
	Timeout time.Duration `yaml:"timeout" json:"timeout"`

	// MaxRetries is the maximum number of retry attempts.
	MaxRetries int `yaml:"max_retries" json:"max_retries"`

	// DefaultUsername is the default bot username.
	DefaultUsername string `yaml:"default_username" json:"default_username"`

	// DefaultIconEmoji is the default bot icon.
	DefaultIconEmoji string `yaml:"default_icon_emoji" json:"default_icon_emoji"`

	// RateLimitPerMinute limits Slack messages per minute.
	RateLimitPerMinute int `yaml:"rate_limit_per_minute" json:"rate_limit_per_minute"`
}

SlackConfig holds Slack-specific configuration.

type SlackField

type SlackField struct {
	Title string `json:"title"`
	Value string `json:"value"`
	Short bool   `json:"short"`
}

SlackField represents a field in a Slack attachment.

type SlackHandler

type SlackHandler struct {
	// contains filtered or unexported fields
}

SlackHandler handles Slack notification delivery.

func NewSlackHandler

func NewSlackHandler(config *SlackConfig, logger *zap.Logger) *SlackHandler

NewSlackHandler creates a new Slack handler.

func (*SlackHandler) Deliver

func (h *SlackHandler) Deliver(ctx context.Context, notification *Notification, setting *NotificationSetting) (*DeliveryResult, error)

Deliver delivers a Slack notification.

func (*SlackHandler) Type

func (h *SlackHandler) Type() NotificationType

Type returns the notification type.

func (*SlackHandler) Validate

func (h *SlackHandler) Validate(setting *NotificationSetting) error

Validate validates a Slack notification setting.

type SlackMessage

type SlackMessage struct {
	Channel     string            `json:"channel,omitempty"`
	Username    string            `json:"username,omitempty"`
	IconEmoji   string            `json:"icon_emoji,omitempty"`
	IconURL     string            `json:"icon_url,omitempty"`
	Text        string            `json:"text,omitempty"`
	Attachments []SlackAttachment `json:"attachments,omitempty"`
	Blocks      []SlackBlock      `json:"blocks,omitempty"`
}

SlackMessage represents a Slack incoming webhook message.

type SlackText

type SlackText struct {
	Type string `json:"type"` // "plain_text" or "mrkdwn"
	Text string `json:"text"`
}

SlackText represents text in a Slack block.

type Storage

type Storage interface {
	// Settings
	SaveSetting(ctx context.Context, setting *NotificationSetting) error
	GetSetting(ctx context.Context, id string) (*NotificationSetting, error)
	DeleteSetting(ctx context.Context, id string) error
	ListSettings(ctx context.Context, filter *SettingsFilter) ([]*NotificationSetting, error)

	// Notifications
	SaveNotification(ctx context.Context, notification *Notification) error
	GetNotification(ctx context.Context, id string) (*Notification, error)
	UpdateNotificationStatus(ctx context.Context, id string, status DeliveryStatus, err string) error
	ListNotifications(ctx context.Context, filter *NotificationsFilter) ([]*Notification, error)
	GetPendingNotifications(ctx context.Context, limit int) ([]*Notification, error)

	// History
	SaveDeliveryHistory(ctx context.Context, history *DeliveryHistory) error
	GetDeliveryHistory(ctx context.Context, notificationID string) ([]*DeliveryHistory, error)

	// Stats
	GetStats(ctx context.Context, settingID string) (*NotificationStats, error)
	IncrementStats(ctx context.Context, settingID string, success bool, deliveryMs int64) error

	// Cleanup
	CleanupOldHistory(ctx context.Context, before time.Time) (int64, error)
}

Storage defines the notification storage interface.

type StorageConfig

type StorageConfig struct {
	// HistoryRetention is how long to keep delivery history.
	HistoryRetention time.Duration `yaml:"history_retention" json:"history_retention"`

	// MaxSettingsPerUser limits notification settings per user.
	MaxSettingsPerUser int `yaml:"max_settings_per_user" json:"max_settings_per_user"`

	// MaxPendingNotifications limits pending notifications.
	MaxPendingNotifications int `yaml:"max_pending_notifications" json:"max_pending_notifications"`
}

StorageConfig holds notification storage configuration.

type TransactionEventData

type TransactionEventData struct {
	Hash        common.Hash     `json:"hash"`
	From        common.Address  `json:"from"`
	To          *common.Address `json:"to,omitempty"`
	Value       string          `json:"value"`
	Gas         uint64          `json:"gas"`
	GasPrice    string          `json:"gas_price"`
	Nonce       uint64          `json:"nonce"`
	Input       string          `json:"input"`
	Status      uint64          `json:"status"`
	BlockNumber uint64          `json:"block_number"`
}

TransactionEventData contains transaction-specific event data.

type WebhookConfig

type WebhookConfig struct {
	// Enabled determines if webhook notifications are available.
	Enabled bool `yaml:"enabled" json:"enabled"`

	// Timeout for webhook HTTP requests.
	Timeout time.Duration `yaml:"timeout" json:"timeout"`

	// MaxRetries is the maximum number of retry attempts.
	MaxRetries int `yaml:"max_retries" json:"max_retries"`

	// MaxConcurrent is the maximum concurrent webhook deliveries.
	MaxConcurrent int `yaml:"max_concurrent" json:"max_concurrent"`

	// AllowedHosts restricts webhook URLs to specific hosts (empty = allow all).
	AllowedHosts []string `yaml:"allowed_hosts" json:"allowed_hosts"`

	// SignatureHeader is the header name for HMAC signature.
	SignatureHeader string `yaml:"signature_header" json:"signature_header"`
}

WebhookConfig holds webhook-specific configuration.

type WebhookHandler

type WebhookHandler struct {
	// contains filtered or unexported fields
}

WebhookHandler handles webhook notification delivery.

func NewWebhookHandler

func NewWebhookHandler(config *WebhookConfig, logger *zap.Logger) *WebhookHandler

NewWebhookHandler creates a new webhook handler.

func (*WebhookHandler) Deliver

func (h *WebhookHandler) Deliver(ctx context.Context, notification *Notification, setting *NotificationSetting) (*DeliveryResult, error)

Deliver delivers a webhook notification.

func (*WebhookHandler) Type

func (h *WebhookHandler) Type() NotificationType

Type returns the notification type.

func (*WebhookHandler) Validate

func (h *WebhookHandler) Validate(setting *NotificationSetting) error

Validate validates a webhook notification setting.

type WebhookPayload

type WebhookPayload struct {
	ID        string        `json:"id"`
	EventType string        `json:"event_type"`
	Timestamp string        `json:"timestamp"`
	Data      *EventPayload `json:"data"`
}

WebhookPayload is the payload sent to webhook endpoints.

Jump to

Keyboard shortcuts

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