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 ¶
- Variables
- func InitEmail()
- func InitSMS()
- func SendAdminLoginEmail(ctx context.Context, params SendAdminLoginEmailParams) error
- func SendLowBackupCodesEmail(ctx context.Context, email string, params LowBackupCodesEmailParams) error
- func SendMFAEmailOTP(ctx context.Context, email string, params MFAEmailOTPParams) error
- func SendOrgInvitationEmail(ctx context.Context, email string, orgName string, verificationToken string, ...) error
- func SendResetPasswordEmail(ctx context.Context, email string, params SendResetPasswordEmailParams) error
- func SendVerificationEmail(ctx context.Context, email string, params SendVerificationEmailParams) error
- type EmailSenderInterface
- type LowBackupCodesEmailParams
- type MFAEmailOTPParams
- type SESEmailSender
- type SMSSenderInterface
- type SMTPEmailSender
- type SMTPSenderError
- type SendAdminLoginEmailParams
- type SendGridEmailSender
- type SendGridSenderError
- type SendResetPasswordEmailParams
- type SendVerificationEmailParams
Constants ¶
This section is empty.
Variables ¶
var EmailEnabled = false
EmailEnabled indicates whether email notifications are enabled.
var ErrEmailSenderNotSet = fmt.Errorf("email sender is not set, please set it using the config file! notifications.email.provider and the respective provider config")
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 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 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 MFAEmailOTPParams ¶
type SESEmailSender ¶
func NewSESEmailSender ¶
func NewSESEmailSender(region, accessKeyId, secretAccessKey, fromAddress string, fromName *string) *SESEmailSender
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
type SMTPSenderError ¶
func (*SMTPSenderError) Error ¶
func (e *SMTPSenderError) Error() string
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
type SendGridSenderError ¶
SendGridSenderError implements the error interface for SendGrid errors.
func (*SendGridSenderError) Error ¶
func (e *SendGridSenderError) Error() string