notifications

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package notifications provides a client for interacting with the notifications API. It allows sending notifications through various channels and providers.

Index

Constants

View Source
const (
	// ParamUserID is the parameter name for user ID.
	ParamUserID = "userId"
	// ParamUserSecret is the parameter name for user secret.
	ParamUserSecret = "userSecret"
	// ParamSender is the parameter name for sender.
	ParamSender = "sender"

	// RecipientStatePending represents a pending recipient state.
	RecipientStatePending RecipientState = "pending"
	// RecipientStateSent represents a sent recipient state.
	RecipientStateSent RecipientState = "sent"
	// RecipientStateDelivered represents a delivered recipient state.
	RecipientStateDelivered RecipientState = "delivered"
	// RecipientStateError represents an error recipient state.
	RecipientStateError RecipientState = "error"

	// ChannelPhone represents the phone channel.
	ChannelPhone ChannelID = "phone"
	// ChannelEmail represents the email channel.
	ChannelEmail ChannelID = "email"
	// ChannelTelegram represents the telegram channel.
	ChannelTelegram ChannelID = "telegram"

	// FieldSubject is the field name for subject.
	FieldSubject = "subject"
	// FieldContentType is the field name for content type.
	FieldContentType = "contentType"
	// FieldInlineAttachments is the field name for inline attachments.
	FieldInlineAttachments = "inlineAttachments"

	// ContentTypeText represents text content type.
	ContentTypeText = "text"
	// ContentTypeHTML represents HTML content type.
	ContentTypeHTML = "html"
	// ContentTypeMarkdown represents markdown content type.
	ContentTypeMarkdown = "markdown"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	// ContentType is the content type
	ContentType string `json:"contentType"`
	// ContentBase64 is the content encoded in base64
	ContentBase64 string `json:"content"`
	// Name is the name
	Name string `json:"name"`
}

Attachment represents an attachment for a notification.

type Attachments

type Attachments []Attachment

Attachments is a slice of attachments.

type ChannelField

type ChannelField struct {
	// ID is the ID
	ID string `json:"id"`
	// Title is the title
	Title string `json:"title"`
	// Description is the description
	Description string `json:"description,omitempty"`
	// Regex is the regular expression for validation
	Regex string `json:"regex,omitempty"`
	// IsRequired indicates if it's required
	IsRequired bool `json:"isRequired"`
}

ChannelField represents a field in a notification channel.

type ChannelID

type ChannelID string

ChannelID represents the ID of a notification channel.

type ChannelInfo

type ChannelInfo struct {
	// ID is the ID
	ID ChannelID `json:"id"`
	// Title is the title
	Title string `json:"title"`
	// Fields are the additional fields
	Fields []ChannelField `json:"fields"`
}

ChannelInfo represents information about a notification channel.

type ChannelsResponse

type ChannelsResponse []ChannelInfo

ChannelsResponse is a slice of ChannelInfo.

type Client

type Client struct {
	*restkit.Client
	// contains filtered or unexported fields
}

Client represents a notifications API client.

func New

func New(config Config) (*Client, error)

New creates a new notifications client with the provided configuration.

func (*Client) GetChannels

func (c *Client) GetChannels(ctx context.Context) (ChannelsResponse, error)

GetChannels returns a list of available channels.

func (*Client) GetProviders

func (c *Client) GetProviders(ctx context.Context) (ProvidersResponse, error)

GetProviders returns a list of available providers.

func (*Client) SendNotification

func (c *Client) SendNotification(
	ctx context.Context,
	provider string,
	request NotificationRequest,
) (*NotificationResponse, error)

SendNotification sends a notification through the specified provider.

type Config

type Config struct {
	// BaseURL is the base URL of the notifications API
	BaseURL string
	// Username is the username for authentication
	Username string
	// Password is the password for authentication
	Password string

	// Client is the HTTP client to use (optional, will use http.DefaultClient if nil)
	Client *http.Client
}

Config represents the configuration for the notifications client.

type NotificationRequest

type NotificationRequest struct {
	// ID is the external ID
	ID *string `json:"id,omitempty"`
	// Recipients are the addresses of recipients
	Recipients []string `json:"recipients"`
	// Payload is the content of the notification
	Payload string `json:"payload"`
	// Options are notification parameters, when using multiple providers,
	// the provider name prefix with two underscores is used: `backend__`
	Options map[string]string `json:"options"`
	// Fields are additional fields specific to the sending channel
	Fields map[string]string `json:"fields"`
}

NotificationRequest represents a request to send a notification.

type NotificationResponse

type NotificationResponse struct {
	// UUID is the ID
	UUID string `json:"uuid"`
	// ID is the external ID
	ID *string `json:"id,omitempty"`
	// Recipients are the recipients
	Recipients []Recipient `json:"recipients"`
	// Success is the count of successful deliveries
	Success int `json:"success"`
	// Error is the count of errors
	Error int `json:"error"`
}

NotificationResponse represents the response from sending a notification.

type ParamsItem

type ParamsItem struct {
	// ID is the ID
	ID string `json:"id"`
	// Title is the title
	Title string `json:"title"`
	// Description is the description
	Description string `json:"description,omitempty"`
	// Regex is the regular expression for validation
	Regex string `json:"regex,omitempty"`
	// IsRequired indicates if it's required
	IsRequired bool `json:"isRequired"`
}

ParamsItem represents a parameter item.

type ProviderInfo

type ProviderInfo struct {
	// ID is the ID
	ID string `json:"id"`
	// Title is the title
	Title string `json:"title"`
	// Description is the description
	Description string `json:"description,omitempty"`
	// Help is the help information
	Help string `json:"help,omitempty"`
	// Channels are the channels
	Channels []ChannelID `json:"channels,omitempty"`
	// Params are the available parameters
	Params []ParamsItem `json:"params"`
}

ProviderInfo represents information about a notification provider.

type ProvidersResponse

type ProvidersResponse []ProviderInfo

ProvidersResponse is a slice of ProviderInfo.

type Recipient

type Recipient struct {
	// Address is the address
	Address string `json:"address"`
	// State is the state
	State RecipientState `json:"state" enums:"pending,sent,delivered,error"`
	// Error is the error text
	Error *string `json:"error,omitempty"`
}

Recipient represents a notification recipient.

type RecipientState

type RecipientState string

RecipientState represents the state of a notification recipient.

Jump to

Keyboard shortcuts

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