Documentation ¶
Index ¶
- type Alert
- type AlertStatus
- type DB
- func (db *DB) Code(ctx context.Context, id string) (int, error)
- func (db *DB) CodeExpiration(ctx context.Context, id string) (t *time.Time, err error)
- func (db *DB) SendContactMethodTest(ctx context.Context, id string) error
- func (db *DB) SendContactMethodVerification(ctx context.Context, id string, resend bool) error
- func (db *DB) VerifyContactMethod(ctx context.Context, cmID string, code int) ([]string, 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 AlertStatus ¶
func (AlertStatus) Body ¶
func (s AlertStatus) Body() string
func (AlertStatus) Destination ¶
func (s AlertStatus) Destination() Dest
func (AlertStatus) ExtendedBody ¶
func (s AlertStatus) ExtendedBody() string
func (AlertStatus) ID ¶
func (s AlertStatus) ID() string
func (AlertStatus) SubjectID ¶
func (s AlertStatus) SubjectID() int
func (AlertStatus) Type ¶
func (s AlertStatus) Type() MessageType
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) CodeExpiration ¶
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 SubjectID() int Body() string ExtendedBody() string }
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 ( // MessageStateActive should be specified when a message is still active. // This includes things like remotely queued, ringing, or in-progress calls. MessageStateActive MessageState = iota // 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 )
Allowed types
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 Stop(context.Context, Dest) error }
A Receiver is something that can process a notification result.
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, resend bool) error VerifyContactMethod(ctx context.Context, cmID string, code int) ([]string, error) CodeExpiration(ctx context.Context, cmID string) (*time.Time, error) Code(ctx context.Context, id string) (int, 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