Documentation
ΒΆ
Overview ΒΆ
Package notification implements pluggable notification providers including SMTP email and Twilio WhatsApp, supporting multiple sender profiles and event-native routing.
Licensed under the MIT License.
Index ΒΆ
- Constants
- type CreateEventTriggerInput
- type EventTrigger
- type MockProvider
- type Module
- func (m *Module) CancelScheduledNotification(ctx context.Context, id string) (bool, error)
- func (m *Module) CreateEventTrigger(ctx context.Context, input CreateEventTriggerInput) (*EventTrigger, error)
- func (m *Module) DeleteEventTrigger(ctx context.Context, id string) (bool, error)
- func (m *Module) FieldResolvers() map[string]any
- func (m *Module) ID() string
- func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error
- func (m *Module) ListEventTriggers(ctx context.Context) ([]*EventTrigger, error)
- func (m *Module) ListNotifications(ctx context.Context, recipient *string) ([]*Notification, error)
- func (m *Module) ListScheduledNotifications(ctx context.Context) ([]*ScheduledNotification, error)
- func (m *Module) Models() []any
- func (m *Module) Mutations() map[string]any
- func (m *Module) Queries() map[string]any
- func (m *Module) Repo() *Repository
- func (m *Module) Routes() []mdk.Route
- func (m *Module) ScheduleNotification(ctx context.Context, input ScheduleNotificationInput) (*ScheduledNotification, error)
- func (m *Module) SendNotification(ctx context.Context, input any) (any, error)
- func (m *Module) SendNotificationStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) Shutdown(ctx context.Context) error
- type MultiChannelRoutingProvider
- type Notification
- type NotificationChannel
- type NotificationStatus
- type Provider
- type Repository
- type SMTPConfig
- type SMTPProvider
- type ScheduleNotificationInput
- type ScheduledNotification
- type TwilioWhatsappConfig
- type TwilioWhatsappProvider
Constants ΒΆ
const ( StatusPending NotificationStatus = "PENDING" StatusSent NotificationStatus = "SENT" StatusFailed NotificationStatus = "FAILED" ChannelEmail NotificationChannel = "EMAIL" ChannelSMS NotificationChannel = "SMS" ChannelWhatsapp NotificationChannel = "WHATSAPP" )
const Version = "0.4.0"
Version is the current version of the Hyperrr Notification Modules.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type CreateEventTriggerInput ΒΆ
type CreateEventTriggerInput struct {
Namespace string `json:"namespace"`
Event string `json:"event"`
Channel string `json:"channel"`
Sender *string `json:"sender,omitempty"`
RecipientTemplate string `json:"recipientTemplate"`
SubjectTemplate *string `json:"subjectTemplate,omitempty"`
BodyTemplate string `json:"bodyTemplate"`
}
type EventTrigger ΒΆ
type EventTrigger struct {
ID string `gorm:"primaryKey" json:"id"`
Namespace string `gorm:"index;not null" json:"namespace"`
Event string `gorm:"not null" json:"event"`
Channel string `gorm:"not null" json:"channel"`
Sender string `json:"sender"`
RecipientTemplate string `gorm:"not null" json:"recipient_template"`
SubjectTemplate string `json:"subject_template"`
BodyTemplate string `gorm:"not null" json:"body_template"`
Enabled bool `gorm:"default:true" json:"enabled"`
}
type MockProvider ΒΆ
type MockProvider struct {
ShouldFail bool
}
MockProvider is a simple provider for testing and development.
func (*MockProvider) Send ΒΆ
func (m *MockProvider) Send(ctx context.Context, n *Notification) error
type Module ΒΆ
type Module struct {
// contains filtered or unexported fields
}
Module implements the mdk.Module interface for Notification.
func (*Module) CancelScheduledNotification ΒΆ
func (*Module) CreateEventTrigger ΒΆ
func (m *Module) CreateEventTrigger(ctx context.Context, input CreateEventTriggerInput) (*EventTrigger, error)
func (*Module) DeleteEventTrigger ΒΆ
func (*Module) FieldResolvers ΒΆ
func (*Module) ListEventTriggers ΒΆ
func (m *Module) ListEventTriggers(ctx context.Context) ([]*EventTrigger, error)
func (*Module) ListNotifications ΒΆ
func (*Module) ListScheduledNotifications ΒΆ
func (m *Module) ListScheduledNotifications(ctx context.Context) ([]*ScheduledNotification, error)
func (*Module) Repo ΒΆ
func (m *Module) Repo() *Repository
func (*Module) ScheduleNotification ΒΆ
func (m *Module) ScheduleNotification(ctx context.Context, input ScheduleNotificationInput) (*ScheduledNotification, error)
func (*Module) SendNotification ΒΆ
SendNotification executes the notification delivery via the provider.
func (*Module) SendNotificationStep ΒΆ
func (m *Module) SendNotificationStep(sCtx mdk.StepContext) mdk.StepResult
SendNotificationStep wraps SendNotification to mdk.StepHandler.
type MultiChannelRoutingProvider ΒΆ
type MultiChannelRoutingProvider struct {
// contains filtered or unexported fields
}
MultiChannelRoutingProvider routes notifications to appropriate providers based on channel.
func NewMultiChannelRoutingProvider ΒΆ
func NewMultiChannelRoutingProvider(email, whatsapp Provider) *MultiChannelRoutingProvider
func (*MultiChannelRoutingProvider) Send ΒΆ
func (m *MultiChannelRoutingProvider) Send(ctx context.Context, n *Notification) error
type Notification ΒΆ
type Notification struct {
ID string `gorm:"primaryKey" json:"id"`
Sender string `json:"sender"` // e.g. "orders@mango.in", "support@mango.in" or "+14155552671"
Recipient string `gorm:"index;not null" json:"recipient"`
Channel NotificationChannel `gorm:"not null" json:"channel"`
Subject string `json:"subject"`
Body string `json:"body"`
Status NotificationStatus `gorm:"not null" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
Notification represents a message sent to a user.
type NotificationChannel ΒΆ
type NotificationChannel string
type NotificationStatus ΒΆ
type NotificationStatus string
type Provider ΒΆ
type Provider interface {
Send(ctx context.Context, n *Notification) error
}
Provider defines the interface for sending notifications.
type Repository ΒΆ
type Repository struct {
// contains filtered or unexported fields
}
Repository handles data access for notifications.
func NewRepository ΒΆ
func NewRepository(database *gorm.DB) *Repository
NewRepository creates a new Repository.
func (*Repository) GetByID ΒΆ
func (r *Repository) GetByID(ctx context.Context, id string) (*Notification, error)
GetByID retrieves a notification by its ID.
func (*Repository) List ΒΆ
func (r *Repository) List(ctx context.Context, recipient string) ([]*Notification, error)
List retrieves all notifications, optionally filtered by recipient.
func (*Repository) Save ΒΆ
func (r *Repository) Save(ctx context.Context, n *Notification) error
Save persists a notification to the database.
type SMTPConfig ΒΆ
type SMTPConfig struct {
Host string `json:"smtp_host"`
Port int `json:"smtp_port"`
Username string `json:"smtp_user"`
Password string `json:"smtp_pass"`
From string `json:"smtp_from"`
}
SMTPConfig holds SMTP server credentials.
type SMTPProvider ΒΆ
type SMTPProvider struct {
// contains filtered or unexported fields
}
SMTPProvider implements email delivery using net/smtp.
func NewSMTPProvider ΒΆ
func NewSMTPProvider(defaultConfig SMTPConfig, senders map[string]SMTPConfig) *SMTPProvider
func (*SMTPProvider) Send ΒΆ
func (s *SMTPProvider) Send(ctx context.Context, n *Notification) error
type ScheduleNotificationInput ΒΆ
type ScheduleNotificationInput struct {
Sender *string `json:"sender,omitempty"`
Recipient string `json:"recipient"`
Channel string `json:"channel"`
Subject *string `json:"subject,omitempty"`
Body string `json:"body"`
ScheduledAt time.Time `json:"scheduledAt"`
CronExpression *string `json:"cronExpression,omitempty"`
}
type ScheduledNotification ΒΆ
type ScheduledNotification struct {
ID string `gorm:"primaryKey" json:"id"`
Sender string `json:"sender"`
Recipient string `gorm:"not null" json:"recipient"`
Channel string `gorm:"not null" json:"channel"`
Subject string `json:"subject"`
Body string `gorm:"not null" json:"body"`
ScheduledAt time.Time `gorm:"index" json:"scheduled_at"`
CronExpression string `json:"cron_expression"`
Status string `gorm:"default:'PENDING'" json:"status"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type TwilioWhatsappConfig ΒΆ
type TwilioWhatsappConfig struct {
AccountSID string `json:"twilio_sid"`
AuthToken string `json:"twilio_token"`
From string `json:"twilio_from"`
}
TwilioWhatsappConfig holds Twilio API credentials.
type TwilioWhatsappProvider ΒΆ
type TwilioWhatsappProvider struct {
// contains filtered or unexported fields
}
TwilioWhatsappProvider implements WhatsApp message delivery using Twilio REST API.
func NewTwilioWhatsappProvider ΒΆ
func NewTwilioWhatsappProvider(defaultConfig TwilioWhatsappConfig, senders map[string]TwilioWhatsappConfig) *TwilioWhatsappProvider
func (*TwilioWhatsappProvider) Send ΒΆ
func (w *TwilioWhatsappProvider) Send(ctx context.Context, n *Notification) error