notification

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateSending    = nfymsg.StateSending
	StateFailedPerm = nfymsg.StateFailedPerm
	StateFailedTemp = nfymsg.StateFailedTemp
	StateDelivered  = nfymsg.StateDelivered
	StateSent       = nfymsg.StateSent
	StateBundled    = nfymsg.StateBundled
	StateUnknown    = nfymsg.StateUnknown
	StatePending    = nfymsg.StatePending

	AlertStateUnknown        = nfymsg.AlertStateUnknown
	AlertStateUnacknowledged = nfymsg.AlertStateUnacknowledged
	AlertStateAcknowledged   = nfymsg.AlertStateAcknowledged
	AlertStateClosed         = nfymsg.AlertStateClosed
)
View Source
const (
	MessageTypeUnknown      = ""
	MessageTypeAlert        = gadb.EnumOutgoingMessagesTypeAlertNotification
	MessageTypeAlertStatus  = gadb.EnumOutgoingMessagesTypeAlertStatusUpdate
	MessageTypeTest         = gadb.EnumOutgoingMessagesTypeTestNotification
	MessageTypeVerification = gadb.EnumOutgoingMessagesTypeVerificationMessage
	MessageTypeAlertBundle  = gadb.EnumOutgoingMessagesTypeAlertNotificationBundle

	// MessageTypeAlertStatusBundle is used for bundled status messages.
	//
	// Deprecated: Alert status messages are no longer bundled, status bundle
	// messages are now dropped.
	MessageTypeAlertStatusBundle   = gadb.EnumOutgoingMessagesTypeAlertStatusUpdateBundle
	MessageTypeScheduleOnCallUsers = gadb.EnumOutgoingMessagesTypeScheduleOnCallNotification

	MessageTypeSignalMessage = gadb.EnumOutgoingMessagesTypeSignalMessage
)

Allowed types

Variables

View Source
var ErrStatusUnsupported = errors.New("status check unsupported by provider")

ErrStatusUnsupported should be returned when a Status() check is not supported by the provider.

Functions

This section is empty.

Types

type Alert

type Alert = nfymsg.Alert

type AlertBundle added in v0.24.0

type AlertBundle = nfymsg.AlertBundle

type AlertState added in v0.29.0

type AlertState = nfymsg.AlertState

type AlertStatus

type AlertStatus = nfymsg.AlertStatus

type DestID added in v0.33.0

type DestID struct {
	// CMID is the ID of the user contact method.
	CMID uuid.NullUUID
	// NCID is the ID of the notification channel.
	NCID uuid.NullUUID
}

func (DestID) IsUserCM added in v0.33.0

func (d DestID) IsUserCM() bool

func (DestID) String added in v0.33.0

func (d DestID) String() string

func (DestID) UUID added in v0.33.0

func (d DestID) UUID() uuid.UUID

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is used as an intermediary between Senders and Receivers. It should be constructed first (with NewManager()) and passed to Senders and Receivers that require it.

func NewManager

func NewManager(reg *nfydest.Registry) *Manager

NewManager initializes a new Manager.

func (*Manager) MessageStatus added in v0.28.0

func (mgr *Manager) MessageStatus(ctx context.Context, providerMsgID ProviderMessageID) (*Status, error)

MessageStatus will return the current status of a message.

func (*Manager) SendMessage added in v0.28.0

func (mgr *Manager) SendMessage(ctx context.Context, msg Message) (*SendResult, error)

SendMessage tries 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) SetResultReceiver added in v0.28.0

func (mgr *Manager) SetResultReceiver(ctx context.Context, recv ResultReceiver) error

SetResultReceiver will set the ResultReceiver as the target for all Receiver calls. It will panic if called multiple times.

type Message

type Message = nfymsg.Message

type MessageLog added in v0.30.1

type MessageLog struct {
	ID           string
	CreatedAt    time.Time
	LastStatusAt time.Time
	MessageType  gadb.EnumOutgoingMessagesType

	LastStatus    State
	StatusDetails string
	SrcValue      string

	AlertID       int
	ProviderMsgID *ProviderMessageID

	UserID   string
	UserName string

	ContactMethodID uuid.UUID

	ChannelID uuid.UUID

	ServiceID   string
	ServiceName string

	SentAt     *time.Time
	RetryCount int
}

type ProviderMessageID added in v0.28.0

type ProviderMessageID = gadb.ProviderMessageID

type Receiver

type Receiver interface {
	// SetMessageStatus can be used to update the state of a message.
	SetMessageStatus(ctx context.Context, externalID string, status *Status) error

	// Receive records a response to a previously sent message.
	Receive(ctx context.Context, callbackID string, result Result) error

	// ReceiveSubject records a response to a previously sent message from a provider/subject (e.g. Slack user).
	ReceiveSubject(ctx context.Context, providerID, subjectID, callbackID string, result Result) error

	// AuthLinkURL will generate a URL to link a provider and subject to a GoAlert user.
	AuthLinkURL(ctx context.Context, providerID, subjectID string, meta authlink.Metadata) (string, error)

	// Start indicates a user has opted-in for notifications to this contact method.
	Start(context.Context, gadb.DestV1) error

	// Stop indicates a user has opted-out of notifications from a contact method.
	Stop(context.Context, gadb.DestV1) error

	// IsKnownDest checks if the given destination is known/not disabled.
	IsKnownDest(ctx context.Context, dest gadb.DestV1) (bool, error)
}

