Documentation
¶
Index ¶
- Variables
- func GetCharacterCount(templateName string, data *TemplateData) (int, error)
- func ListTemplates() []string
- func ValidateTemplate(templateName string) error
- type MockSMSMessage
- type MockSMSProvider
- func (p *MockSMSProvider) ClearSentMessages()
- func (p *MockSMSProvider) GetSentMessages() []MockSMSMessage
- func (p *MockSMSProvider) GetStatus(ctx context.Context, providerID string) (notification.NotificationStatus, error)
- func (p *MockSMSProvider) ID() string
- func (p *MockSMSProvider) Send(ctx context.Context, notif *notification.Notification) error
- func (p *MockSMSProvider) Type() notification.NotificationType
- func (p *MockSMSProvider) Validate() error
- func (p *MockSMSProvider) ValidateConfig() error
- type Provider
- type RenderedTemplate
- type Template
- type TemplateData
- type TwilioConfig
- type TwilioErrorResponse
- type TwilioMessageResponse
- type TwilioProvider
- func (p *TwilioProvider) GetStatus(ctx context.Context, providerID string) (notification.NotificationStatus, error)
- func (p *TwilioProvider) ID() string
- func (p *TwilioProvider) Send(ctx context.Context, notif *notification.Notification) error
- func (p *TwilioProvider) Type() notification.NotificationType
- func (p *TwilioProvider) Validate() error
- func (p *TwilioProvider) ValidateConfig() error
Constants ¶
This section is empty.
Variables ¶
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 ¶
ValidateTemplate validates that a template renders correctly with sample data
Types ¶
type MockSMSMessage ¶
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) Send ¶
func (p *MockSMSProvider) Send(ctx context.Context, notif *notification.Notification) error
Send sends a mock SMS notification
func (*MockSMSProvider) Type ¶
func (p *MockSMSProvider) Type() notification.NotificationType
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 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 ¶
Template represents an SMS template
func GetTemplate ¶
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) Send ¶
func (p *TwilioProvider) Send(ctx context.Context, notif *notification.Notification) error
Send sends an SMS notification
func (*TwilioProvider) Type ¶
func (p *TwilioProvider) Type() notification.NotificationType
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