message

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package message defines the notification delivery log entity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Count

type Count struct {
	Status  Status `json:"status"`
	Channel string `json:"channel"`
	N       int    `json:"n"`
}

Count is the number of messages with one status on one channel.

type Delivery

type Delivery struct {
	Status            Status
	Error             string
	ProviderMessageID string
	SentAt            *time.Time
}

Delivery is the outcome of one send attempt, written by RecordDelivery.

type ListOptions

type ListOptions struct {
	Channel string
	Status  Status
	Limit   int
	Offset  int
}

ListOptions defines filtering options for listing messages.

type Message

type Message struct {
	ID                id.MessageID      `json:"id"`
	AppID             string            `json:"app_id"`
	EnvID             string            `json:"env_id,omitempty"`
	TemplateID        string            `json:"template_id,omitempty"`
	ProviderID        string            `json:"provider_id,omitempty"`
	ProviderMessageID string            `json:"provider_message_id,omitempty"`
	Channel           string            `json:"channel"`
	Recipient         string            `json:"recipient"`
	Subject           string            `json:"subject,omitempty"`
	Body              string            `json:"body,omitempty"`
	Status            Status            `json:"status"`
	Error             string            `json:"error,omitempty"`
	Metadata          map[string]string `json:"metadata,omitempty"`
	Async             bool              `json:"async"`
	Attempts          int               `json:"attempts"`
	SentAt            *time.Time        `json:"sent_at,omitempty"`
	DeliveredAt       *time.Time        `json:"delivered_at,omitempty"`
	CreatedAt         time.Time         `json:"created_at"`
}

Message represents a sent or queued notification in the delivery log.

type Status

type Status string

Status represents the delivery state of a message.

const (
	StatusQueued    Status = "queued"
	StatusSending   Status = "sending"
	StatusSent      Status = "sent"
	StatusFailed    Status = "failed"
	StatusBounced   Status = "bounced"
	StatusDelivered Status = "delivered"

	// StatusSuppressed is a send Herald chose not to make, because the
	// recipient opted out of this notification type on this channel.
	StatusSuppressed Status = "suppressed"

	// StatusFiltered is a device the caller's filter dropped.
	StatusFiltered Status = "filtered"
)

Message status constants.

type Store

type Store interface {
	CreateMessage(ctx context.Context, m *Message) error
	GetMessage(ctx context.Context, messageID id.MessageID) (*Message, error)
	// RecordDelivery writes the outcome of a send: status, error, the vendor's
	// message ID and when it was sent. Every field is written, so an empty
	// value clears what was there.
	RecordDelivery(ctx context.Context, messageID id.MessageID, d Delivery) error
	ListMessages(ctx context.Context, appID string, opts ListOptions) ([]*Message, error)
	// CountMessages groups the messages created at or after since by status
	// and channel, sorted by status then channel.
	CountMessages(ctx context.Context, appID string, since time.Time) ([]Count, error)
}

Store defines persistence operations for the message delivery log.

Jump to

Keyboard shortcuts

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