Documentation ¶
Index ¶
- Constants
- Variables
- type Channel
- type ConfigProvider
- type Courier
- type CourierMessageDispatchStatus
- type Dependencies
- type EmailTemplate
- type Handler
- type HandlerProvider
- type ListCourierMessagesParameters
- type Message
- type MessageDispatch
- type MessageStatus
- type MessageType
- type PersistenceProvider
- type Persister
- type Provider
- type SMSTemplate
- type SMTPChannel
- type SMTPClient
- type Template
Constants ¶
View Source
const ( AdminRouteCourier = "/courier" AdminRouteListMessages = AdminRouteCourier + "/messages" AdminRouteGetMessage = AdminRouteCourier + "/messages/:msgID" )
Variables ¶
View Source
var ErrQueueEmpty = errors.New("queue is empty")
Functions ¶
This section is empty.
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
CourierConfig() config.CourierConfigs
}
type Courier ¶
type Courier interface { Work(ctx context.Context) error QueueEmail(ctx context.Context, t EmailTemplate) (uuid.UUID, error) QueueSMS(ctx context.Context, t SMSTemplate) (uuid.UUID, error) DispatchQueue(ctx context.Context) error DispatchMessage(ctx context.Context, msg Message) error UseBackoff(b backoff.BackOff) FailOnDispatchError() }
func NewCourier ¶
func NewCourier(ctx context.Context, deps Dependencies) (Courier, error)
func NewCourierWithCustomTemplates ¶ added in v1.1.0
func NewCourierWithCustomTemplates(ctx context.Context, deps Dependencies, newEmailTemplateFromMessage func(d template.Dependencies, msg Message) (EmailTemplate, error)) (Courier, error)
type CourierMessageDispatchStatus ¶ added in v0.11.1
type CourierMessageDispatchStatus string
swagger:enum CourierMessageDispatchStatus
const ( CourierMessageDispatchStatusFailed CourierMessageDispatchStatus = "failed" CourierMessageDispatchStatusSuccess CourierMessageDispatchStatus = "success" )
type Dependencies ¶
type Dependencies interface { PersistenceProvider x.TracingProvider x.LoggingProvider ConfigProvider x.HTTPClientProvider jsonnetsecure.VMProvider }
type EmailTemplate ¶
type EmailTemplate interface { Template EmailSubject(context.Context) (string, error) EmailBody(context.Context) (string, error) EmailBodyPlaintext(context.Context) (string, error) EmailRecipient() (string, error) }
func NewEmailTemplateFromMessage ¶
func NewEmailTemplateFromMessage(d template.Dependencies, msg Message) (EmailTemplate, error)
type Handler ¶ added in v0.11.0
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶ added in v0.11.0
func NewHandler(r handlerDependencies) *Handler
func (*Handler) RegisterAdminRoutes ¶ added in v0.11.0
func (h *Handler) RegisterAdminRoutes(admin *x.RouterAdmin)
func (*Handler) RegisterPublicRoutes ¶ added in v0.11.0
func (h *Handler) RegisterPublicRoutes(public *x.RouterPublic)
type HandlerProvider ¶ added in v0.11.0
type HandlerProvider interface {
CourierHandler() *Handler
}
type ListCourierMessagesParameters ¶ added in v0.11.0
type ListCourierMessagesParameters struct { keysetpagination.RequestParameters // Status filters out messages based on status. // If no value is provided, it doesn't take effect on filter. // // required: false // in: query Status *MessageStatus `json:"status"` // Recipient filters out messages based on recipient. // If no value is provided, it doesn't take effect on filter. // // required: false // in: query Recipient string `json:"recipient"` }
Paginated List Courier Message Parameters
swagger:parameters listCourierMessages
type Message ¶
type Message struct { // required: true ID uuid.UUID `json:"id" faker:"-" db:"id"` NID uuid.UUID `json:"-" faker:"-" db:"nid"` // required: true Status MessageStatus `json:"status" db:"status"` // required: true Type MessageType `json:"type" db:"type"` // required: true Recipient string `json:"recipient" db:"recipient"` // required: true Body string `json:"body" db:"body"` // required: true Subject string `json:"subject" db:"subject"` // required: true TemplateType template.TemplateType `json:"template_type" db:"template_type"` Channel sqlxx.NullString `json:"channel" db:"channel"` TemplateData []byte `json:"-" db:"template_data"` // required: true SendCount int `json:"send_count" db:"send_count"` // Dispatches store information about the attempts of delivering a message // May contain an error if any happened, or just the `success` state. Dispatches []MessageDispatch `json:"dispatches,omitempty" has_many:"courier_message_dispatches" order_by:"created_at desc" faker:"-"` // CreatedAt is a helper struct field for gobuffalo.pop. // required: true CreatedAt time.Time `json:"created_at" faker:"-" db:"created_at"` // UpdatedAt is a helper struct field for gobuffalo.pop. // required: true UpdatedAt time.Time `json:"updated_at" faker:"-" db:"updated_at"` }
swagger:model message
func (Message) DefaultPageToken ¶ added in v0.11.1
func (m Message) DefaultPageToken() keysetpagination.PageToken
func (Message) PageToken ¶ added in v0.11.1
func (m Message) PageToken() keysetpagination.PageToken
type MessageDispatch ¶ added in v0.11.1
type MessageDispatch struct { // The ID of this message dispatch // required: true ID uuid.UUID `json:"id" db:"id"` // The ID of the message being dispatched // required: true MessageID uuid.UUID `json:"message_id" db:"message_id"` // The status of this dispatch // Either "failed" or "success" // required: true Status CourierMessageDispatchStatus `json:"status" db:"status"` // An optional error Error sqlxx.JSONRawMessage `json:"error,omitempty" db:"error"` // CreatedAt is a helper struct field for gobuffalo.pop. // required: true CreatedAt time.Time `json:"created_at" db:"created_at"` // UpdatedAt is a helper struct field for gobuffalo.pop. // required: true UpdatedAt time.Time `json:"updated_at" db:"updated_at"` NID uuid.UUID `json:"-" db:"nid"` }
MessageDispatch represents an attempt of sending a courier message It contains the status of the attempt (failed or successful) and the error if any occured
swagger:model messageDispatch
func (MessageDispatch) TableName ¶ added in v0.11.1
func (MessageDispatch) TableName() string
type MessageStatus ¶
type MessageStatus int
A Message's Status
swagger:model courierMessageStatus
const ( MessageStatusQueued MessageStatus = iota + 1 MessageStatusSent MessageStatusProcessing MessageStatusAbandoned )
func ToMessageStatus ¶ added in v0.11.0
func ToMessageStatus(str string) (MessageStatus, error)
func (MessageStatus) IsValid ¶ added in v0.11.0
func (ms MessageStatus) IsValid() error
func (MessageStatus) MarshalJSON ¶ added in v0.11.0
func (ms MessageStatus) MarshalJSON() ([]byte, error)
func (MessageStatus) String ¶ added in v0.11.0
func (ms MessageStatus) String() string
func (*MessageStatus) UnmarshalJSON ¶ added in v0.11.0
func (ms *MessageStatus) UnmarshalJSON(data []byte) error
type MessageType ¶
type MessageType int
A Message's Type
It can either be `email` or `phone`
swagger:model courierMessageType
const ( MessageTypeEmail MessageType = iota + 1 MessageTypeSMS )
func ToMessageType ¶ added in v0.11.0
func ToMessageType(str string) (MessageType, error)
func (MessageType) IsValid ¶ added in v0.11.0
func (mt MessageType) IsValid() error
func (MessageType) MarshalJSON ¶ added in v0.11.0
func (mt MessageType) MarshalJSON() ([]byte, error)
func (MessageType) String ¶ added in v0.11.0
func (mt MessageType) String() string
func (*MessageType) UnmarshalJSON ¶ added in v0.11.0
func (mt *MessageType) UnmarshalJSON(data []byte) error
type PersistenceProvider ¶
type PersistenceProvider interface {
CourierPersister() Persister
}
type Persister ¶
type Persister interface { AddMessage(context.Context, *Message) error NextMessages(context.Context, uint8) ([]Message, error) SetMessageStatus(context.Context, uuid.UUID, MessageStatus) error LatestQueuedMessage(ctx context.Context) (*Message, error) IncrementMessageSendCount(context.Context, uuid.UUID) error // ListMessages lists all messages in the store given the page, itemsPerPage, status and recipient. // Returns list of messages, total count of messages satisfied by given filter, and error if any ListMessages(context.Context, ListCourierMessagesParameters, []keysetpagination.Option) ([]Message, int64, *keysetpagination.Paginator, error) // FetchMessage returns a message with the id or nil and an error if not found FetchMessage(context.Context, uuid.UUID) (*Message, error) // Records an attempt of sending out a courier message // Returns an error if it fails RecordDispatch(ctx context.Context, msgID uuid.UUID, status CourierMessageDispatchStatus, err error) error }
type SMSTemplate ¶
type SMSTemplate interface { json.Marshaler SMSBody(context.Context) (string, error) PhoneNumber() (string, error) TemplateType() template.TemplateType }
func NewSMSTemplateFromMessage ¶
func NewSMSTemplateFromMessage(d template.Dependencies, m Message) (SMSTemplate, error)
type SMTPChannel ¶ added in v1.1.0
type SMTPChannel struct {
// contains filtered or unexported fields
}
func NewSMTPChannel ¶ added in v1.1.0
func NewSMTPChannel(deps Dependencies, cfg *config.SMTPConfig) (*SMTPChannel, error)
func NewSMTPChannelWithCustomTemplates ¶ added in v1.1.0
func NewSMTPChannelWithCustomTemplates(deps Dependencies, cfg *config.SMTPConfig, newEmailTemplateFromMessage func(d template.Dependencies, msg Message) (EmailTemplate, error)) (*SMTPChannel, error)
func (*SMTPChannel) Dispatch ¶ added in v1.1.0
func (c *SMTPChannel) Dispatch(ctx context.Context, msg Message) error
func (*SMTPChannel) ID ¶ added in v1.1.0
func (c *SMTPChannel) ID() string
type SMTPClient ¶ added in v1.1.0
func NewSMTPClient ¶ added in v1.1.0
func NewSMTPClient(deps Dependencies, cfg *config.SMTPConfig) (*SMTPClient, error)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.