Documentation
¶
Index ¶
- type Alert
- type AlertBundle
- type AlertStatus
- type AlertStatusBundle
- type DB
- func (db *DB) Code(ctx context.Context, id string) (int, error)
- func (db *DB) FindManyMessageStatuses(ctx context.Context, ids ...string) ([]MessageStatus, error)
- func (db *DB) LastMessageStatus(ctx context.Context, typ MessageType, cmID string, from time.Time) (*MessageStatus, time.Time, error)
- func (db *DB) SendContactMethodTest(ctx context.Context, id string) error
- func (db *DB) SendContactMethodVerification(ctx context.Context, cmID string) error
- func (db *DB) VerifyContactMethod(ctx context.Context, cmID string, code int) error
- type Dest
- type DestType
- type Manager
- func (m *Manager) RegisterReceiver(r Receiver)
- func (m *Manager) RegisterSender(t DestType, name string, s SendResponder)
- func (m *Manager) Send(ctx context.Context, msg Message) (*MessageStatus, error)
- func (mgr *Manager) SetStubNotifiers()
- func (m *Manager) Shutdown(context.Context) error
- func (m *Manager) Status(ctx context.Context, id, providerMsgID string) (*MessageStatus, error)
- type Message
- type MessageResponse
- type MessageState
- type MessageStatus
- type MessageType
- type Receiver
- type Result
- type SendResponder
- type Sender
- type Store
- type Test
- type Verification
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
Dest Dest
CallbackID string // CallbackID is the identifier used to communicate a response to the notification
AlertID int // The global alert number
Summary string
Details string
}
Alert represents outgoing notifications for alerts.
func (Alert) Destination ¶
func (Alert) ExtendedBody ¶
func (Alert) Type ¶
func (a Alert) Type() MessageType
type AlertBundle ¶ added in v0.24.0
type AlertBundle struct {
Dest Dest
CallbackID string // CallbackID is the identifier used to communicate a response to the notification
ServiceID string
ServiceName string // The service being notified for
Count int // Number of unacked alerts
}
AlertBundle represents a bundle of outgoing alert notifications for a single service.
func (AlertBundle) Destination ¶ added in v0.24.0
func (b AlertBundle) Destination() Dest
func (AlertBundle) ID ¶ added in v0.24.0
func (b AlertBundle) ID() string
func (AlertBundle) Type ¶ added in v0.24.0
func (b AlertBundle) Type() MessageType
type AlertStatus ¶
func (AlertStatus) Destination ¶
func (s AlertStatus) Destination() Dest
func (AlertStatus) ID ¶
func (s AlertStatus) ID() string
func (AlertStatus) Type ¶
func (s AlertStatus) Type() MessageType
type AlertStatusBundle ¶ added in v0.24.0
type AlertStatusBundle struct {
Dest Dest
CallbackID string
LogEntry string
AlertID int
Count int // The total number of status updates this bundle represents.
}
func (AlertStatusBundle) Destination ¶ added in v0.24.0
func (b AlertStatusBundle) Destination() Dest
func (AlertStatusBundle) ID ¶ added in v0.24.0
func (b AlertStatusBundle) ID() string
func (AlertStatusBundle) Type ¶ added in v0.24.0
func (b AlertStatusBundle) Type() MessageType
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) FindManyMessageStatuses ¶ added in v0.25.0
func (*DB) LastMessageStatus ¶ added in v0.26.0
func (*DB) SendContactMethodTest ¶
func (*DB) SendContactMethodVerification ¶
type DestType ¶
type DestType int
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is used as an intermediary between Senders and Receivers. It should be contstructed first (with NewManager()) and passed to Senders and Receivers that require it.
func (*Manager) RegisterReceiver ¶
RegisterReceiver will set the given Receiver as the target for all Receive() calls. It will panic if called multiple times.
func (*Manager) RegisterSender ¶
func (m *Manager) RegisterSender(t DestType, name string, s SendResponder)
RegisterSender will register a sender under a given DestType and name. A sender for the same name and type will replace an existing one, if any.
func (*Manager) Send ¶
Send implements the Sender interface by trying all registered senders for the type given in Notification. An error is returned if there are no registered senders for the type or if an error is returned from all of them.
func (*Manager) SetStubNotifiers ¶
func (mgr *Manager) SetStubNotifiers()
SetStubNotifiers will cause all notifications senders to be stubbed out.
This causes all notifications to be marked as delivered, but not actually sent.
type Message ¶
type Message interface {
ID() string
Type() MessageType
Destination() Dest
}
A Message contains information that can be provided to a user for notification.
type MessageResponse ¶
type MessageResponse struct {
Ctx context.Context
ID string
From Dest
Result Result
Err chan error
}
MessageResponse represents a received response from a user.
type MessageState ¶
type MessageState int
MessageState represents the current state of an outgoing message.
const ( // MessageStateSending should be specified when a message is sending but has not been sent. // This includes things like remotely queued, ringing, or in-progress calls. MessageStateSending MessageState = iota // MessageStatePending idicates a message waiting to be sent. MessageStatePending // MessageStateSent means the message has been sent completely, but may not // have been delivered (or delivery confirmation is not supported.). For // example, an SMS on the carrier network (but not device) or a voice call // that rang but got `no-answer`. MessageStateSent // MessageStateDelivered means the message is completed and was received // by the end device. SMS delivery confirmation, or a voice call was // completed (including if it was voice mail). MessageStateDelivered // MessageStateFailedTemp should be set when a message was not sent (no SMS or ringing phone) // but a subsequent try later may succeed. (e.g. voice call with busy signal). MessageStateFailedTemp // MessageStateFailedPerm should be set when a message was not sent (no SMS or ringing phone) // but a subsequent attempt will not be expected to succeed. For messages that fail due to // invalid config, they should set this state, as without manual intervention, a retry // will also fail. MessageStateFailedPerm )
type MessageStatus ¶
type MessageStatus struct {
// Ctx is the context of this status update (used for tracing if provided).
Ctx context.Context
// ID is the GoAlert message ID.
ID string
// ProviderMessageID is a string that represents the provider-specific ID of the message (e.g. Twilio SID).
ProviderMessageID string
// State is the current state.
State MessageState
// Details can contain any additional information about the State (e.g. "ringing", "no-answer" etc..).
Details string
// Sequence can be used when the provider sends updates out-of order (e.g. Twilio).
// The Sequence number defaults to 0, and a status update is ignored unless it's
// Sequence number is >= the current one.
Sequence int
}
MessageStatus represents the state of an outgoing message.
type MessageType ¶
type MessageType int
MessageType indicates the type of notification message.
const ( MessageTypeAlert MessageType = iota MessageTypeAlertStatus MessageTypeTest MessageTypeVerification MessageTypeAlertBundle MessageTypeAlertStatusBundle )
Allowed types
func (*MessageType) Scan ¶ added in v0.26.0
func (s *MessageType) Scan(value interface{}) error
func (MessageType) String ¶
func (i MessageType) String() string
type Receiver ¶
type Receiver interface {
UpdateStatus(context.Context, *MessageStatus) error
Receive(ctx context.Context, callbackID string, result Result) error
Start(context.Context, Dest) error
Stop(context.Context, Dest) error
}
A Receiver is something that can process a notification result.
type Result ¶
type Result int
Result specifies a response to a notification.
Possible notification responses.
type SendResponder ¶
type SendResponder interface {
Sender
ListenStatus() <-chan *MessageStatus
ListenResponse() <-chan *MessageResponse
}
A SendResponder can send messages and provide status and responses
type Sender ¶
type Sender interface {
// Send should return nil if the notification was sent successfully. It should be expected
// that a returned error means that the notification should be attempted again.
Send(context.Context, Message) (*MessageStatus, error)
Status(ctx context.Context, id, providerID string) (*MessageStatus, error)
}
A Sender is something that can send a notification.
type Store ¶
type Store interface {
SendContactMethodTest(ctx context.Context, cmID string) error
SendContactMethodVerification(ctx context.Context, cmID string) error
VerifyContactMethod(ctx context.Context, cmID string, code int) error
Code(ctx context.Context, id string) (int, error)
FindManyMessageStatuses(ctx context.Context, ids ...string) ([]MessageStatus, error)
// LastMessageStatus will return the MessageStatus and creation time of the most recent message of the requested type for the provided contact method ID, if one was created from the provided from time.
LastMessageStatus(ctx context.Context, typ MessageType, cmID string, from time.Time) (*MessageStatus, time.Time, error)
}
type Test ¶
type Test struct {
Dest Dest
CallbackID string // CallbackID is the identifier used to communicate a response to the notification
}
Test represents outgoing test notification.
func (Test) Destination ¶
func (Test) ExtendedBody ¶
func (Test) Type ¶
func (t Test) Type() MessageType
type Verification ¶
type Verification struct {
Dest Dest
CallbackID string // CallbackID is the identifier used to communicate a response to the notification
Code int
}
Verification represents outgoing verification code.
func (Verification) Body ¶
func (v Verification) Body() string
func (Verification) Destination ¶
func (v Verification) Destination() Dest
func (Verification) ExtendedBody ¶
func (v Verification) ExtendedBody() string
func (Verification) ID ¶
func (v Verification) ID() string
func (Verification) SubjectID ¶
func (v Verification) SubjectID() int
func (Verification) Type ¶
func (v Verification) Type() MessageType