Help us shape the future of Go! Take the 2026 Go Developer Survey

sms

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sms sends text messages, verification codes above all, through the provider the administrators configure. The providers live in the subpackages; Sender hides which one is in force and renders the message template for the providers that take a finished text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSupportedPlatforms

func GetSupportedPlatforms() []integration.Info

GetSupportedPlatforms describes the providers and their configuration fields for the administrators' settings page.

Types

type Message added in v1.21.0

type Message struct {
	// Area is the country calling code, without the plus sign ("86").
	Area string
	// Mobile is the number within the area.
	Mobile string
	// Params fill the message template: the text template kept in the
	// provider configuration, or for Alibaba Cloud the template approved on
	// the provider's side. A verification code travels as "code".
	Params map[string]string
}

Message is one text message to a phone number.

func CodeMessage added in v1.21.0

func CodeMessage(area, mobile, code string) Message

CodeMessage is the message that delivers a verification code.

type Platform

type Platform int

Platform is an SMS provider, stored in the configuration by its name.

const (
	AlibabaCloud Platform = iota
	Smsbao
	Abosend
	Twilio
)

The supported providers.

func (Platform) String

func (p Platform) String() string

String returns the name the configuration stores p under.

type Sender

type Sender interface {
	// Send delivers msg; ctx bounds the provider call.
	Send(ctx context.Context, msg Message) error
}

Sender delivers text messages through one provider account. It is safe for concurrent use.

func NewSender

func NewSender(platform, config string) (Sender, error)

NewSender builds the provider client for one provider configuration. config carries the provider credentials (access keys, auth tokens, passwords) and must never be logged. Callers that send repeatedly keep their sender in a Senders cache.

type Senders added in v1.21.0

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

Senders keeps the sender built for the provider configuration in force, rebuilding it when the configuration changes. The zero value is ready.

func (*Senders) Get added in v1.21.0

func (s *Senders) Get(platform, config string) (Sender, error)

Get returns the sender for platform and config.

Directories

Path Synopsis
Package abosend sends text messages through the Abosend HTTP API.
Package abosend sends text messages through the Abosend HTTP API.
Package alibabacloud sends text messages through Alibaba Cloud SMS, which fills a template approved on the provider's side.
Package alibabacloud sends text messages through Alibaba Cloud SMS, which fills a template approved on the provider's side.
Package smsbao sends text messages through the SMSBao HTTP API.
Package smsbao sends text messages through the SMSBao HTTP API.
Package twilio sends text messages through the Twilio API.
Package twilio sends text messages through the Twilio API.

Jump to

Keyboard shortcuts

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