github.com/subosito/twilio@v0.0.1/examples_test.go (about) 1 package twilio_test 2 3 import ( 4 "fmt" 5 "github.com/subosito/twilio" 6 ) 7 8 // This example shows the usage of twilio package. You can get your AccountSid and AuthToken on Account Dashboard page. 9 func Example() { 10 // Common stuffs 11 AccountSid := "ac650108548e09aC2eed18ddb850c20b9" 12 AuthToken := "2ecaf74387cbb28456aad6fb57b5ad682" 13 from := "+15005550006" 14 to := "+62801234567" 15 callbackUrl := "http://subosito.com/" 16 17 // Initialize twilio client 18 t := twilio.NewTwilio(AccountSid, AuthToken) 19 20 // You can set custom Transport, eg: when you're using `appengine/urlfetch` on Google's appengine. 21 // c := appengine.NewContext(r) // r is a *http.Request 22 // t.Transport = urlfetch.Transport{Context: c} 23 24 // Send SMS 25 params := twilio.SMSParams{StatusCallback: callbackUrl} 26 s, err := t.SendSMS(from, to, "Hello Go!", params) 27 28 // or, make a voice call 29 // params := twilio.CallParams{Url: callbackUrl} 30 // s, err := t.MakeCall(from, to, params) 31 32 if err != nil { 33 fmt.Println(err) 34 return 35 } 36 37 fmt.Printf("%+v\n", s) 38 return 39 } 40 41 func ExampleTwilio_MakeCall() { 42 // Common stuffs 43 AccountSid := "ac650108548e09aC2eed18ddb850c20b9" 44 AuthToken := "2ecaf74387cbb28456aad6fb57b5ad682" 45 from := "+15005550006" 46 to := "+62801234567" 47 callbackUrl := "http://subosito.com/" 48 49 // Initialize twilio client 50 t := twilio.NewTwilio(AccountSid, AuthToken) 51 52 // Voice call 53 params := twilio.CallParams{Url: callbackUrl, Timeout: 90} 54 s, err := t.MakeCall(from, to, params) 55 56 if err != nil { 57 fmt.Println(err) 58 return 59 } 60 61 fmt.Printf("%+v\n", s) 62 return 63 }