Documentation
¶
Index ¶
Constants ¶
const ( TwilioSID = "TWILIO_SID" TwilioAuthToken = "TWILIO_AUTH_TOKEN" TwilioPhoneNumber = "TWILIO_PHONE_NUMBER" )
Environment variable keys
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client manages our requests
type Request ¶
type Request struct {
ToCity string `url:"ToCity"`
FromZip int `url:"FromZip"`
MessageSID string `url:"MessageSID"`
SMSMessageSID string `url:"SMSMessageSID"`
ToCountry string `url:"ToCountry"`
FromCountry string `url:"FromCountry"`
ToZip string `url:"ToZip"`
FromState string `url:"FromState"`
SMSStatus string `url:"SMSStatus"` // should maybe be an enum?
FromCity string `url:"FromCity"`
Body string `url:"Body"`
To string `url:"To"`
AccountSID string `url:"AccountSID"`
NumMedia int `url:"NumMedia"`
From string `url:"From"`
SMSSid string `url:"SMSSid"`
NumSegments int `url:"NumSegments"`
}
Request represents an request to a Twilio webhook. These seem to always come in as a standard set of key/value form pairs (as opposed to JSON).
func NewDecoder ¶
NewDecoder is simply a wrapper around `Request.Decode()`. Use it like so:
req, _ := twilio.NewDecoder(htmlRequest)
fmt.Println("Hey look, this message is from", req.From)
type Response ¶
type Response struct {
// Error indicates weather or not the response was an error. This is not
// part of a normal Twilio response: we added it ourselves to remove some
// ambigulity in our repsonses
Error bool `json:"error"`
// Found only in error responses
Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"`
MoreInfo string `json:"more_info,omitempty"`
// This is an ambigulous response. If the response is an error, this is an
// `int`, otherwise this is a `string` (often "queued"). To deal with this
// curious API design we don't export this and instead process the response
// into either `.HTTPStatusCode` for errors or `.MessageStatus` for
// successes.
Status interface{} `json:"status,omitempty"`
// HTTPStatusCode is the JSON `status` key in error responses. It will not
// be set in success responses.
HTTPStatusCode int `json:"http_status_code,omitempty"`
// MessageStatus is the JSON `status` key in success responses. It will not
// be set in error responses.
MessageStatus string `json:"message_status,omitempty"`
// Time strings we need to parse separately
DateCreated string `json:"date_created,omitempty"`
DateUpdated string `json:"date_updated,omitempty"`
DateSent string `json:"date_sent,omitempty"`
// Parsed time strings
Created *time.Time `json:"created,omitempty"`
Updated *time.Time `json:"updated,omitempty"`
Sent *time.Time `json:"sent,omitempty"`
// Found in success responses
SID string `json:"sid,omitempty"`
AccountSID string `json:"account_sid,omitempty"`
To string `json:"to,omitempty"`
From string `json:"from,omitempty"`
MessagingServiceSID string `json:"messaging_service_sid,omitempty"`
Body string `json:"body,omitempty"`
NumSegments string `json:"num_segments,omitempty"` // Twilio, why is this a string?
NumMedia string `json:"num_media,omitempty"` // Twilio, why is this a string?
Direction string `json:"direction,omitempty"`
APIVersion string `json:"api_version,omitempty"`
Price string `json:"price,omitempty"`
PriceUnit string `json:"price_unit,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
ErrorMesssage string `json:"error_messsage,omitempty"`
URI string `json:"uri,omitempty"`
SubResourceURIs map[string]string `json:"sub_resource_uris,omitempty"`
}
Response contains values in a Twilio success response received after sending an SMS.
func SendSMS ¶
SendSMS sends an SMS. We expect the following environment varaibles to be set: TWILIO_SID, TWILIO_AUTH_TOKEN, TWILIO_PHONE_NUMBER.
To send an SMS without using environment variables, see `Client`.
func (Response) CheckError ¶
CheckError checks the response object for an error. If we recieved one, return an error
func (*Response) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshalling for this struct. We do it here to handle the ambiguity of certain fields.