notifications

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package notifications provides functionality to manage and send notifications. It includes support for email and SMS notifications, with configurations for each type.

Email and SMS senders are implemented as interfaces, allowing for different implementations. Every implementation must have a config object, which is passed during initialization.

Index

Constants

This section is empty.

Variables

View Source
var EmailEnabled = false

EmailEnabled indicates whether email notifications are enabled.

View Source
var ErrEmailSenderNotSet = fmt.Errorf("email sender is not set, please set it using the config file! notifications.email.provider and the respective provider config")
View Source
var SMSEnabled = false

SMSEnabled indicates whether SMS notifications are enabled.

Functions

func InitEmail

func InitEmail()

InitEmail initializes the email sender based on the configuration. If the email sender is not configured, it logs a warning and skips initialization.

Sets EmailEnabled to true if the email sender is configured.

func InitSMS

func InitSMS()

func SendAdminLoginEmail

func SendAdminLoginEmail(ctx context.Context, params SendAdminLoginEmailParams) error

SendAdminLoginEmail sends an admin login email to the specified recipient. It uses the global EmailSender instance to send the email. The email includes the OTP code and its expiration time.

func SendLowBackupCodesEmail

func SendLowBackupCodesEmail(ctx context.Context, email string, params LowBackupCodesEmailParams) error

SendLowBackupCodesEmail sends an email to the user when they have a low number of backup codes left. It uses the global EmailSender instance to send the email.

func SendMFAEmailOTP

func SendMFAEmailOTP(ctx context.Context, email string, params MFAEmailOTPParams) error

func SendOrgInvitationEmail

func SendOrgInvitationEmail(ctx context.Context, email string, orgName string, verificationToken string, expiresAt time.Time, existingUser bool) error

func SendResetPasswordEmail

func SendResetPasswordEmail(ctx context.Context, email string, params SendResetPasswordEmailParams) error

SendResetPasswordEmail sends a password reset email to the specified recipient. It uses the global EmailSender instance to send the email. The email also includes a link to reset the password.

func SendVerificationEmail

func SendVerificationEmail(ctx context.Context, email string, params SendVerificationEmailParams) error

SendVerificationEmail sends a verification email to the specified recipient. It uses the global EmailSender instance to send the email. The email also includes a link to verify the email address.

Types

type EmailSenderInterface

type EmailSenderInterface interface {
	SendEmail(to string, subject string, htmlContent, plainTextContent string) error // SendEmail sends an email to the specified recipient with the given subject and body.
}
var EmailSender EmailSenderInterface // EmailSender is the global email sender instance.

type LowBackupCodesEmailParams

type LowBackupCodesEmailParams struct {
	UserName           string
	NumBackupCodesLeft int
}

type MFAEmailOTPParams

type MFAEmailOTPParams struct {
	OTP       string
	ExpiresAt time.Time
}

type SESEmailSender

type SESEmailSender struct {
	Client      *sesv2.Client
	FromAddress string
	FromName    string
}

func NewSESEmailSender

func NewSESEmailSender(region, accessKeyId, secretAccessKey, fromAddress string, fromName *string) *SESEmailSender

func (*SESEmailSender) SendEmail

func (s *SESEmailSender) SendEmail(to string, subject, htmlContent, plainTextContent string) error

SendEmail sends an email using AWS SES.

type SMSSenderInterface

type SMSSenderInterface interface {
	SendSMS(to string, message string) error // SendSMS sends an SMS to the specified recipient with the given message.
}
var SMSSender SMSSenderInterface // SMSSender is the global SMS sender instance.

type SMTPEmailSender

type SMTPEmailSender struct {
	Host        string
	Port        string
	FromAddress string
	FromName    string
	Password    string
}

func NewSMTPEmailSender

func NewSMTPEmailSender(host, port, fromAddress, fromName, password string) *SMTPEmailSender

func (*SMTPEmailSender) SendEmail

func (s *SMTPEmailSender) SendEmail(to string, subject, htmlContent, plainTextContent string) error

SendEmail sends an email using SMTP.

type SMTPSenderError

type SMTPSenderError struct {
	ErrorString string
	StatusCode  int
}

func (*SMTPSenderError) Error

func (e *SMTPSenderError) Error() string

type SendAdminLoginEmailParams

type SendAdminLoginEmailParams struct {
	Email     string
	Code      string
	ExpiresAt time.Time
}

type SendGridEmailSender

type SendGridEmailSender struct {
	Client *sendgrid.Client
	// FromAddress is the email address from which notifications are sent.
	FromAddress string
	// FromName is the name associated with the FromAddress. If not given, it defaults to the `config.Application.Name`.
	FromName string
}

SendGridEmailSender implements the EmailSenderInterface using SendGrid for sending emails.

func NewSendGridEmailSender

func NewSendGridEmailSender(apiKey string, fromAddress string, fromName *string) *SendGridEmailSender

func (*SendGridEmailSender) SendEmail

func (s *SendGridEmailSender) SendEmail(to string, subject, htmlContent, plainTextContent string) error

SendEmail sends an email using the SendGrid API.

type SendGridSenderError

type SendGridSenderError struct {
	Body       string
	StatusCode int
}

SendGridSenderError implements the error interface for SendGrid errors.

func (*SendGridSenderError) Error

func (e *SendGridSenderError) Error() string

type SendResetPasswordEmailParams

type SendResetPasswordEmailParams struct {
	UserName  string
	Token     string
	ExpiresAt time.Time
}

type SendVerificationEmailParams

type SendVerificationEmailParams struct {
	UserName          string
	VerificationToken string
	ExpiresAt         time.Time
}

Directories

Path Synopsis
Package templates provides the templates for notifications.
Package templates provides the templates for notifications.

Jump to

Keyboard shortcuts

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