Documentation
¶
Overview ¶
Package webhook provides webhook management for external integrations.
Index ¶
- type Config
- type CreateRequest
- type Handler
- func (h *Handler) Create(c echo.Context) error
- func (h *Handler) Delete(c echo.Context) error
- func (h *Handler) Get(c echo.Context) error
- func (h *Handler) GetEvents(c echo.Context) error
- func (h *Handler) IngressHandler(c echo.Context) error
- func (h *Handler) List(c echo.Context) error
- func (h *Handler) RegenerateSecret(c echo.Context) error
- func (h *Handler) RegisterRoutes(g *echo.Group)
- func (h *Handler) Update(c echo.Context) error
- type Service
- func (s *Service) Create(name string, webhookType WebhookType, description string) (*Webhook, error)
- func (s *Service) Delete(id string) error
- func (s *Service) Get(id string) (*Webhook, bool)
- func (s *Service) GetEvents(webhookID string, limit int) ([]*WebhookEvent, error)
- func (s *Service) HandleRequest(w http.ResponseWriter, r *http.Request, webhookID string)
- func (s *Service) Handler() http.HandlerFunc
- func (s *Service) List() []*Webhook
- func (s *Service) RegenerateSecret(id string) (string, error)
- func (s *Service) RegisterHandler(webhookType WebhookType, handler WebhookHandler)
- func (s *Service) Stop()
- func (s *Service) Update(id string, name, description string, enabled bool) error
- type UpdateRequest
- type Webhook
- type WebhookEvent
- type WebhookHandler
- type WebhookType
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 ¶
NewHandler creates a new webhook handler.
func (*Handler) Create ¶
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 ¶
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 ¶
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 ¶
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 ¶
IngressHandler handles incoming webhook requests. This should be mounted at /hooks/:id
func (*Handler) List ¶
List returns all webhooks. @Summary List webhooks @Tags webhooks @Produce json @Success 200 {array} Webhook @Router /api/v1/webhooks [get]
func (*Handler) RegenerateSecret ¶
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 ¶
RegisterRoutes registers webhook routes.
func (*Handler) Update ¶
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 ¶
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) GetEvents ¶
func (s *Service) GetEvents(webhookID string, limit int) ([]*WebhookEvent, error)
GetEvents returns events for a webhook.
func (*Service) HandleRequest ¶
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) RegenerateSecret ¶
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.
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" )