sms

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sms sends outbound SMS messages and ingests delivery-report callbacks.

SMSService is the entry point. Build it with NewSMSService, then register one or more SMSProvider implementations with RegisterProvider; the service holds them by name and resolves them at send time. SMSRequest carries the recipient list, message body, sender ID, and a typed ProviderOptions map for any provider-specific extras; the response is SMSResponse with a typed ProviderData field.

Delivery reports are handled separately. Africa's Talking POSTs them as form-encoded requests; DeliveryReport is the parsed shape and DeliveryReportHandler dispatches each report to a callback (or, by default, to a structured slog entry). Build the handler with NewDeliveryReportHandler and override the default sink with WithReportHandler. Phone numbers are redacted before they reach logs.

Provider implementations live under providers/. Today that is providers/africastalking, the Africa's Talking HTTP adapter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeliveryReport

type DeliveryReport struct {
	ID            string // AT message ID (matches messageId from send response)
	Status        string // Sent|Submitted|Buffered|Rejected|Success|Failed|AbsentSubscriber|Expired
	PhoneNumber   string
	NetworkCode   string
	FailureReason string // Only present if Rejected or Failed
}

DeliveryReport represents an SMS delivery report callback from Africa's Talking. AT sends these as form-encoded POST requests to the configured callback URL.

func (DeliveryReport) IsFinalStatus

func (d DeliveryReport) IsFinalStatus() bool

IsFinalStatus returns true if the delivery status is terminal (no further updates expected).

type DeliveryReportHandler

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

DeliveryReportHandler processes SMS delivery report callbacks.

func NewDeliveryReportHandler

func NewDeliveryReportHandler(opts ...DeliveryReportOption) *DeliveryReportHandler

NewDeliveryReportHandler creates a new DeliveryReportHandler. By default it logs reports using structured logging.

func (*DeliveryReportHandler) HandleReport

func (h *DeliveryReportHandler) HandleReport(ctx context.Context, report DeliveryReport)

HandleReport processes a single delivery report.

type DeliveryReportOption

type DeliveryReportOption func(*DeliveryReportHandler)

DeliveryReportOption configures a DeliveryReportHandler.

func WithReportHandler

func WithReportHandler(fn func(ctx context.Context, report DeliveryReport)) DeliveryReportOption

WithReportHandler sets a custom handler function for delivery reports.

type SMSProvider

type SMSProvider interface {
	// SendSMS sends an SMS message using the provided context and request.
	SendSMS(ctx context.Context, req SMSRequest) (SMSResponse, error)

	// SendSingleSMS sends a single SMS message using the provided context, recipient, message, and sender.
	SendSingleSMS(ctx context.Context, to string, message string, from string) (SMSResponse, error)

	// SendBulkSMS sends a bulk SMS message using the provided context, recipients, message, and sender.
	SendBulkSMS(ctx context.Context, to []string, message string, from string) (SMSResponse, error)
}

SMSProvider is an interface for sending SMS messages.

type SMSRequest

type SMSRequest struct {
	To              string
	ToMultiple      []string
	Message         string
	From            string
	ProviderOptions map[string]any // Provider-specific options
}

SMSRequest represents an SMS message request.

type SMSResponse

type SMSResponse struct {
	ProviderData any // Provider-specific response data
}

SMSResponse represents an SMS message response.

type SMSService

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

SMSService is a service for managing SMS providers.

func NewSMSService

func NewSMSService() *SMSService

NewSMSService creates a new SMS service.

func (*SMSService) DeleteProvider

func (s *SMSService) DeleteProvider(name string) error

DeleteProvider deletes a registered SMS provider by name.

func (*SMSService) DeleteProviders

func (s *SMSService) DeleteProviders() error

DeleteProviders deletes all registered SMS providers.

func (*SMSService) GetProvider

func (s *SMSService) GetProvider(name string) (SMSProvider, error)

GetProvider retrieves an SMS provider by name.

func (*SMSService) GetProviders

func (s *SMSService) GetProviders() map[string]SMSProvider

GetProviders retrieves all registered SMS providers.

func (*SMSService) RegisterProvider

func (s *SMSService) RegisterProvider(name string, provider SMSProvider)

RegisterProvider registers an SMS provider with the service.

Directories

Path Synopsis
providers

Jump to

Keyboard shortcuts

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