Skip to content

Webhook

Overview

The Webhook domain in comby is designed to manage webhooks, enabling systems to notify external services of events or changes in real time. Webhooks are a critical part of integration workflows, providing a mechanism for external systems to react to specific events by consuming data through HTTP endpoints. The Webhook aggregate models the configuration and state of a webhook, ensuring consistency and traceability through event sourcing.

Structure

The Webhook aggregate extends the BaseAggregate, leveraging comby's core capabilities to manage state, track changes, and persist events. The aggregate defines fields that represent the attributes of a webhook:

  • References: Reserved for potential relationships with other entities (not explicitly included in the default implementation).

  • Value Objects:

    • Active: A boolean indicating whether the webhook is active and capable of sending notifications.
    • EventDataIdentifier: The identifier of the event data that the webhook is configured to process.
    • WebhookUrl: The HTTP endpoint to which the webhook sends its notifications.

This structure allows the Webhook aggregate to model the configuration and status of webhooks effectively, ensuring compatibility with a wide range of integration scenarios.

Commands

WebhookCommandAdd

Domain Command Struct:

go
type WebhookCommandAdd struct {
	WebhookUuid         string `json:"webhookUuid"`
	DomainEvtIdentifier string `json:"domainEvtIdentifier"`
	WebhookUrl          string `json:"webhookUrl"`
	Attributes          string `json:"attributes,omitempty"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) WebhookCommandAdd(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandAdd) ([]comby.Event, error)

WebhookCommandRemove

Domain Command Struct:

go
type WebhookCommandRemove struct {
	WebhookUuid string `json:"webhookUuid"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) WebhookCommandRemove(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandRemove) ([]comby.Event, error)

WebhookCommandRemoveAttribute

Domain Command Struct:

go
type WebhookCommandRemoveAttribute struct {
	WebhookUuid string `json:"webhookUuid"`
	Key         string `json:"key"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) WebhookCommandRemoveAttribute(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandRemoveAttribute) ([]comby.Event, error)

WebhookCommandSetAttribute

Domain Command Struct:

go
type WebhookCommandSetAttribute struct {
	WebhookUuid string `json:"webhookUuid"`
	Key         string `json:"key"`
	Value       any    `json:"value"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) WebhookCommandSetAttribute(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandSetAttribute) ([]comby.Event, error)

WebhookCommandUpdate

Domain Command Struct:

go
type WebhookCommandUpdate struct {
	WebhookUuid         string   `json:"webhookUuid"`
	Active              bool     `json:"active,omitempty"`
	DomainEvtIdentifier string   `json:"domainEvtIdentifier,omitempty"`
	WebhookUrl          string   `json:"webhookUrl,omitempty"`
	Attributes          string   `json:"attributes,omitempty"`
	PatchedFields       []string `json:"patchedFields"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) WebhookCommandUpdate(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandUpdate) ([]comby.Event, error)

Queries

Domain Query Structs:

Domain Query Responses:

WebhookQueryList

Domain Query Struct:

go
type WebhookQueryList struct {
	TenantUuid string `json:"tenantUuid"`
	Page       int64  `json:"page,omitempty"`
	PageSize   int64  `json:"pageSize,omitempty"`
	OrderBy    string `json:"orderBy,omitempty"`
	Attributes string `json:"attributes,omitempty"`
}

Domain Query Handling Method:

go
func (qs *queryService) WebhookQueryList(ctx context.Context, qry comby.Query, domainQry *WebhookQueryList) (*WebhookQueryListResponse, error)

WebhookQueryModel

Domain Query Struct:

go
type WebhookQueryModel struct {
	WebhookUuid string `json:"webhookUuid"`
}

Domain Query Handling Method:

go
func (qs *queryService) WebhookQueryModel(ctx context.Context, qry comby.Query, domainQry *WebhookQueryModel) (*WebhookQueryItemResponse, error)

WebhookQueryListResponse

go
type WebhookQueryListResponse struct {
	Items    []*readmodel.WebhookModel `json:"items,omitempty"`
	Total    int64                     `json:"total,omitempty"`
	Page     int64                     `json:"page,omitempty"`
	PageSize int64                     `json:"pageSize,omitempty"`
}

WebhookQueryItemResponse

go
type WebhookQueryItemResponse struct {
	Item *readmodel.WebhookModel `json:"item,omitempty"`
}

Events

WebhookAddedEvent

Domain Event Struct:

go
type WebhookAddedEvent struct {
	DomainEvtIdentifier string `json:"domainEvtIdentifier"`
	WebhookUrl          string `json:"webhookUrl"`
	Attributes          string `json:"attributes,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Webhook) WebhookAddedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookAddedEvent) (error)

WebhookRemovedEvent

Domain Event Struct:

go
type WebhookRemovedEvent struct {
	Reason string `json:"reason,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Webhook) WebhookRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookRemovedEvent) (error)

WebhookAttributeRemovedEvent

Domain Event Struct:

go
type WebhookAttributeRemovedEvent struct {
	Key string `json:"key"`
}

Domain Event Handling Method:

go
func (agg *Webhook) WebhookAttributeRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookAttributeRemovedEvent) (error)

WebhookAttributeSetEvent

Domain Event Struct:

go
type WebhookAttributeSetEvent struct {
	Key   string `json:"key"`
	Value any    `json:"value"`
}

Domain Event Handling Method:

go
func (agg *Webhook) WebhookAttributeSetEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookAttributeSetEvent) (error)

WebhookUpdatedEvent

Domain Event Struct:

go
type WebhookUpdatedEvent struct {
	Active              bool   `json:"active"`
	DomainEvtIdentifier string `json:"domainEvtIdentifier"`
	WebhookUrl          string `json:"webhookUrl"`
	Attributes          string `json:"attributes,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Webhook) WebhookUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookUpdatedEvent) (error)

Aggregate

Aggregate Struct:

go
type Webhook struct {
	*comby.BaseAggregate
	// Value Objects
	Active              bool
	DomainEvtIdentifier string
	WebhookUrl          string
}

Methods

Add

go
func (agg *Webhook) Add(domainEvtIdentifier, webhookUrl, attributes string) (error)

Remove

go
func (agg *Webhook) Remove() (error)

RemoveAttribute

go
func (agg *Webhook) RemoveAttribute(key string) (error)

SetAttribute

go
func (agg *Webhook) SetAttribute(key string, value any) (error)

Update

go
func (agg *Webhook) Update(active bool, domainEvtIdentifier, webhookUrl, attributes string) (error)

Event Handlers

WebhookReadmodel

Domain EventMethod
webhookAggregate.WebhookAddedEventWebhookAddedEvent
webhookAggregate.WebhookUpdatedEventWebhookUpdatedEvent
webhookAggregate.WebhookRemovedEventWebhookRemovedEvent
webhookAggregate.WebhookAttributeSetEventWebhookAttributeSetEvent
webhookAggregate.WebhookAttributeRemovedEventWebhookAttributeRemovedEvent
tenantAggregate.TenantCreatedEventTenantCreatedEvent
tenantAggregate.TenantRemovedEventTenantRemovedEvent
tenantAggregate.TenantUpdatedEventTenantUpdatedEvent