twilio

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CallStatusUnknown    = CallStatus("")
	CallStatusInitiated  = CallStatus("initiated")
	CallStatusQueued     = CallStatus("queued")
	CallStatusRinging    = CallStatus("ringing")
	CallStatusInProgress = CallStatus("in-progress")
	CallStatusCompleted  = CallStatus("completed")
	CallStatusBusy       = CallStatus("busy")
	CallStatusFailed     = CallStatus("failed")
	CallStatusNoAnswer   = CallStatus("no-answer")
	CallStatusCanceled   = CallStatus("canceled")
)

Defined status values for voice calls.

View Source
const (
	MessageStatusUnknown     = MessageStatus("")
	MessageStatusAccepted    = MessageStatus("accepted")
	MessageStatusQueued      = MessageStatus("queued")
	MessageStatusSending     = MessageStatus("sending")
	MessageStatusSent        = MessageStatus("sent")
	MessageStatusReceiving   = MessageStatus("receiving")
	MessageStatusReceived    = MessageStatus("received")
	MessageStatusDelivered   = MessageStatus("delivered")
	MessageStatusUndelivered = MessageStatus("undelivered")
	MessageStatusFailed      = MessageStatus("failed")
)

Defined status values for messages.

View Source
const (
	MessageErrorCodeQueueOverflow       = MessageErrorCode(30001)
	MessageErrorCodeAccountSuspended    = MessageErrorCode(30002)
	MessageErrorCodeHandsetUnreachable  = MessageErrorCode(30003)
	MessageErrorCodeMessageBlocked      = MessageErrorCode(30004)
	MessageErrorCodeHandsetUnknown      = MessageErrorCode(30005)
	MessageErrorCodeLandlineUnreachable = MessageErrorCode(30006)
	MessageErrorCodeCarrierViolation    = MessageErrorCode(30007)
	MessageErrorCodeUnknown             = MessageErrorCode(30008)
	MessageErrorCodeMissingSegment      = MessageErrorCode(30009)
	MessageErrorCodeExceedsMaxPrice     = MessageErrorCode(30010)
)

Defined error codes for messages.

View Source
const (
	CallTypeAlert       = CallType("alert")
	CallTypeAlertStatus = CallType("alert-status")
	CallTypeTest        = CallType("test")
	CallTypeVerify      = CallType("verify")
	CallTypeStop        = CallType("stop")
)

Supported call types.

View Source
const DefaultTwilioAPIURL = "https://api.twilio.com/2010-04-01"

DefaultTwilioAPIURL is the value that will be used if Config.APIURL is empty.

Variables

This section is empty.

Functions

func Signature

func Signature(authToken, url string, fields url.Values) []byte

Signature will calculate the raw signature for a request from Twilio. https://www.twilio.com/docs/api/security#validating-requests

func WrapHeaderHack

func WrapHeaderHack(h http.Handler) http.Handler

WrapHeaderHack wraps an http.Handler so that a 204 is returned if the body is empty.

A Go 1.10 change removed the implicit header for responses with no content. Unfortunately Twilio logs empty responses (with no `Content-Type`) as 502s.

func WrapValidation

func WrapValidation(h http.Handler, c Config) http.Handler

WrapValidation will wrap an http.Handler to do X-Twilio-Signature checking.

Types

type Call

type Call struct {
	SID            string
	To             string
	From           string
	Status         CallStatus
	SequenceNumber *int
	Direction      string
	CallDuration   time.Duration
	ErrorMessage   *string
	ErrorCode      *CallErrorCode
}

Call represents a Twilio voice call.

type CallErrorCode

type CallErrorCode int

CallErrorCode is an error code encountered when making a call.

type CallStatus

type CallStatus string

CallStatus indicates the state of a voice call.

https://www.twilio.com/docs/api/twiml/twilio_request#request-parameters-call-status

func (*CallStatus) Scan

func (s *CallStatus) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

type CallType

type CallType string

CallType indicates a supported Twilio voice call type.

type Config

type Config struct {

	// APIURL can be used to override the Twilio API URL
	APIURL string

	// Client is an optional net/http client to use, if nil the global default is used.
	Client *http.Client
}

Config contains the details needed to interact with Twilio for SMS

func (*Config) GetSMS

func (c *Config) GetSMS(ctx context.Context, sid string) (*Message, error)

GetSMS will return the current state of a Message from Twilio.

func (*Config) GetVoice

func (c *Config) GetVoice(ctx context.Context, sid string) (*Call, error)

GetVoice will return the current state of a voice call from Twilio.

func (*Config) SendSMS

func (c *Config) SendSMS(ctx context.Context, to, body string, o *SMSOptions) (*Message, error)

SendSMS will send an SMS using Twilio.

func (*Config) StartVoice

func (c *Config) StartVoice(ctx context.Context, to string, o *VoiceOptions) (*Call, error)

StartVoice will initiate a voice call to the given number.

type Exception

type Exception struct {
	Status   int
	Message  string
	Code     int
	MoreInfo string `json:"more_info"`
}

Exception contains information on a Twilio error.

