webhook

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DeliveryTTL = 48 * time.Hour

Variables

This section is empty.

Functions

This section is empty.

Types

type Deliverer

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

func NewDeliverer

func NewDeliverer(requireHTTPS bool) *Deliverer

func (*Deliverer) Deliver

func (d *Deliverer) Deliver(ctx context.Context, agent *identity.AgentIdentity, p Payload) error

Deliver is a convenience alias for DeliverHTTP.

func (*Deliverer) DeliverHTTP

func (d *Deliverer) DeliverHTTP(ctx context.Context, agent *identity.AgentIdentity, p Payload) error

DeliverHTTP performs the actual HTTP POST to the agent's webhook URL.

type Delivery

type Delivery struct {
	AgentID       string     `json:"agent_id"`
	MessageID     string     `json:"message_id"`
	Status        string     `json:"status"`
	Attempts      int        `json:"attempts"`
	MaxAttempts   int        `json:"max_attempts"`
	LastError     string     `json:"last_error"`
	LastAttemptAt *time.Time `json:"last_attempt_at,omitempty"`
	NextRetryAt   time.Time  `json:"next_retry_at"`
	CreatedAt     time.Time  `json:"created_at"`
	ExpiresAt     time.Time  `json:"expires_at"`
}

type DeliveryStore

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

func NewDeliveryStore

func NewDeliveryStore(pool *pgxpool.Pool) *DeliveryStore

func (*DeliveryStore) CreateDelivery

func (s *DeliveryStore) CreateDelivery(ctx context.Context, messageID string, lastError string) (*Delivery, error)

func (*DeliveryStore) DeleteExpiredDeliveries

func (s *DeliveryStore) DeleteExpiredDeliveries(ctx context.Context) (int64, error)

func (*DeliveryStore) GetPendingDeliveries

func (s *DeliveryStore) GetPendingDeliveries(ctx context.Context, limit int) ([]Delivery, error)

func (*DeliveryStore) MarkAttemptFailed

func (s *DeliveryStore) MarkAttemptFailed(ctx context.Context, messageID, errMsg string, nextRetry time.Time) error

func (*DeliveryStore) MarkDelivered

func (s *DeliveryStore) MarkDelivered(ctx context.Context, messageID string) error

func (*DeliveryStore) MarkFailed

func (s *DeliveryStore) MarkFailed(ctx context.Context, messageID, errMsg string) error

type Payload

type Payload struct {
	MessageID      string            `json:"message_id,omitempty"`
	ConversationID string            `json:"conversation_id,omitempty"`
	From           string            `json:"from"`
	To             string            `json:"to"`
	RawMessage     []byte            `json:"raw_message"`
	AuthHeaders    map[string]string `json:"auth_headers"`
	ReceivedAt     time.Time         `json:"received_at"`
}

type PersistentDeliverer

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

PersistentDeliverer wraps Deliverer with DB persistence for retry support.

func NewPersistentDeliverer

func NewPersistentDeliverer(deliverer *Deliverer, store *DeliveryStore) *PersistentDeliverer

func (*PersistentDeliverer) Deliver

Deliver attempts delivery and persists the result. On failure, the delivery is queued for retry. Always returns nil — the message is safely persisted. Use this for SMTP inbound where the message is already accepted.

func (*PersistentDeliverer) DeliverSync

func (pd *PersistentDeliverer) DeliverSync(ctx context.Context, agent *identity.AgentIdentity, p Payload) error

DeliverSync attempts delivery, persists the result, and returns the error. Use this for API-initiated sends where the caller needs immediate feedback.

type RetryWorker

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

func NewRetryWorker

func NewRetryWorker(deliveryStore *DeliveryStore, deliverer *Deliverer, identityStore *identity.Store) *RetryWorker

func (*RetryWorker) Start

func (w *RetryWorker) Start(ctx context.Context)

Jump to

Keyboard shortcuts

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