notification

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 13 Imported by: 0

README ΒΆ

notification β€” Hyperrr Pluggable Notification Module

Go Reference

This repository contains the standalone, pluggable notification and messaging providers for the Hyperrr engine. It includes support for SMTP email sending, Twilio WhatsApp integration, multi-channel routing, and multiple sender profiles (e.g. orders@mango.in, support@mango.in).


πŸ“¬ Features

  • SMTP Email Provider: Sends HTML and plain-text emails via standard net/smtp.
  • Multi-profile Sender Support: Dynamically routes messages using different sender profiles and credentials depending on context (e.g., support vs. sales vs. transactional notifications).
  • Twilio WhatsApp Provider: Integrates with Twilio for WhatsApp messaging campaigns and notifications.
  • Multi-Channel Router: Intelligently routes notifications to email, WhatsApp, or both based on preferences and recipient endpoints.
  • Event-Native Workflows: Reacts automatically to platform events (such as user registrations or order completion status) via the Hyperrr event bus.

πŸ› οΈ Usage

This module is imported by the core Hyperrr engine and registers its notification models, routes, and step handlers during runtime initialization.

To learn more about how to configure notification profiles or build custom channels, see the Hyperrr Developer Guide.

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 ΒΆ

View Source
const (
	StatusPending NotificationStatus = "PENDING"
	StatusSent    NotificationStatus = "SENT"
	StatusFailed  NotificationStatus = "FAILED"

	ChannelEmail    NotificationChannel = "EMAIL"
	ChannelSMS      NotificationChannel = "SMS"
	ChannelWhatsapp NotificationChannel = "WHATSAPP"
)
View Source
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 NewModule ΒΆ

func NewModule(provider Provider) *Module

func (*Module) CancelScheduledNotification ΒΆ

func (m *Module) CancelScheduledNotification(ctx context.Context, id string) (bool, error)

func (*Module) CreateEventTrigger ΒΆ

func (m *Module) CreateEventTrigger(ctx context.Context, input CreateEventTriggerInput) (*EventTrigger, error)

func (*Module) DeleteEventTrigger ΒΆ

func (m *Module) DeleteEventTrigger(ctx context.Context, id string) (bool, error)

func (*Module) FieldResolvers ΒΆ

func (m *Module) FieldResolvers() map[string]any

func (*Module) ID ΒΆ

func (m *Module) ID() string

func (*Module) Init ΒΆ

func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error

func (*Module) ListEventTriggers ΒΆ

func (m *Module) ListEventTriggers(ctx context.Context) ([]*EventTrigger, error)

func (*Module) ListNotifications ΒΆ

func (m *Module) ListNotifications(ctx context.Context, recipient *string) ([]*Notification, error)

func (*Module) ListScheduledNotifications ΒΆ

func (m *Module) ListScheduledNotifications(ctx context.Context) ([]*ScheduledNotification, error)

func (*Module) Models ΒΆ

func (m *Module) Models() []any

func (*Module) Mutations ΒΆ

func (m *Module) Mutations() map[string]any

func (*Module) Queries ΒΆ

func (m *Module) Queries() map[string]any

func (*Module) Repo ΒΆ

func (m *Module) Repo() *Repository

func (*Module) Routes ΒΆ

func (m *Module) Routes() []mdk.Route

func (*Module) ScheduleNotification ΒΆ

func (m *Module) ScheduleNotification(ctx context.Context, input ScheduleNotificationInput) (*ScheduledNotification, error)

func (*Module) SendNotification ΒΆ

func (m *Module) SendNotification(ctx context.Context, input any) (any, error)

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.

func (*Module) Shutdown ΒΆ

func (m *Module) Shutdown(ctx context.Context) error

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 ΒΆ

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 ΒΆ

Jump to

Keyboard shortcuts

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