func (*Exception) Error

func (e *Exception) Error() string

type KeyPressed

type KeyPressed string

KeyPressed specifies a key pressed from the voice menu options.

type Message

type Message struct {
	SID          string
	To           string
	From         string
	Status       MessageStatus
	ErrorCode    *MessageErrorCode
	ErrorMessage *string
}

Message represents a Twilio message.

type MessageErrorCode

type MessageErrorCode int

A MessageErrorCode is a defined error code for Twilio messages.

https://www.twilio.com/docs/api/messaging/message#delivery-related-errors

type MessageStatus

type MessageStatus string

MessageStatus indicates the state of a message.

https://www.twilio.com/docs/api/messaging/message#message-status-values

func (*MessageStatus) Scan

func (s *MessageStatus) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

type SMS

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

SMS implements a notification.Sender for Twilio SMS.

func NewSMS

func NewSMS(ctx context.Context, db *sql.DB, c *Config) (*SMS, error)

NewSMS performs operations like validating essential parameters, registering the Twilio client and db and adding routes for successful and unsuccessful message delivery to Twilio

func (*SMS) ListenResponse

func (s *SMS) ListenResponse() <-chan *notification.MessageResponse

ListenResponse will return a channel that is fed async message responses.

func (*SMS) ListenStatus

func (s *SMS) ListenStatus() <-chan *notification.MessageStatus

ListenStatus will return a channel that is fed async status updates.

func (*SMS) Send

Send implements the notification.Sender interface.

func (*SMS) ServeMessage

func (s *SMS) ServeMessage(w http.ResponseWriter, req *http.Request)

func (*SMS) ServeStatusCallback

func (s *SMS) ServeStatusCallback(w http.ResponseWriter, req *http.Request)

func (*SMS) Status

func (s *SMS) Status(ctx context.Context, id, providerID string) (*notification.MessageStatus, error)

Status provides the current status of a message.

type SMSOptions

type SMSOptions struct {
	// ValidityPeriod controls how long a message will still be valid in Twilio's queue.
	ValidityPeriod time.Duration

	// CallbackParams will be added to callback URLs
	CallbackParams url.Values
}

SMSOptions allows configuring outgoing SMS messages.

func (*SMSOptions) StatusCallbackURL

func (sms *SMSOptions) StatusCallbackURL(cfg config.Config) (string, error)

StatusCallbackURL will return the status callback url for the given configuration.

type Voice

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

Voice implements a notification.Sender for Twilio voice calls.

func NewVoice

func NewVoice(ctx context.Context, db *sql.DB, c *Config) (*Voice, error)

NewVoice will send out the initial Call to Twilio, specifying all details needed for Twilio to make the first call to the end user It performs operations like validating essential parameters, registering the Twilio client and db and adding routes for successful and unsuccessful call connections to Twilio

func (*Voice) ListenResponse

func (v *Voice) ListenResponse() <-chan *notification.MessageResponse

ListenResponse will return a channel that is fed async message responses.

func (*Voice) ListenStatus

func (v *Voice) ListenStatus() <-chan *notification.MessageStatus

ListenStatus will return a channel that is fed async status updates.

func (*Voice) Send

Send implements the notification.Sender interface.

func (*Voice) ServeAlert

func (v *Voice) ServeAlert(w http.ResponseWriter, req *http.Request)

ServeAlert serves a call for an alert notification.

func (*Voice) ServeAlertStatus

func (v *Voice) ServeAlertStatus(w http.ResponseWriter, req *http.Request)

func (*Voice) ServeCall

func (v *Voice) ServeCall(w http.ResponseWriter, req *http.Request)

func (*Voice) ServeStatusCallback

func (v *Voice) ServeStatusCallback(w http.ResponseWriter, req *http.Request)

func (*Voice) ServeStop

func (v *Voice) ServeStop(w http.ResponseWriter, req *http.Request)

func (*Voice) ServeTest

func (v *Voice) ServeTest(w http.ResponseWriter, req *http.Request)

func (*Voice) ServeVerify

func (v *Voice) ServeVerify(w http.ResponseWriter, req *http.Request)

func (*Voice) Status

func (v *Voice) Status(ctx context.Context, id, providerID string) (*notification.MessageStatus, error)

Status provides the current status of a message.

type VoiceOptions

type VoiceOptions struct {
	// ValidityPeriod controls how long a message will still be valid in Twilio's queue.
	ValidityPeriod time.Duration

	// The call type/message.
	CallType CallType

	// CallbackParams will be added to all callback URLs
	CallbackParams url.Values

	// Params will be added to the voice callback URL
	Params url.Values
}

VoiceOptions allows configuring outgoing voice calls.

func (*VoiceOptions) CallbackURL

func (voice *VoiceOptions) CallbackURL(cfg config.Config) (string, error)

CallbackURL will return the callback url for the given configuration.

func (*VoiceOptions) StatusCallbackURL

func (voice *VoiceOptions) StatusCallbackURL(cfg config.Config) (string, error)

StatusCallbackURL will return the status callback url for the given configuration.

Jump to

Keyboard shortcuts

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