sms

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sms defines interfaces for sending SMS text messages.

Although exported, this package is non intended for general consumption. It is a shared dependency between multiple exposure notifications projects. We cannot guarantee that there won't be breaking changes in the future.

Index

Constants

View Source
const TwilioMessagingServiceSidPrefix = "MG"

TwilioMessagingServiceSidPrefix is the prefix for a 34 character messaging service identifier

Variables

View Source
var ErrNoop error = errors.New("noop always fails")

ErrNoop is the error NoopFail always returns.

Functions

func IsSMSQueueFull added in v0.20.0

func IsSMSQueueFull(err error) bool

IsSMSQueueFull returns if the given error is Twilio's message queue full error.

func IsTwilioCode added in v0.20.0

func IsTwilioCode(err error, code int) bool

IsTwilioCode returns if the given error matches a Twilio error code.

Types

type Config

type Config struct {
	ProviderType ProviderType

	// Twilio options
	TwilioAccountSid string
	TwilioAuthToken  string
	TwilioFromNumber string
}

Config represents configuration for an SMS provider.

type Noop

type Noop struct{}

Noop does nothing.

func (*Noop) SendSMS

func (p *Noop) SendSMS(_ context.Context, _, _ string) error

SendSMS does nothing.

type NoopFail added in v0.19.0

type NoopFail struct{}

NoopFail always fails.

func (*NoopFail) SendSMS added in v0.19.0

func (p *NoopFail) SendSMS(_ context.Context, _, _ string) error

SendSMS does nothing.

type Provider

type Provider interface {
	// SendSMS sends an SMS text message from the given number to the given number
	// with the provided message.
	SendSMS(ctx context.Context, to, message string) error
}

func NewNoop

func NewNoop(_ context.Context) (Provider, error)

NewNoop creates a new SMS sender that does nothing.

func NewNoopFail added in v0.19.0

func NewNoopFail(_ context.Context) (Provider, error)

NewNoopFail creates a new SMS sender that only returns ErrNoop.

func NewTwilio

func NewTwilio(ctx context.Context, accountSid, authToken, from string) (Provider, error)

NewTwilio creates a new Twilio SMS sender with the given auth.

func ProviderFor

func ProviderFor(ctx context.Context, c *Config) (Provider, error)

type ProviderType

type ProviderType string

ProviderType represents a type of SMS provider.

const (
	ProviderTypeNoop     ProviderType = "NOOP"
	ProviderTypeNoopFail ProviderType = "NOOP_FAIL"
	ProviderTypeTwilio   ProviderType = "TWILIO"
)

type Twilio

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

Twilio sends messages via the Twilio API.

func (*Twilio) SendSMS

func (p *Twilio) SendSMS(ctx context.Context, to, message string) error

SendSMS sends a message using the Twilio API.

type TwilioError

type TwilioError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

TwilioError represents an error returned from the Twilio API.

func (*TwilioError) Error

func (e *TwilioError) Error() string

Jump to

Keyboard shortcuts

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