A Receiver processes incoming messages and responses.

type ReceiverSetter added in v0.27.0

type ReceiverSetter interface {
	SetReceiver(Receiver)
}

ReceiverSetter is an optional interface a Sender can implement for use with two-way interactions.

type Result

type Result int

Result specifies a response to a notification.

const (
	ResultAcknowledge Result = iota
	ResultResolve
	ResultEscalate
)

Possible notification responses.

func (Result) String

func (i Result) String() string

type ResultReceiver added in v0.28.0

type ResultReceiver interface {
	SetSendResult(ctx context.Context, res *SendResult) error

	Receive(ctx context.Context, callbackID string, result Result) error
	ReceiveSubject(ctx context.Context, providerID, subjectID, callbackID string, result Result) error
	AuthLinkURL(ctx context.Context, providerID, subjectID string, meta authlink.Metadata) (string, error)
	Start(context.Context, gadb.DestV1) error
	Stop(context.Context, gadb.DestV1) error

	IsKnownDest(ctx context.Context, dest gadb.DestV1) (bool, error)
}

A ResultReceiver processes notification responses.

type ScheduleOnCallUsers added in v0.28.0

type ScheduleOnCallUsers = nfymsg.ScheduleOnCallUsers

type SearchCursor added in v0.30.1

type SearchCursor struct {
	ID        string    `json:"i,omitempty"`
	CreatedAt time.Time `json:"n,omitempty"`
}

SearchCursor is used to indicate a position in a paginated list.

type SearchOptions added in v0.30.1

type SearchOptions struct {
	Search string       `json:"s,omitempty"`
	After  SearchCursor `json:"a,omitempty"`

	CreatedAfter  time.Time `json:"ca,omitempty"`
	CreatedBefore time.Time `json:"cb,omitempty"`

	// Omit specifies a list of message IDs to exclude from the results
	Omit []string `json:"o,omitempty"`

	Limit int `json:"-"`
}

SearchOptions allow filtering and paginating the list of messages.

type SendResult added in v0.28.0

type SendResult = nfymsg.SendResult

type SentMessage added in v0.28.0

type SentMessage = nfymsg.SentMessage

type SignalMessage added in v0.33.0

type SignalMessage = nfymsg.SignalMessage

type State added in v0.28.0

type State = nfymsg.State

type Status added in v0.28.0

type Status = nfymsg.Status

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore added in v0.30.0

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

func (*Store) Code

func (s *Store) Code(ctx context.Context, id string) (int, error)

func (*Store) FindManyMessageStatuses added in v0.25.0

func (s *Store) FindManyMessageStatuses(ctx context.Context, strIDs []string) ([]SendResult, error)

func (*Store) LastMessageStatus added in v0.26.0

func (s *Store) LastMessageStatus(ctx context.Context, typ gadb.EnumOutgoingMessagesType, cmIDStr string, from time.Time) (*SendResult, time.Time, 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.

func (*Store) OriginalMessageStatus added in v0.28.0

func (s *Store) OriginalMessageStatus(ctx context.Context, alertID int, dstID DestID) (*SendResult, error)

OriginalMessageStatus will return the status of the first alert notification sent to `dest` for the given `alertID`.

func (*Store) Search added in v0.30.1

func (s *Store) Search(ctx context.Context, opts *SearchOptions) ([]MessageLog, error)

func (*Store) SendContactMethodTest

func (s *Store) SendContactMethodTest(ctx context.Context, id string) error

func (*Store) SendContactMethodVerification

func (s *Store) SendContactMethodVerification(ctx context.Context, cmID string) error

func (*Store) TimeSeries added in v0.31.0

func (s *Store) TimeSeries(ctx context.Context, opts TimeSeriesOpts) ([]TimeSeriesBucket, error)

TimeSeries returns a list of time series buckets for the given search options.

func (*Store) VerifyContactMethod

func (s *Store) VerifyContactMethod(ctx context.Context, cmID string, code int) error

type Test

type Test = nfymsg.Test

type TimeSeriesBucket added in v0.31.0

type TimeSeriesBucket struct {
	Start time.Time
	End   time.Time
	Count int
}

type TimeSeriesOpts added in v0.31.0

type TimeSeriesOpts struct {
	SearchOptions
	TimeSeriesOrigin   time.Time
	TimeSeriesInterval time.Duration
}

type UnknownSubjectError added in v0.30.0

type UnknownSubjectError struct {
	AlertID int
}

UnknownSubjectError is returned from ReceiveSubject when the subject is unknown.

func (UnknownSubjectError) Error added in v0.30.0

func (e UnknownSubjectError) Error() string

type User added in v0.28.0

type User = nfymsg.User

type Verification

type Verification = nfymsg.Verification

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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