Documentation ¶
Index ¶
- Constants
- func Signature(authToken, url string, fields url.Values) []byte
- func WrapHeaderHack(h http.Handler) http.Handler
- func WrapValidation(h http.Handler, c Config) http.Handler
- type Call
- type CallErrorCode
- type CallStatus
- type CallType
- type Config
- func (c *Config) GetSMS(ctx context.Context, sid string) (*Message, error)
- func (c *Config) GetVoice(ctx context.Context, sid string) (*Call, error)
- func (c *Config) SendSMS(ctx context.Context, to, body string, o *SMSOptions) (*Message, error)
- func (c *Config) StartVoice(ctx context.Context, to string, o *VoiceOptions) (*Call, error)
- type Exception
- type KeyPressed
- type Message
- type MessageErrorCode
- type MessageStatus
- type SMS
- func (s *SMS) ListenResponse() <-chan *notification.MessageResponse
- func (s *SMS) ListenStatus() <-chan *notification.MessageStatus
- func (s *SMS) Send(ctx context.Context, msg notification.Message) (*notification.MessageStatus, error)
- func (s *SMS) ServeMessage(w http.ResponseWriter, req *http.Request)
- func (s *SMS) ServeStatusCallback(w http.ResponseWriter, req *http.Request)
- func (s *SMS) Status(ctx context.Context, id, providerID string) (*notification.MessageStatus, error)
- type SMSOptions
- type Voice
- func (v *Voice) ListenResponse() <-chan *notification.MessageResponse
- func (v *Voice) ListenStatus() <-chan *notification.MessageStatus
- func (v *Voice) Send(ctx context.Context, msg notification.Message) (*notification.MessageStatus, error)
- func (v *Voice) ServeAlert(w http.ResponseWriter, req *http.Request)
- func (v *Voice) ServeAlertStatus(w http.ResponseWriter, req *http.Request)
- func (v *Voice) ServeCall(w http.ResponseWriter, req *http.Request)
- func (v *Voice) ServeStatusCallback(w http.ResponseWriter, req *http.Request)
- func (v *Voice) ServeStop(w http.ResponseWriter, req *http.Request)
- func (v *Voice) ServeTest(w http.ResponseWriter, req *http.Request)
- func (v *Voice) ServeVerify(w http.ResponseWriter, req *http.Request)
- func (v *Voice) Status(ctx context.Context, id, providerID string) (*notification.MessageStatus, error)
- type VoiceOptions
Constants ¶
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.
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.
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.
const ( CallTypeAlert = CallType("alert") CallTypeAlertStatus = CallType("alert-status") CallTypeTest = CallType("test") CallTypeVerify = CallType("verify") CallTypeStop = CallType("stop") )
Supported call types.
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 ¶
Signature will calculate the raw signature for a request from Twilio. https://www.twilio.com/docs/api/security#validating-requests
func WrapHeaderHack ¶
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.
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 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) StartVoice ¶
StartVoice will initiate a voice call to the given number.
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 ¶
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 ¶
func (s *SMS) Send(ctx context.Context, msg notification.Message) (*notification.MessageStatus, error)
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 ¶
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 ¶
func (v *Voice) Send(ctx context.Context, msg notification.Message) (*notification.MessageStatus, error)
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) ServeStatusCallback ¶
func (v *Voice) ServeStatusCallback(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.