Documentation
¶
Overview ¶
Package webhook provides HTTP handler utilities for CloudContactAI webhooks.
Package webhook provides a service for managing CloudContactAI webhooks.
Package webhook provides types and utilities for handling CloudContactAI webhooks.
Package webhook provides functionality to configure and manage webhooks for CCAI events.
Index ¶
- func CreateHandler(options HandlerOptions) http.HandlerFunc
- type Client
- func (w *Client) Delete(id string) (*WebhookDeleteResponse, error)
- func (w *Client) List() ([]WebhookResponse, error)
- func (w *Client) Register(config WebhookConfig) (*WebhookResponse, error)
- func (w *Client) Update(id string, config WebhookConfig) (*WebhookResponse, error)
- func (w *Client) VerifySignature(signature string, clientID string, eventHash string, secret string) bool
- type HTTPClient
- type HandlerOptions
- type Service
- func (s *Service) Delete(id string) (*WebhookDeleteResponse, error)
- func (s *Service) List() ([]WebhookResponse, error)
- func (s *Service) Register(config WebhookConfig) (*WebhookResponse, error)
- func (s *Service) Update(id string, config WebhookConfig) (*WebhookResponse, error)
- func (s *Service) VerifySignature(signature, clientID, eventHash, secret string) bool
- type WebhookConfig
- type WebhookDeleteResponse
- type WebhookEvent
- type WebhookEventType
- type WebhookResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHandler ¶
func CreateHandler(options HandlerOptions) http.HandlerFunc
CreateHandler creates an HTTP handler for CloudContactAI webhooks
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a webhook client for managing CloudContactAI webhooks
func (*Client) Delete ¶
func (w *Client) Delete(id string) (*WebhookDeleteResponse, error)
Delete deletes a webhook
func (*Client) List ¶
func (w *Client) List() ([]WebhookResponse, error)
List lists all registered webhooks
func (*Client) Register ¶
func (w *Client) Register(config WebhookConfig) (*WebhookResponse, error)
Register registers a new webhook endpoint
func (*Client) Update ¶
func (w *Client) Update(id string, config WebhookConfig) (*WebhookResponse, error)
Update updates an existing webhook configuration
type HTTPClient ¶
type HTTPClient interface {
Request(method, path string, data interface{}, headers map[string]string) ([]byte, error)
GetClientID() string
}
HTTPClient interface for making HTTP requests
type HandlerOptions ¶
type HandlerOptions struct {
// ClientID is the CCAI client ID (required for signature verification)
ClientID string
// Secret used to verify webhook signatures
Secret string
// Handler for all webhook events
OnEvent func(event *WebhookEvent) error
// Whether to log events to console
LogEvents bool
}
HandlerOptions represents configuration options for the webhook handler
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents the webhook service for managing CloudContactAI webhooks
func NewService ¶
func NewService(client HTTPClient) *Service
NewService creates a new webhook service
func (*Service) Delete ¶
func (s *Service) Delete(id string) (*WebhookDeleteResponse, error)
Delete deletes a webhook
func (*Service) List ¶
func (s *Service) List() ([]WebhookResponse, error)
List lists all registered webhooks
func (*Service) Register ¶
func (s *Service) Register(config WebhookConfig) (*WebhookResponse, error)
Register registers a new webhook endpoint If config.Secret is nil, the server will generate a secret automatically
func (*Service) Update ¶
func (s *Service) Update(id string, config WebhookConfig) (*WebhookResponse, error)
Update updates an existing webhook configuration
func (*Service) VerifySignature ¶
VerifySignature verifies a webhook signature using HMAC-SHA256 Signature is computed as: HMAC-SHA256(secretKey, clientId:eventHash) encoded in Base64
type WebhookConfig ¶
type WebhookConfig struct {
URL string `json:"url"`
Events []WebhookEventType `json:"events"`
Secret *string `json:"secretKey,omitempty"` // Optional secret - if nil, server generates one automatically
}
WebhookConfig represents the configuration for webhook integration
type WebhookDeleteResponse ¶
WebhookDeleteResponse represents the response when deleting a webhook
type WebhookEvent ¶
type WebhookEvent struct {
EventType string `json:"eventType"` // Type of the event (e.g., "message.sent")
Data map[string]interface{} `json:"data"` // Event-specific data
EventHash string `json:"eventHash"` // Hash computed by the backend for signature verification
}
WebhookEvent represents the webhook payload sent by the server This is the unified structure for all event types
func ParseEvent ¶
func ParseEvent(payload []byte) (*WebhookEvent, error)
ParseEvent parses a raw webhook JSON payload into a WebhookEvent
type WebhookEventType ¶
type WebhookEventType string
WebhookEventType represents the types of webhook events
const ( // MessageSentEvent represents an outbound message event MessageSentEvent WebhookEventType = "message.sent" // MessageIncomingEvent represents an inbound message event MessageIncomingEvent WebhookEventType = "message.incoming" // MessageReceivedEvent represents an inbound message event (legacy name) MessageReceivedEvent WebhookEventType = "message.received" // MessageExcludedEvent represents a message excluded during campaign MessageExcludedEvent WebhookEventType = "message.excluded" // MessageErrorCarrierEvent represents a carrier-level delivery failure MessageErrorCarrierEvent WebhookEventType = "message.error.carrier" // MessageErrorCloudcontactEvent represents a CloudContact system error MessageErrorCloudcontactEvent WebhookEventType = "message.error.cloudcontact" )
type WebhookResponse ¶
type WebhookResponse struct {
ID interface{} `json:"id"`
URL string `json:"url"`
Method string `json:"method"`
IntegrationType string `json:"integrationType"`
SecretKey string `json:"secretKey,omitempty"`
}
WebhookResponse represents the response when registering/updating webhooks