Documentation ¶
Index ¶
- Constants
- Variables
- 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 CarrierInfo
- type Config
- func (c *Config) CarrierInfo(ctx context.Context, number string, fetch bool) (*CarrierInfo, error)
- func (c Config) FetchCarrierInfo(ctx context.Context, number string) (*CarrierInfo, error)
- 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) FriendlyValue(ctx context.Context, value string) (string, error)
- func (s *SMS) Send(ctx context.Context, msg notification.Message) (*notification.SentMessage, error)
- func (s *SMS) ServeMessage(w http.ResponseWriter, req *http.Request)
- func (s *SMS) ServeStatusCallback(w http.ResponseWriter, req *http.Request)
- func (s *SMS) SetReceiver(r notification.Receiver)
- func (s *SMS) Status(ctx context.Context, externalID string) (*notification.Status, error)
- type SMSOptions
- type Voice
- func (v *Voice) FriendlyValue(ctx context.Context, value string) (string, error)
- func (v *Voice) Send(ctx context.Context, msg notification.Message) (*notification.SentMessage, 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) ServeInbound(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) SetReceiver(r notification.Receiver)
- func (v *Voice) Status(ctx context.Context, externalID string) (*notification.Status, 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 ( // Supported call types. CallTypeAlert = CallType("alert") CallTypeAlertStatus = CallType("alert-status") CallTypeTest = CallType("test") CallTypeVerify = CallType("verify") CallTypeStop = CallType("stop") )
const DefaultLookupURL = "https://lookups.twilio.com"
DefaultLookupURL is the value that will be used for lookup calls if Config.BaseURL is empty.
const DefaultTwilioAPIURL = "https://api.twilio.com"
DefaultTwilioAPIURL is the value that will be used for API calls if Config.BaseURL is empty.
Variables ¶
var ErrCarrierStale = errors.New("carrier data is stale")
ErrCarrierStale is returned if the available carrier data is over a year old.
ErrCarrierUnavailable is returned if the carrier data is missing and fetch is disabled.
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 CarrierInfo ¶ added in v0.25.0
type CarrierInfo struct { Name string `json:"name"` Type string `json:"type"` MobileNetworkCode string `json:"mobile_network_code"` MobileCountryCode string `json:"mobile_country_code"` }
CarrierInfo holds information about the carrier network for a particular number.
type Config ¶
type Config struct { // BaseURL can be used to override the Twilio API and Lookup URL bases. BaseURL string // Client is an optional net/http client to use, if nil the global default is used. Client *http.Client // CMStore is used for storing and fetching metadata (like carrier information). CMStore *contactmethod.Store }
Config contains the details needed to interact with Twilio for SMS
func (*Config) CarrierInfo ¶ added in v0.25.0
CarrierInfo will return carrier information for the provided number. If fetch is true, it will fetch data from the Twilio API if it is not available from the DB.
func (Config) FetchCarrierInfo ¶ added in v0.25.0
FetchCarrierInfo will lookup carrier information for the provided number using the Twilio API.
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 MessagingServiceSID string `json:"messaging_service_sid"` }
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) FriendlyValue ¶ added in v0.28.0
FriendlyValue will return the international formatting of the phone number.
func (*SMS) Send ¶
func (s *SMS) Send(ctx context.Context, msg notification.Message) (*notification.SentMessage, 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) SetReceiver ¶ added in v0.27.0
func (s *SMS) SetReceiver(r notification.Receiver)
SetReceiver sets the notification.Receiver for incoming messages and status updates.
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 // FromNumber allows overriding the specified FromNumber instead of using the context config. FromNumber string }
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) FriendlyValue ¶ added in v0.28.0
FriendlyValue will return the international formatting of the phone number.
func (*Voice) Send ¶
func (v *Voice) Send(ctx context.Context, msg notification.Message) (*notification.SentMessage, 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) ServeInbound ¶ added in v0.29.0
func (v *Voice) ServeInbound(w http.ResponseWriter, req *http.Request)
ServeInbound is the handler for inbound calls.
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) SetReceiver ¶ added in v0.27.0
func (v *Voice) SetReceiver(r notification.Receiver)
SetReceiver sets the notification.Receiver for incoming calls and status updates.
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.