Documentation
¶
Overview ¶
Package twilio provides support for interacting with Twilio REST API
Example ¶
This example shows the usage of twilio package. You can get your AccountSid and AuthToken on Account Dashboard page.
package main
import (
"fmt"
"github.com/subosito/twilio"
)
func main() {
// Common stuffs
AccountSid := "ac650108548e09aC2eed18ddb850c20b9"
AuthToken := "2ecaf74387cbb28456aad6fb57b5ad682"
from := "+15005550006"
to := "+62801234567"
callbackUrl := "http://subosito.com/"
// Initialize twilio client
t := twilio.NewTwilio(AccountSid, AuthToken)
// You can set custom Transport, eg: when you're using `appengine/urlfetch` on Google's appengine.
// c := appengine.NewContext(r) // r is a *http.Request
// t.Transport = urlfetch.Transport{Context: c}
// Send SMS
params := twilio.SMSParams{StatusCallback: callbackUrl}
s, err := t.SendSMS(from, to, "Hello Go!", params)
// or, make a voice call
// params := twilio.CallParams{Url: callbackUrl}
// s, err := t.MakeCall(from, to, params)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", s)
return
}
Output:
Index ¶
- type CallParams
- type CallResponse
- type CallSipParams
- type Exception
- type Pagination
- type Parameter
- type Price
- type SMSListResponse
- type SMSParams
- type SMSResponse
- type Timestamp
- type Twilio
- func (t *Twilio) GetSMS(sid string) (s *SMSResponse, err error)
- func (t *Twilio) ListSMS(filters map[string]string) (sl *SMSListResponse, err error)
- func (t *Twilio) MakeCall(from, to string, p CallParams) (r *CallResponse, err error)
- func (t *Twilio) MakeSipCall(to string, p CallSipParams) (r *CallResponse, err error)
- func (t *Twilio) SendSMS(from, to, body string, p SMSParams) (s *SMSResponse, err error)
- func (t *Twilio) SimpleSendSMS(from, to, body string) (*SMSResponse, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallParams ¶
type CallResponse ¶
type CallResponse struct {
Sid string `json:"sid"`
DateCreated Timestamp `json:"date_created,omitempty"`
DateUpdated Timestamp `json:"date_updated,omitempty"`
ParentCallSid string `json:"parent_call_sid"`
AccountSid string `json:"account_sid"`
To string `json:"to"`
ToFormatted string `json:"to_formatted"`
From string `json:"from"`
FromFormatted string `json:"from_formatted"`
PhoneNumberSid string `json:"phone_number_sid"`
Status string `json:"status"`
StartTime Timestamp `json:"start_time,omitempty"`
EndTime Timestamp `json:"end_time,omitempty"`
Duration string `json:"duration,omitempty"`
Price Price `json:"price,omitempty"`
Direction string `json:"direction"`
AnsweredBy string `json:"answered_by,omitempty"`
ApiVersion string `json:"api_version"`
ForwardedFrom string `json:"forwarded_from,omitempty"`
CallerName string `json:"caller_name,omitempty"`
Uri string `json:"uri"`
SubresourceUris struct {
Notifications string `json:"notifications"`
Recordings string `json:"recordings"`
} `json:"subresource_uris"`
}
type CallSipParams ¶
type Exception ¶
type Exception struct {
Status int `json:"status"`
Message string `json:"message"`
Code int `json:"code"`
MoreInfo string `json:"more_info"`
}
Exception holds information about error response returned by Twilio API
type Pagination ¶
type Pagination struct {
Start int `json:"start"`
Total int `json:"total"`
NumPages int `json:"num_pages"`
Page int `json:"page"`
PageSize int `json:"page_size"`
End int `json:"end"`
Uri string `json:"uri"`
FirstPageUri string `json:"first_page_uri"`
LastPageUri string `json:"last_page_uri"`
NextPageUri string `json:"next_page_uri"`
PreviousPageUri string `json:"previous_page_uri"`
}
type SMSListResponse ¶
type SMSListResponse struct {
Pagination
SMSMessages []SMSResponse
}
type SMSResponse ¶
type SMSResponse struct {
AccountSid string `json:"account_sid"`
ApiVersion string `json:"api_version"`
Body string `json:"body"`
DateCreated Timestamp `json:"date_created,omitempty"`
DateSent Timestamp `json:"date_sent,omitempty"`
DateUpdated Timestamp `json:"date_updated,omitempty"`
Direction string `json:"direction"`
From string `json:"from"`
Price Price `json:"price,omitempty"`
Sid string `json:"sid"`
Status string `json:"status"`
To string `json:"to"`
Uri string `json:"uri"`
}
type Timestamp ¶
func (*Timestamp) UnmarshalJSON ¶
type Twilio ¶
type Twilio struct {
AccountSid string
AuthToken string
BaseUrl string
// Transport is the HTTP transport to use when making requests.
// It will default to http.DefaultTransport if nil
Transport http.RoundTripper
}
func (*Twilio) ListSMS ¶
func (t *Twilio) ListSMS(filters map[string]string) (sl *SMSListResponse, err error)
Returns a list of SMS messages associates with your account. It's support list filters via `map[string]string`:
"To" : Only show SMS messages to this phone number "From" : Only show SMS messages from this phone number "DateSent" : Only show SMS messages sent on this date (in GMT format), given as `YYYY-MM-DD`.
func (*Twilio) MakeCall ¶
func (t *Twilio) MakeCall(from, to string, p CallParams) (r *CallResponse, err error)
Make a voice call. You need to set one of `Url` or `ApplicationSid` parameter on `CallParams`
Example ¶
package main
import (
"fmt"
"github.com/subosito/twilio"
)
func main() {
// Common stuffs
AccountSid := "ac650108548e09aC2eed18ddb850c20b9"
AuthToken := "2ecaf74387cbb28456aad6fb57b5ad682"
from := "+15005550006"
to := "+62801234567"
callbackUrl := "http://subosito.com/"
// Initialize twilio client
t := twilio.NewTwilio(AccountSid, AuthToken)
// Voice call
params := twilio.CallParams{Url: callbackUrl, Timeout: 90}
s, err := t.MakeCall(from, to, params)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", s)
return
}
Output:
func (*Twilio) MakeSipCall ¶
func (t *Twilio) MakeSipCall(to string, p CallSipParams) (r *CallResponse, err error)
func (*Twilio) SendSMS ¶
func (t *Twilio) SendSMS(from, to, body string, p SMSParams) (s *SMSResponse, err error)
Send SMS with more verbose options. It's support optional parameters.
StatusCallback : A URL that Twilio will POST to when your message is processed. ApplicationSid : Twilio will POST `SMSSid` as well as other statuses to the URL in the `SMSStatusCallback` property of this application
func (*Twilio) SimpleSendSMS ¶
func (t *Twilio) SimpleSendSMS(from, to, body string) (*SMSResponse, error)
Simple version of Send SMS with no optional parameters support.
Click to show internal directories.
Click to hide internal directories.
