notifiers

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

Notifiers

Notifiers is a shared library — not a standalone service. It provides the core logic for managing notifier records and delivering notifications, and is consumed by the SMTP Notifier and SMPP Notifier services. It is composed of two layers:

  1. Notifier manager — an HTTP API for creating, updating, listing, and removing notifier records. Notifiers are group-scoped: each notifier belongs to a group and carries a list of contact addresses (emails, phone numbers, etc.).
  2. Sender backends — pluggable delivery implementations that consume broker messages and send notifications to the contacts defined on the relevant notifiers. Two backends are provided: SMTP (email) and SMPP (SMS).

Data Model

Field Type Description
id UUID Unique notifier identifier
group_id UUID Group this notifier belongs to
name string Human-readable notifier name
contacts []string Delivery addresses (emails, phone numbers, etc.)
metadata JSON object Arbitrary metadata

Sender Backends

Each backend is a separate binary that subscribes to the broker and dispatches notifications:

Backend Binary Protocol Contacts format
SMTP mainfluxlabs-smtp-notifier Email user@example.com
SMPP mainfluxlabs-smpp-notifier SMS +1234567890

See the individual backend READMEs for configuration details:

Deployment

This package is a shared library and does not have its own binary. Deploy the individual sender backends:

Usage

Start a sender backend to begin consuming messages from the broker and dispatching notifications to the contacts listed on the relevant notifiers. The notifier manager HTTP API can be used independently to manage notifier records.

Documentation

Overview

Package notifiers contain the domain concept definitions needed to support Mainflux notifications functionality.

Index

Constants

This section is empty.

Variables

View Source
var AllowedOrders = map[string]string{
	"id":   "id",
	"name": "name",
}
View Source
var ErrNotify = errors.New("failed to send notification")

ErrNotify wraps sending notification errors,

Functions

This section is empty.

Types

type Notifier

type Notifier struct {
	ID       string
	GroupID  string
	Name     string
	Contacts []string
	Metadata map[string]any
}

type NotifierRepository

type NotifierRepository interface {
	// Save persists multiple notifiers. Notifiers are saved using a transaction.
	// If one notifier fails then none will be saved.
	// Successful operation is indicated by non-nil error response.
	Save(ctx context.Context, nfs ...Notifier) ([]Notifier, error)

	// RetrieveByGroup retrieves notifiers related to a certain group,
	// identified by a given ID.
	RetrieveByGroup(ctx context.Context, groupID string, pm PageMetadata) (NotifiersPage, error)

	// RetrieveByID retrieves the notifier having the provided ID.
	RetrieveByID(ctx context.Context, id string) (Notifier, error)

	// Update performs an update to the existing notifier.
	// A non-nil error is returned to indicate operation failure.
	Update(ctx context.Context, n Notifier) error

	// Remove removes notifiers having the provided IDs.
	Remove(ctx context.Context, ids ...string) error

	// RemoveByGroup removes notifiers related to a certain group,
	// identified by a given group ID.
	RemoveByGroup(ctx context.Context, groupID string) error
}

NotifierRepository specifies a notifier persistence API.

type NotifiersPage added in v0.28.1

type NotifiersPage struct {
	Total     uint64
	Notifiers []Notifier
}

type PageMetadata added in v0.39.0

type PageMetadata struct {
	Total    uint64         `json:"total,omitempty"`
	Offset   uint64         `json:"offset,omitempty"`
	Limit    uint64         `json:"limit,omitempty"`
	Order    string         `json:"order,omitempty"`
	Dir      string         `json:"dir,omitempty"`
	Name     string         `json:"name,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

PageMetadata contains page metadata that helps navigation.

func (PageMetadata) Validate added in v0.39.0

func (pm PageMetadata) Validate(maxLimitSize, maxNameSize int) error

Validate validates the page metadata.

type Sender added in v0.28.1

type Sender interface {
	// Send method is used to send notification for the
	// received message to the provided list of receivers.
	Send(to []string, msg protomfx.Message) error

	// ValidateContacts method is used to validate contacts
	// to which notifications will be sent.
	ValidateContacts(contacts []string) error
}

Sender represents an API for sending notification.

type Service

type Service interface {
	// CreateNotifiers creates notifiers for a certain group identified by the group ID.
	CreateNotifiers(ctx context.Context, token, groupID string, notifiers ...Notifier) ([]Notifier, error)

	// ListNotifiersByGroup retrieves data about a subset of notifiers
	// related to a certain group, identified by the provided group ID.
	ListNotifiersByGroup(ctx context.Context, token string, groupID string, pm PageMetadata) (NotifiersPage, error)

	// ViewNotifier retrieves data about the notifier identified with the provided ID.
	ViewNotifier(ctx context.Context, token, id string) (Notifier, error)

	// UpdateNotifier updates the notifier identified by the provided ID.
	UpdateNotifier(ctx context.Context, token string, notifier Notifier) error

	// RemoveNotifiers removes notifiers identified with the provided IDs.
	RemoveNotifiers(ctx context.Context, token string, id ...string) error

	// RemoveNotifiersByGroup removes notifiers related to the specified group,
	// identified by the provided group ID.
	RemoveNotifiersByGroup(ctx context.Context, groupID string) error

	consumers.MessageConsumer
}

Service represents a notification service. All methods that accept a token parameter use it to identify and authorize the user performing the operation.

func New

func New(idp uuid.IDProvider, sender Sender, notifierRepo NotifierRepository, things domain.ThingsClient) Service

New instantiates the subscriptions service implementation.

Directories

Path Synopsis
api
Package smpp contains the domain concept definitions needed to support Mainflux SMS notifications.
Package smpp contains the domain concept definitions needed to support Mainflux SMS notifications.
Package smtp contains the domain concept definitions needed to support Mainflux SMTP notifications.
Package smtp contains the domain concept definitions needed to support Mainflux SMTP notifications.

Jump to

Keyboard shortcuts

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