sms

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTemplates = map[string]*Template{
	"verification": {
		Name: "verification",
		Body: `{{.AppName}}: Your verification code is {{.VerificationCode}}. This code expires in {{.ExpiryTime}}. If you didn't request this, please ignore this message.`,
	},

	"two_factor": {
		Name: "two_factor",
		Body: `{{.AppName}}: Your 2FA code is {{.VerificationCode}}. This code expires in {{.ExpiryTime}}. Do not share this code with anyone.`,
	},

	"password_reset": {
		Name: "password_reset",
		Body: `{{.AppName}}: Your password reset code is {{.ResetCode}}. This code expires in {{.ExpiryTime}}. If you didn't request this, please contact support.`,
	},

	"login_code": {
		Name: "login_code",
		Body: `{{.AppName}}: Your login code is {{.LoginCode}}. This code expires in {{.ExpiryTime}}. Use this code to complete your sign-in.`,
	},

	"login_notification": {
		Name: "login_notification",
		Body: `{{.AppName}}: New login detected from {{.Location}} at {{.Timestamp}}. If this wasn't you, secure your account immediately.`,
	},

	"account_locked": {
		Name: "account_locked",
		Body: `{{.AppName}}: Your account has been temporarily locked due to suspicious activity. Contact support at {{.SupportPhone}} if you need assistance.`,
	},

	"device_verification": {
		Name: "device_verification",
		Body: `{{.AppName}}: New device login detected: {{.DeviceName}} from {{.Location}}. Your verification code is {{.VerificationCode}}. Expires in {{.ExpiryTime}}.`,
	},

	"password_changed": {
		Name: "password_changed",
		Body: `{{.AppName}}: Your password was successfully changed at {{.Timestamp}}. If you didn't make this change, contact support immediately.`,
	},

	"phone_verification": {
		Name: "phone_verification",
		Body: `{{.AppName}}: Verify your phone number with code {{.VerificationCode}}. This code expires in {{.ExpiryTime}}.`,
	},

	"backup_codes": {
		Name: "backup_codes",
		Body: `{{.AppName}}: Your backup codes have been regenerated. Make sure to save them in a secure location. Generated at {{.Timestamp}}.`,
	},
}

DefaultTemplates contains the default SMS templates

Functions

func GetCharacterCount

func GetCharacterCount(templateName string, data *TemplateData) (int, error)

GetCharacterCount returns the character count for a rendered template

func ListTemplates

func ListTemplates() []string

ListTemplates returns all available template names

func ValidateTemplate

func ValidateTemplate(templateName string) error

ValidateTemplate validates that a template renders correctly with sample data

Types

type MockSMSMessage

type MockSMSMessage struct {
	Recipient string
	Subject   string
	Body      string
}

MockSMSMessage represents a sent SMS message for testing

type MockSMSProvider

type MockSMSProvider struct {
	SentMessages []MockSMSMessage
}

MockSMSProvider is a mock SMS provider for testing

func NewMockSMSProvider

func NewMockSMSProvider() *MockSMSProvider

NewMockSMSProvider creates a new mock SMS provider

func (*MockSMSProvider) ClearSentMessages

func (p *MockSMSProvider) ClearSentMessages()

ClearSentMessages clears all sent messages

func (*MockSMSProvider) GetSentMessages

func (p *MockSMSProvider) GetSentMessages() []MockSMSMessage

GetSentMessages returns all sent messages

func (*MockSMSProvider) GetStatus

func (p *MockSMSProvider) GetStatus(ctx context.Context, providerID string) (notification.NotificationStatus, error)

GetStatus returns the status (always delivered for mock)

func (*MockSMSProvider) ID

func (p *MockSMSProvider) ID() string

ID returns the provider ID

func (*MockSMSProvider) Send

Send sends a mock SMS notification

func (*MockSMSProvider) Type

Type returns the notification type this provider handles

func (*MockSMSProvider) Validate

func (p *MockSMSProvider) Validate() error

Validate validates the mock provider (always valid)

func (*MockSMSProvider) ValidateConfig

func (p *MockSMSProvider) ValidateConfig() error

ValidateConfig validates the mock provider (always valid)

type Provider

type Provider interface {
	SendSMS(to, message string) error
}

Provider defines minimal SMS sending capabilities used by phone plugin

type RenderedTemplate

type RenderedTemplate struct {
	Body string
}

RenderedTemplate represents a rendered SMS template

func RenderTemplate

func RenderTemplate(templateName string, data *TemplateData) (*RenderedTemplate, error)

RenderTemplate renders an SMS template with the provided data

type Template

type Template struct {
	Name string
	Body string
}

Template represents an SMS template

func GetTemplate

func GetTemplate(name string) (*Template, bool)

GetTemplate returns a template by name

type TemplateData

type TemplateData struct {
	UserName         string
	UserEmail        string
	OrganizationName string
	VerificationCode string
	ResetCode        string
	LoginCode        string
	IPAddress        string
	DeviceName       string
	Location         string
	Timestamp        string
	ExpiryTime       string
	AppName          string
	SupportPhone     string
}

TemplateData represents data passed to SMS templates

type TwilioConfig

type TwilioConfig struct {
	AccountSID string `json:"account_sid"`
	AuthToken  string `json:"auth_token"`
	FromNumber string `json:"from_number"`
	BaseURL    string `json:"base_url"`
}

TwilioConfig holds Twilio configuration

type TwilioErrorResponse

type TwilioErrorResponse struct {
	Code     int    `json:"code"`
	Message  string `json:"message"`
	MoreInfo string `json:"more_info"`
	Status   int    `json:"status"`
}

TwilioErrorResponse represents a Twilio error response

type TwilioMessageResponse

type TwilioMessageResponse struct {
	Sid          string `json:"sid"`
	Status       string `json:"status"`
	ErrorCode    int    `json:"error_code"`
	ErrorMessage string `json:"error_message"`
}

TwilioMessageResponse represents a Twilio message response

type TwilioProvider

type TwilioProvider struct {
	// contains filtered or unexported fields
}

TwilioProvider implements notification.Provider for Twilio SMS

func NewTwilioProvider

func NewTwilioProvider(config TwilioConfig) *TwilioProvider

NewTwilioProvider creates a new Twilio SMS provider

func (*TwilioProvider) GetStatus

func (p *TwilioProvider) GetStatus(ctx context.Context, providerID string) (notification.NotificationStatus, error)

GetStatus gets the delivery status of a notification from Twilio

func (*TwilioProvider) ID

func (p *TwilioProvider) ID() string

ID returns the provider ID

func (*TwilioProvider) Send

Send sends an SMS notification

func (*TwilioProvider) Type

Type returns the notification type this provider handles

func (*TwilioProvider) Validate

func (p *TwilioProvider) Validate() error

Validate validates the provider configuration

func (*TwilioProvider) ValidateConfig

func (p *TwilioProvider) ValidateConfig() error

ValidateConfig validates the provider configuration

Jump to

Keyboard shortcuts

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