twilio

package module
v0.0.0-...-b39ca9a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2014 License: MIT Imports: 8 Imported by: 2

README

Twilio NON-OFFICIAL Golang wrapper

This project is in a really alpha state for now. Feel free of provide pull requests or add new issues.

GoDoc Build Status

How to use?

On the import section of your Go project:

import (
    ...
    "github.com/agonzalezro/twilio-go"
    ...
)

Now, if you want to send an SMS just do:

client = twilio.NewTwilioRestClient("Your account here", "Your token here")
client.Messsages.Create("+44fromnumber", "+31tonumber", "Hi world!")

If you want to check more than this tiny example, you must check the generated documentation at godoc.

Supported methods

  • You can send SMS.
  • You can do calls.

How to develop easily?

What I do is create a symbolic link of my code (if you know a better way, please let me know :)

If your go path is in your folder ~/go, and you cloned the repo to ~/twilio-go, you can just copy paste this commands:

$ export GOPATH=/Users/alex/go
$ mkdir -p $GOPATH/src/github.com/agonzalezro
$ ln -s $HOME/twilio-go $GOPATH/src/github.com/agonzalezro

Examples

I've included few examples on the examples/ folder.

For example, if you want to send an sms, you can use this command (filling the needed information, of course):

go run examples/sms/sms.go \
	-account XXXXYOURACCOUNTHEREXXXX \
	-token YYYYOURTOKENHEREYYYY \
	-from +15005550006 \
	-to +447449601002 \
	-body "Hi world\!"

If you want to make a call, you will need an adittional step. You should check the documentation of TwiML and provide the XML in an endpoint that is accessible from the world.

After having that, you can use this command (note that I am using environment variables now):

TWILIO_ACCOUNT=AC0f9f0c5025b665ed8d68e649e442b0ff \
TWILIO_TOKEN=77a081faa8bebb1487827b527f87a0e5 \
TWILIO_NUMBER=+15005550006 \
go run examples/voice/voice.go \
	-to 447449601002 \
	-url http://YOURENDPOINTXML/MUSTALLOWPOST

TODO

  • Logical: finish all the API REST methods.
  • Add more tests!
  • Remove duplication, there is a lot: in tests & in modules code :(

Documentation

Overview

Package twilio is s small wrapper to be used with the Twilio API. Twilio lets you use standard web languages to build voice, VoIP and SMS applications via a web API.

To use it, all that you need is to create a client:

client := NewTwilioRestClient("yourAccount", "yourToken")

And to send a message just write:

client.Messages.Create("fromNumber", "toNumber", "body")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Calls

type Calls struct {
	// contains filtered or unexported fields
}

Calls is an intermediate class that for now is here just to emulate the Python API behaviour

func (*Calls) Create

func (c *Calls) Create(from string, to string, URL string) (*CallsResponse, *ErrorResponse)

Create a new call. You will need an external XML endpoint with the TwiML XML

type CallsResponse

type CallsResponse struct {
	Sid             string
	DateCreated     string `json:"date_created"`
	DateUpdated     string `json:"date_updated"`
	ParentCallSid   string `json:"parent_call_sid"`
	AccountSid      string `json:"account_sid"`
	To              string
	ToFormated      string `json:"to_formatted"`
	From            string
	FromFormatted   string `json:"from_formatted"`
	PhoneNumberSid  string `json:"phone_number_sid"`
	Status          string
	StartTime       string `json:"start_time"`
	EndTime         string `json:"end_time"`
	Duration        string
	Price           string
	PriceUnit       string `json:"price_unit"`
	Direction       string
	AnsweredBy      string `json:"answered_by"`
	APIVersion      string `json:"api_version"`
	Annotation      string
	ForwardedFrom   string `json:"forwaded_from"`
	GroupSid        string `json:"group_sid"`
	CallerName      string `json:"caller_name"`
	Uri             string
	SubresourceUris struct {
		Notifications string
		Recordings    string
	} `json:"subresource_uris"`
}

CallsResponse is the struct where we will Unmarshal the API response

type ErrorResponse

type ErrorResponse struct {
	Code     int `json:",int"`
	Message  string
	MoreInfo string `json:"more_info,string"`
	Status   string
}

ErrorResponse is the global struct that we are going to use to unmarshall the errors returned by the API

func NewErrorResponse

func NewErrorResponse(body io.Reader) *ErrorResponse

NewErrorResponse will create an object type ErrorResponse giving the body passed as parameter

type Messages

type Messages struct {
	// contains filtered or unexported fields
}

Messages is an intermediate class that will allow the creation of lists of recipients/messages

func (*Messages) Create

func (m *Messages) Create(from string, to string, body string) (*MessagesResponse, *ErrorResponse)

Create a new SMS

type MessagesResponse

type MessagesResponse struct {
	AccountSid  string `json:"account_sid,string"`
	APIVersion  string `json:"api_version,string"`
	Body        string
	NumSegments string `json:"num_segments,string"`
	NumMedia    string `json:"num_media,string"`
	DateCreated string `json:"date_created,string"`
	DateSent    string `json:"date_sent,string"`
	DateUpdated string `json:"date_updated,string"`
	Direction   string
	From        string
	Prices      string
	Sid         string
	Status      string
	To          string
	Uri         string
}

MessagesResponse is the struct where we will Unmarshal the API response

type TwilioRestClient

type TwilioRestClient struct {
	Calls    *Calls
	Messages *Messages
	// contains filtered or unexported fields
}

TwilioRestClient is an struct to store your Twilio credentials and available methods

func NewTwilioRestClient

func NewTwilioRestClient(account string, token string) *TwilioRestClient

NewTwilioRestClient is going to create a new Twilio client providing the account and token details

Directories

Path Synopsis
examples
sms
This example is showing how to create a command to send SMS using the Twilio API in a really easy way.
This example is showing how to create a command to send SMS using the Twilio API in a really easy way.
voice
This example is going to make a call using the Twilio API.
This example is going to make a call using the Twilio API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL