twilio

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package twilio delivers AuthKit's text messages through Twilio Messaging (email goes through adapters/smtp).

sms, err := twilio.NewSMS(twilio.SMSConfig{
	AccountSID:          os.Getenv("TWILIO_ACCOUNT_SID"),
	AuthToken:           os.Getenv("TWILIO_AUTH_TOKEN"),
	MessagingServiceSID: os.Getenv("TWILIO_MESSAGING_SERVICE_SID"),
	AppName:             "MyApp",
})
if err != nil {
	return err
}
deps := authkit.Deps{Postgres: db, Email: email, SMS: sms}

It renders every message kind from a built-in template in the message's Language (Spanish for "es", else English). Set Render to supply your own body for some kinds; returning false falls back to the built-in one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SMS

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

SMS delivers AuthKit's text messages through the Twilio Messaging API and confirms delivery before Send returns. It is an authkit.SMSSender: wire it as authkit.Deps.SMS.

func NewSMS

func NewSMS(cfg SMSConfig) (*SMS, error)

NewSMS validates cfg and returns an SMS.

func (*SMS) CheckHealth

func (s *SMS) CheckHealth(ctx context.Context) error

CheckHealth reports, without sending an SMS, whether Twilio will refuse this sender. It fails when the credentials, account or Messaging Service are refused, the service has no sender, or every sender is a toll-free number without an approved verification (error 30032). A network error or 5xx on those lookups fails too; the next check re-arms. Anything else it can't tell counts as healthy. Refused toll-free senders beside working ones, and senders it can't tell about, log a warning on slog.Default, once per change.

func (*SMS) Send

func (s *SMS) Send(ctx context.Context, msg iam.SMSMessage) error

Send renders msg (Render, else the built-in template for msg.Kind), sends it and waits up to 12s for a delivery verdict: a definite failure is an error, a message still in flight is not.

type SMSConfig

type SMSConfig struct {
	AccountSID          string
	AuthToken           string
	MessagingServiceSID string
	// AppName names the app in the built-in copy (default "Auth").
	AppName string
	// Client sends the API requests (default: a 10s-timeout client).
	Client *http.Client
	// DeliveryPollInterval is the gap between delivery status polls (default
	// 750ms).
	DeliveryPollInterval time.Duration
	// Render returns the body for msg, or false to use the built-in template
	// for msg.Kind.
	Render func(ctx context.Context, msg iam.SMSMessage) (string, bool)
}

SMSConfig configures NewSMS. AccountSID, AuthToken and MessagingServiceSID are required.

Jump to

Keyboard shortcuts

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