Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

natebrennand/twiliogo

Repository files navigation

Twilio Go

alt text Build Status

Write Twilio applications with our Go helper library. To get started, there are some example applications in the examples folder.

All Twilio API calls are validated at runtime to insure that all necesary information is provided.

You can generate a callback parser for all Twilio callbacks that will publish the parsed callbacks into a channel. See the SMS example below for an example of how this works.

Installation

go get github.com/natebrennand/twiliogo

Usage

Linking your account(s)

You can manage your credentials either through environment variables or manually setting them. The library will panic if you attempt to input an invalid AccountSid or token.

Environment Variables

export TWILIO_ACCOUNT="accountsid"
export TWILIO_TOKEN="accounttoken"
act := twilogo.NewAccountFromEnv()

Manual Setting

act := twiliogo.NewAccount("AccountSid", "AccountToken")

Making a call

act := twilogo.NewAccountFromEnv()

resp, err := act.Voice.Call(voice.Post{
	From: "+{ Your Twilio Number }",
	To:   "+{ Your Destination Number }",
	URL:  "http://twimlbin.com/mytwiml",
})

Sending a text - with a callback handler

act := twilogo.NewAccountFromEnv()

resp, err := act.Sms.Send(sms.Post{
	From:           "+{ Your Twilio Number }",
	To:             "+{ Your Destination Number }",
	Body:           "Ready to become a Go-ru?",
	StatusCallback: "{ Your IP/DNS }/sms_callback",
})

smsChan := make(chan sms.Callback)
go func(callbackChan chan sms.Callback){
	for {
		smsCallback <- callbackChan
		// process smsCallback as desired
	}
}()

// Register the sms callback handler
// All incoming SMS callbacks will be parsed and sent into "smsChan"
http.Handle("/sms_callback", sms.CallbackHandler(smsChan))

http.ListenAndServe("0.0.0.0:8000", nil)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages