webhook

package
v0.0.0-...-8acab51 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package webhook provides webhook management for external integrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Enabled indicates if webhooks are enabled.
	Enabled bool `yaml:"enabled"`
	// SecretLength is the length of generated secrets.
	SecretLength int `yaml:"secret_length"`
	// MaxPayloadSize is the maximum payload size in bytes.
	MaxPayloadSize int64 `yaml:"max_payload_size"`
	// EventRetentionHours is how long to keep events.
	EventRetentionHours int `yaml:"event_retention_hours"`
	// MaxEventsPerWebhook is the maximum events to keep per webhook.
	MaxEventsPerWebhook int `yaml:"max_events_per_webhook"`
}

Config contains webhook service configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default webhook configuration.

type CreateRequest

type CreateRequest struct {
	Name        string      `json:"name" validate:"required"`
	Type        WebhookType `json:"type" validate:"required"`
	Description string      `json:"description"`
}

CreateRequest represents a create webhook request.

type Handler

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

Handler provides HTTP handlers for webhook management.

func NewHandler

func NewHandler(service *Service, logger *zap.Logger) *Handler

NewHandler creates a new webhook handler.

func (*Handler) Create

func (h *Handler) Create(c echo.Context) error

Create creates a new webhook. @Summary Create webhook @Tags webhooks @Accept json @Produce json @Param request body CreateRequest true "Create request" @Success 201 {object} Webhook @Failure 400 {object} map[string]string @Router /api/v1/webhooks [post]

func (*Handler) Delete

func (h *Handler) Delete(c echo.Context) error

Delete deletes a webhook. @Summary Delete webhook @Tags webhooks @Param id path string true "Webhook ID" @Success 200 {object} map[string]string @Failure 404 {object} map[string]string @Router /api/v1/webhooks/{id} [delete]

func (*Handler) Get

func (h *Handler) Get(c echo.Context) error

Get returns a webhook by ID. @Summary Get webhook @Tags webhooks @Produce json @Param id path string true "Webhook ID" @Success 200 {object} Webhook @Failure 404 {object} map[string]string @Router /api/v1/webhooks/{id} [get]

func (*Handler) GetEvents

func (h *Handler) GetEvents(c echo.Context) error

GetEvents returns events for a webhook. @Summary Get webhook events @Tags webhooks @Produce json @Param id path string true "Webhook ID" @Param limit query int false "Limit" default(20) @Success 200 {array} WebhookEvent @Failure 404 {object} map[string]string @Router /api/v1/webhooks/{id}/events [get]

func (*Handler) IngressHandler

func (h *Handler) IngressHandler(c echo.Context) error

IngressHandler handles incoming webhook requests. This should be mounted at /hooks/:id

func (*Handler) List

func (h *Handler) List(c echo.Context) error

List returns all webhooks. @Summary List webhooks @Tags webhooks @Produce json @Success 200 {array} Webhook @Router /api/v1/webhooks [get]

func (*Handler) RegenerateSecret

func (h *Handler) RegenerateSecret(c echo.Context) error

RegenerateSecret regenerates the webhook secret. @Summary Regenerate webhook secret @Tags webhooks @Produce json @Param id path string true "Webhook ID" @Success 200 {object} map[string]string @Failure 404 {object} map[string]string @Router /api/v1/webhooks/{id}/regenerate-secret [post]

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(g *echo.Group)

RegisterRoutes registers webhook routes.

func (*Handler) Update

func (h *Handler) Update(c echo.Context) error

Update updates a webhook. @Summary Update webhook @Tags webhooks @Accept json @Produce json @Param id path string true "Webhook ID" @Param request body UpdateRequest true "Update request" @Success 200 {object} map[string]string @Failure 400 {object} map[string]string @Failure 404 {object} map[string]string @Router /api/v1/webhooks/{id} [put]

type Service

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

Service manages webhooks.

func NewService

func NewService(cfg Config, logger *zap.Logger) *Service

NewService creates a new webhook service.

func (*Service) Create

func (s *Service) Create(name string, webhookType WebhookType, description string) (*Webhook, error)

Create creates a new webhook.

func (*Service) Delete

func (s *Service) Delete(id string) error

Delete deletes a webhook.

func (*Service) Get

func (s *Service) Get(id string) (*Webhook, bool)

Get returns a webhook by ID.

func (*Service) GetEvents

func (s *Service) GetEvents(webhookID string, limit int) ([]*WebhookEvent, error)

GetEvents returns events for a webhook.

func (*Service) HandleRequest

func (s *Service) HandleRequest(w http.ResponseWriter, r *http.Request, webhookID string)

HandleRequest handles an incoming webhook request.

func (*Service) Handler

func (s *Service) Handler() http.HandlerFunc

Handler returns an HTTP handler for the webhook service.

func (*Service) List

func (s *Service) List() []*Webhook

List returns all webhooks.

func (*Service) RegenerateSecret

func (s *Service) RegenerateSecret(id string) (string, error)

RegenerateSecret regenerates the secret for a webhook.

func (*Service) RegisterHandler

func (s *Service) RegisterHandler(webhookType WebhookType, handler WebhookHandler)

RegisterHandler registers a handler for a webhook type.

func (*Service) Stop

func (s *Service) Stop()

Stop stops the webhook service.

func (*Service) Update

func (s *Service) Update(id string, name, description string, enabled bool) error

Update updates a webhook.

type UpdateRequest

type UpdateRequest struct {
	Name        string `json:"name" validate:"required"`
	Description string `json:"description"`
	Enabled     bool   `json:"enabled"`
}

UpdateRequest represents an update webhook request.

type Webhook

type Webhook struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Type        WebhookType            `json:"type"`
	Secret      string                 `json:"secret,omitempty"`
	Enabled     bool                   `json:"enabled"`
	Description string                 `json:"description,omitempty"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
	LastUsedAt  *time.Time             `json:"last_used_at,omitempty"`
	UseCount    int64                  `json:"use_count"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

Webhook represents a registered webhook.

type WebhookEvent

type WebhookEvent struct {
	ID          string                 `json:"id"`
	WebhookID   string                 `json:"webhook_id"`
	Payload     json.RawMessage        `json:"payload"`
	Headers     map[string]string      `json:"headers"`
	ReceivedAt  time.Time              `json:"received_at"`
	ProcessedAt *time.Time             `json:"processed_at,omitempty"`
	Status      string                 `json:"status"`
	Error       string                 `json:"error,omitempty"`
	Response    interface{}            `json:"response,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

WebhookEvent represents an incoming webhook event.

type WebhookHandler

type WebhookHandler func(ctx context.Context, event *WebhookEvent) (interface{}, error)

WebhookHandler is a function that handles webhook events.

type WebhookType

type WebhookType string

WebhookType represents the type of webhook.

const (
	// TypeWake triggers the agent with the webhook payload.
	TypeWake WebhookType = "wake"
	// TypeAgent runs an isolated agent with the payload.
	TypeAgent WebhookType = "agent"
	// TypeCustom uses a custom handler.
	TypeCustom WebhookType = "custom"
)

Jump to

Keyboard shortcuts

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