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
- WebhookCommandRemove
- WebhookCommandRemoveAttribute
- WebhookCommandSetAttribute
- WebhookCommandUpdate
WebhookCommandAdd
Domain Command Struct:
type WebhookCommandAdd struct {
WebhookUuid string `json:"webhookUuid"`
DomainEvtIdentifier string `json:"domainEvtIdentifier"`
WebhookUrl string `json:"webhookUrl"`
Attributes string `json:"attributes,omitempty"`
}
Domain Command Handling Method:
func (cs *commandHandler) WebhookCommandAdd(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandAdd) ([]comby.Event, error)
WebhookCommandRemove
Domain Command Struct:
type WebhookCommandRemove struct {
WebhookUuid string `json:"webhookUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) WebhookCommandRemove(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandRemove) ([]comby.Event, error)
WebhookCommandRemoveAttribute
Domain Command Struct:
type WebhookCommandRemoveAttribute struct {
WebhookUuid string `json:"webhookUuid"`
Key string `json:"key"`
}
Domain Command Handling Method:
func (cs *commandHandler) WebhookCommandRemoveAttribute(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandRemoveAttribute) ([]comby.Event, error)
WebhookCommandSetAttribute
Domain Command Struct:
type WebhookCommandSetAttribute struct {
WebhookUuid string `json:"webhookUuid"`
Key string `json:"key"`
Value any `json:"value"`
}
Domain Command Handling Method:
func (cs *commandHandler) WebhookCommandSetAttribute(ctx context.Context, cmd comby.Command, domainCmd *WebhookCommandSetAttribute) ([]comby.Event, error)
WebhookCommandUpdate
Domain Command Struct:
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:
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:
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:
func (qs *queryService) WebhookQueryList(ctx context.Context, qry comby.Query, domainQry *WebhookQueryList) (*WebhookQueryListResponse, error)
WebhookQueryModel
Domain Query Struct:
type WebhookQueryModel struct {
WebhookUuid string `json:"webhookUuid"`
}
Domain Query Handling Method:
func (qs *queryService) WebhookQueryModel(ctx context.Context, qry comby.Query, domainQry *WebhookQueryModel) (*WebhookQueryItemResponse, error)
WebhookQueryListResponse
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
type WebhookQueryItemResponse struct {
Item *readmodel.WebhookModel `json:"item,omitempty"`
}
Events
- WebhookAddedEvent
- WebhookRemovedEvent
- WebhookAttributeRemovedEvent
- WebhookAttributeSetEvent
- WebhookUpdatedEvent
WebhookAddedEvent
Domain Event Struct:
type WebhookAddedEvent struct {
DomainEvtIdentifier string `json:"domainEvtIdentifier"`
WebhookUrl string `json:"webhookUrl"`
Attributes string `json:"attributes,omitempty"`
}
Domain Event Handling Method:
func (agg *Webhook) WebhookAddedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookAddedEvent) (error)
WebhookRemovedEvent
Domain Event Struct:
type WebhookRemovedEvent struct {
Reason string `json:"reason,omitempty"`
}
Domain Event Handling Method:
func (agg *Webhook) WebhookRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookRemovedEvent) (error)
WebhookAttributeRemovedEvent
Domain Event Struct:
type WebhookAttributeRemovedEvent struct {
Key string `json:"key"`
}
Domain Event Handling Method:
func (agg *Webhook) WebhookAttributeRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookAttributeRemovedEvent) (error)
WebhookAttributeSetEvent
Domain Event Struct:
type WebhookAttributeSetEvent struct {
Key string `json:"key"`
Value any `json:"value"`
}
Domain Event Handling Method:
func (agg *Webhook) WebhookAttributeSetEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookAttributeSetEvent) (error)
WebhookUpdatedEvent
Domain Event Struct:
type WebhookUpdatedEvent struct {
Active bool `json:"active"`
DomainEvtIdentifier string `json:"domainEvtIdentifier"`
WebhookUrl string `json:"webhookUrl"`
Attributes string `json:"attributes,omitempty"`
}
Domain Event Handling Method:
func (agg *Webhook) WebhookUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *WebhookUpdatedEvent) (error)
Aggregate
Aggregate Struct:
type Webhook struct {
*comby.BaseAggregate
// Value Objects
Active bool
DomainEvtIdentifier string
WebhookUrl string
}
Methods
Add
func (agg *Webhook) Add(domainEvtIdentifier, webhookUrl, attributes string) (error)
Remove
func (agg *Webhook) Remove() (error)
RemoveAttribute
func (agg *Webhook) RemoveAttribute(key string) (error)
SetAttribute
func (agg *Webhook) SetAttribute(key string, value any) (error)
Update
func (agg *Webhook) Update(active bool, domainEvtIdentifier, webhookUrl, attributes string) (error)
Event Handlers
WebhookReadmodel
Domain Event | Method |
---|---|
webhookAggregate.WebhookAddedEvent | WebhookAddedEvent |
webhookAggregate.WebhookUpdatedEvent | WebhookUpdatedEvent |
webhookAggregate.WebhookRemovedEvent | WebhookRemovedEvent |
webhookAggregate.WebhookAttributeSetEvent | WebhookAttributeSetEvent |
webhookAggregate.WebhookAttributeRemovedEvent | WebhookAttributeRemovedEvent |
tenantAggregate.TenantCreatedEvent | TenantCreatedEvent |
tenantAggregate.TenantRemovedEvent | TenantRemovedEvent |
tenantAggregate.TenantUpdatedEvent | TenantUpdatedEvent |