Documentation
¶
Index ¶
- Constants
- Variables
- 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 TemplateType
Constants ¶
View Source
const AdminRouteCourier = "/courier"
View Source
const AdminRouteGetMessage = AdminRouteCourier + "/messages/:msgID"
View Source
const AdminRouteListMessages = AdminRouteCourier + "/messages"
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)
SmtpDialer() *gomail.Dialer
DispatchQueue(ctx context.Context) error
DispatchMessage(ctx context.Context, msg Message) error
SetGetEmailTemplateType(f func(t EmailTemplate) (TemplateType, error))
SetNewEmailTemplateFromMessage(f func(d template.Dependencies, msg Message) (EmailTemplate, error))
UseBackoff(b backoff.BackOff)
}
func NewCourier ¶
func NewCourier(ctx context.Context, deps Dependencies) (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.LoggingProvider
ConfigProvider
x.HTTPClientProvider
jsonnetsecure.VMProvider
}
type EmailTemplate ¶
type EmailTemplate interface {
json.Marshaler
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 TemplateType `json:"template_type" db:"template_type"`
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 MessageTypePhone )
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)
}
func NewSMSTemplateFromMessage ¶
func NewSMSTemplateFromMessage(d Dependencies, m Message) (SMSTemplate, error)
type TemplateType ¶
type TemplateType string
A Template's type
swagger:enum TemplateType
const ( TypeRecoveryInvalid TemplateType = "recovery_invalid" TypeRecoveryValid TemplateType = "recovery_valid" TypeRecoveryCodeInvalid TemplateType = "recovery_code_invalid" TypeRecoveryCodeValid TemplateType = "recovery_code_valid" TypeVerificationInvalid TemplateType = "verification_invalid" TypeVerificationValid TemplateType = "verification_valid" TypeVerificationCodeInvalid TemplateType = "verification_code_invalid" TypeVerificationCodeValid TemplateType = "verification_code_valid" TypeOTP TemplateType = "otp" TypeTestStub TemplateType = "stub" )
func GetEmailTemplateType ¶
func GetEmailTemplateType(t EmailTemplate) (TemplateType, error)
func SMSTemplateType ¶
func SMSTemplateType(t SMSTemplate) (TemplateType, error)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.