Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidationError(err error) bool
- type CreateWebhookInput
- type DiscordProvider
- type Dispatcher
- type DispatcherConfig
- type GenericProvider
- type HTTPClient
- type PostgresRepository
- func (r *PostgresRepository) Create(ctx context.Context, webhook *Webhook) error
- func (r *PostgresRepository) Delete(ctx context.Context, id string) error
- func (r *PostgresRepository) Get(ctx context.Context, id string) (*Webhook, error)
- func (r *PostgresRepository) GetEnabledForNotificationType(ctx context.Context, teamID string, notificationType string) ([]*Webhook, error)
- func (r *PostgresRepository) ListByTeam(ctx context.Context, teamID string) ([]*Webhook, error)
- func (r *PostgresRepository) Update(ctx context.Context, id string, input UpdateWebhookInput) (*Webhook, error)
- func (r *PostgresRepository) UpdateLastTriggered(ctx context.Context, id string, lastError *string) error
- type Provider
- type ProviderRegistry
- type Repository
- type Service
- func (s *Service) Create(ctx context.Context, input CreateWebhookInput) (*Webhook, error)
- func (s *Service) Delete(ctx context.Context, id string) error
- func (s *Service) DispatchToTeam(ctx context.Context, teamID, notificationType, title, message string, ...)
- func (s *Service) Get(ctx context.Context, id string) (*Webhook, error)
- func (s *Service) GetMasked(ctx context.Context, id string) (*Webhook, error)
- func (s *Service) ListByTeam(ctx context.Context, teamID string) ([]*Webhook, error)
- func (s *Service) TestWebhook(ctx context.Context, id string) error
- func (s *Service) Update(ctx context.Context, id string, input UpdateWebhookInput) (*Webhook, error)
- type SlackProvider
- type UpdateWebhookInput
- type ValidationError
- type Webhook
- type WebhookNotification
Constants ¶
const ( ProviderSlack = "slack" ProviderDiscord = "discord" ProviderGeneric = "generic" )
Variables ¶
var ( ErrNotFound = errors.New("webhook not found") ValidProviders = map[string]bool{ ProviderSlack: true, ProviderDiscord: true, ProviderGeneric: true, } )
Functions ¶
func IsValidationError ¶
IsValidationError reports whether err is a user-facing validation error.
Types ¶
type CreateWebhookInput ¶
type CreateWebhookInput struct {
TeamID string `json:"team_id"`
Name string `json:"name"`
Provider string `json:"provider"`
WebhookURL string `json:"webhook_url"`
NotificationTypes []string `json:"notification_types"`
Enabled *bool `json:"enabled"`
}
CreateWebhookInput is the input for creating a webhook.
type DiscordProvider ¶
type DiscordProvider struct{}
DiscordProvider formats messages for Discord webhooks using embeds.
func (*DiscordProvider) ContentType ¶
func (p *DiscordProvider) ContentType() string
func (*DiscordProvider) FormatMessage ¶
func (p *DiscordProvider) FormatMessage(notification WebhookNotification) ([]byte, error)
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher handles async delivery of webhook notifications.
func NewDispatcher ¶
func NewDispatcher(repo Repository, registry *ProviderRegistry, config DispatcherConfig) *Dispatcher
NewDispatcher creates a new webhook dispatcher.
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(webhook *Webhook, notification WebhookNotification)
Dispatch queues a webhook delivery job.
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start(ctx context.Context)
Start begins the dispatcher worker pool.
type DispatcherConfig ¶
type DispatcherConfig struct {
MaxWorkers int
QueueSize int
Timeout time.Duration
MaxRetries int
RetryDelay time.Duration
}
DispatcherConfig configures the webhook dispatcher.
type GenericProvider ¶
type GenericProvider struct{}
GenericProvider formats messages as a simple JSON payload for custom integrations.
func (*GenericProvider) ContentType ¶
func (p *GenericProvider) ContentType() string
func (*GenericProvider) FormatMessage ¶
func (p *GenericProvider) FormatMessage(notification WebhookNotification) ([]byte, error)
type HTTPClient ¶
HTTPClient interface for testability.
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
func (*PostgresRepository) Create ¶
func (r *PostgresRepository) Create(ctx context.Context, webhook *Webhook) error
func (*PostgresRepository) Delete ¶
func (r *PostgresRepository) Delete(ctx context.Context, id string) error
func (*PostgresRepository) GetEnabledForNotificationType ¶
func (*PostgresRepository) ListByTeam ¶
func (*PostgresRepository) Update ¶
func (r *PostgresRepository) Update(ctx context.Context, id string, input UpdateWebhookInput) (*Webhook, error)
func (*PostgresRepository) UpdateLastTriggered ¶
type Provider ¶
type Provider interface {
// FormatMessage converts a notification into the provider-specific payload.
FormatMessage(notification WebhookNotification) ([]byte, error)
// ContentType returns the HTTP Content-Type header for requests.
ContentType() string
}
Provider formats notification messages for a specific webhook destination.
type ProviderRegistry ¶
type ProviderRegistry struct {
// contains filtered or unexported fields
}
ProviderRegistry holds all registered webhook providers.
func DefaultRegistry ¶
func DefaultRegistry() *ProviderRegistry
DefaultRegistry creates a registry with the built-in providers.
func NewProviderRegistry ¶
func NewProviderRegistry() *ProviderRegistry
NewProviderRegistry creates a new empty registry.
func (*ProviderRegistry) Get ¶
func (r *ProviderRegistry) Get(name string) (Provider, bool)
Get retrieves a provider by name.
func (*ProviderRegistry) Register ¶
func (r *ProviderRegistry) Register(name string, provider Provider)
Register adds a provider to the registry.
type Repository ¶
type Repository interface {
Create(ctx context.Context, webhook *Webhook) error
Get(ctx context.Context, id string) (*Webhook, error)
Update(ctx context.Context, id string, input UpdateWebhookInput) (*Webhook, error)
Delete(ctx context.Context, id string) error
ListByTeam(ctx context.Context, teamID string) ([]*Webhook, error)
GetEnabledForNotificationType(ctx context.Context, teamID string, notificationType string) ([]*Webhook, error)
UpdateLastTriggered(ctx context.Context, id string, lastError *string) error
}
Repository defines the webhook data access interface.
func NewPostgresRepository ¶
func NewPostgresRepository(db *pgxpool.Pool) Repository
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles webhook operations.
func NewService ¶
func NewService(repo Repository, encryptor *crypto.Encryptor, dispatcher *Dispatcher) *Service
NewService creates a new webhook service.
func (*Service) DispatchToTeam ¶
func (s *Service) DispatchToTeam(ctx context.Context, teamID, notificationType, title, message string, data map[string]interface{})
DispatchToTeam finds matching webhooks for a team and dispatches the notification. This implements the ExternalNotifier interface for the notification service.
func (*Service) ListByTeam ¶
ListByTeam lists all webhooks for a team with masked URLs.
func (*Service) TestWebhook ¶
TestWebhook sends a test notification to the webhook.
type SlackProvider ¶
type SlackProvider struct{}
SlackProvider formats messages for Slack incoming webhooks using Block Kit.
func (*SlackProvider) ContentType ¶
func (p *SlackProvider) ContentType() string
func (*SlackProvider) FormatMessage ¶
func (p *SlackProvider) FormatMessage(notification WebhookNotification) ([]byte, error)
type UpdateWebhookInput ¶
type UpdateWebhookInput struct {
Name *string `json:"name,omitempty"`
WebhookURL *string `json:"webhook_url,omitempty"`
NotificationTypes []string `json:"notification_types,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}
UpdateWebhookInput is the input for updating a webhook.
type ValidationError ¶
type ValidationError struct {
Message string
}
ValidationError represents a user-facing validation failure.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type Webhook ¶
type Webhook struct {
ID string `json:"id"`
TeamID string `json:"team_id"`
Name string `json:"name"`
Provider string `json:"provider"`
WebhookURL string `json:"webhook_url"`
NotificationTypes []string `json:"notification_types"`
Enabled bool `json:"enabled"`
LastTriggeredAt *time.Time `json:"last_triggered_at,omitempty"`
LastError *string `json:"last_error,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Webhook represents a team webhook configuration.