notification

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

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) Body

func (a Alert) Body() string

func (Alert) Destination

func (a Alert) Destination() Dest

func (Alert) ExtendedBody

func (a Alert) ExtendedBody() string

func (Alert) ID

func (a Alert) ID() string

func (Alert) SubjectID

func (a Alert) SubjectID() int

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

type AlertStatus struct {
	Dest       Dest
	CallbackID string
	AlertID    int
	LogEntry   string
}

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 NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

func (*DB) Code

func (db *DB) Code(ctx context.Context, id string) (int, error)

func (*DB) FindManyMessageStatuses added in v0.25.0

func (db *DB) FindManyMessageStatuses(ctx context.Context, ids ...string) ([]MessageStatus, error)

func (*DB) LastMessageStatus added in v0.26.0

func (db *DB) LastMessageStatus(ctx context.Context, typ MessageType, cmID string, from time.Time) (*MessageStatus, time.Time, error)

func (*DB) SendContactMethodTest

func (db *DB) SendContactMethodTest(ctx context.Context, id string) error

func (*DB) SendContactMethodVerification

func (db *DB) SendContactMethodVerification(ctx context.Context, cmID string) error

func (*DB) VerifyContactMethod

func (db *DB) VerifyContactMethod(ctx context.Context, cmID string, code int) error

type Dest

type Dest struct {
	ID    string
	Type  DestType
	Value string
}

type DestType

type DestType int
const (
	DestTypeUnknown DestType = iota
	DestTypeVoice
	DestTypeSMS
	DestTypeSlackChannel
)

func (DestType) IsUserCM

func (t DestType) IsUserCM() bool

IsUserCM returns true if the DestType represents a user contact method.

func (DestType) String

func (i DestType) String() string

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 NewManager

func NewManager() *Manager

NewManager initializes a new Manager.

func (*Manager) RegisterReceiver

func (m *Manager) RegisterReceiver(r Receiver)

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

func (m *Manager) Send(ctx context.Context, msg Message) (*MessageStatus, error)

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.

func (*Manager) Shutdown

func (m *Manager) Shutdown(context.Context) error

Shutdown will stop the manager, waiting for pending background operations to finish.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context, id, providerMsgID string) (*MessageStatus, error)

Status will return the current status of a message.

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

func (MessageType) Value added in v0.26.0

func (s MessageType) Value() (driver.Value, error)

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.

const (
	ResultAcknowledge Result = iota
	ResultResolve
	ResultStart
	ResultStop
)

Possible notification responses.

func (Result) String

func (i Result) String() string

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) Body

func (t Test) Body() string

func (Test) Destination

func (t Test) Destination() Dest

func (Test) ExtendedBody

func (t Test) ExtendedBody() string

func (Test) ID

func (t Test) ID() string

func (Test) SubjectID

func (t Test) SubjectID() int

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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