goexoml

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2015 License: MIT Imports: 2 Imported by: 0

README

goexoml GoDoc

The ExoML library for golang

####What is it? goexoml is the official ExoML library written in golang.
ExoML (ExotelMarkupLanguage) enables one to add logic to calls.When someone makes a call to an exophone ,Exotel will look up the URL associated with exophone and make a request to that URL. The URL can be configured to respond with ExoMLs Responses,which exotel interprets and executes

For Example

The following will be interpreted by exotel as a request to make a call to the number +919742033616 and makes call

<?xml version="1.0" encoding="UTF-8"?>
<Response>
	<Dial>
			<Number>
					+919742033616
			</Number>
	</Dial>
</Response>

####currently supported verbs

  • Dial
  • Hangup
  • Play
  • Record
  • Redirect
  • Say
  • Gather

####how to use Install the latest library using go get

go get github.com/exotel/goexoml

or from the gopkg repo to make sure the version number is maintained all time

go get gopkg.in/exotel/goexoml.v1 //for v1.x.x

###sample Code

package main

import (
	"fmt"

	"github.com/exotel/goexoml"
)

//Example - creates a sample response as follows
// <?xml version="1.0" encoding="UTF-8"?>
// <Response>
//     <Say>
//         Please leave a message at the beep.
//         Press the star key when finished.
//     </Say>
//     <Record
//         action="http://example.exotel.in/handleRecording"
//         method="GET"
//         maxLength="20"
//         finishOnKey="*"
//         />
//     <Say>I did not receive a recording</Say>
// </Response>
func Example() (string, error) {
	//create a new response object
	resp := goexoml.NewResponse()

	//create a new say verb and add attributes and values
	say1 := goexoml.NewSay().SetText("Please leave a message at the beep.\n         Press the star key when finished.")

	//create a new say verb and add attributes and values
	say2 := goexoml.NewSay().SetText("I did not receive a recording.")

	//create the recors vberb and add attributes
	rec := goexoml.NewRecord().SetAction("http://example.exotel.in/handleRecording").SetMethod("GET").SetMaxLength(20)

	//Add the Action verbs to the response object in expected order
	err := resp.Action(say1, rec, say2)
	if err != nil {
		fmt.Println(err.Error())
		return "", err
	}
	// OR
	////Add the Action verbs to the response object in expected order
	// resp.AddSay(say1).AddRecord(rec).AddSay(say2)
	return resp.String(), nil
}

func main() {
	exoml, err := Example()
	if err != nil {
		fmt.Print("Error occured :", err.Error())
		return
	}
	fmt.Println(exoml)
	return
}

####What if i don't have go installed ? This is how you can install go in linux [this is for version 1.5.2 of golang]

wget https://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.5.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

now you have go installed,try checking by checking the version

go version

Now you have to set the Workspace,say you are setting,~/go as the worksapce this is how it is done

export GOPATH=$HOME/go

Add these two export statements in ~/.bashrc so that its set all the time Now you are ready to test goexoml,get the library using go get ie,

go get github.com/exotel/goexoml

Now you can copy paste the sample code server.go from example/server to a file ,say path/to/file.go The example program uses an external library for spawning http server intsll it as

go get github.com/labstack/echo

Run the server as

go run path/to/file.go

By now the exoml library would be running on port 1323

Test it

curl http://localhost:1323/dial/+919742033616
```

This would return an exoml
```
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>You can't handle the truth</Say>
    <Dial>+919742033616</Dial>
    <Hangup></Hangup>
</Response
```


####Versioning
#####*major version Changes would mean following *
* Removing or renaming *any* exposed name (function, method, type, etc)
* Adding, removing or renaming methods in an interface
* Adding a parameter to a function, method, or interface
* Changing the type of a parameter or result in a function, method, or interface
* Changing the number of results in a function, method, or interface
* Some user facing struct changes

#####*expect these changes even without major version being same *
* Adding exposed names (function, method, type, etc)
* Renaming a parameter or result of a function, method, or interface*
* Some struct changes which does not directly affect the functionality of the library [*much*] but may/maynot add new features to the existing library





####contributions
sarath@exotel.in

Documentation

Overview

Package goexoml The ExoML library for golang goexoml is the official ExoML library written in golang. ExoML(ExotelMarkupLanguage) enables one to add logic to calls.

When someone makes a call to an *exophone* ,Exotel will look up the URL associated with *exophone* and make a request to that URL.

sample Code

package main

import (
	"fmt"

	"github.com/exotel/goexoml"
)

//Example - creates a sample response as follows
// <?xml version="1.0" encoding="UTF-8"?>
// <Response>
//     <Say>
//         Please leave a message at the beep.
//         Press the star key when finished.
//     </Say>
//     <Record
//         action="http://example.exotel.in/handleRecording"
//         method="GET"
//         maxLength="20"
//         finishOnKey="*"
//         />
//     <Say>I did not receive a recording</Say>
// </Response>
func Example() (string, error) {
	//create a new response object
	resp := goexoml.NewResponse()

	//create a new say verb and add attributes and values
	say1 := goexoml.NewSay().SetText("Please leave a message at the beep.\n         Press the star key when finished.")

	//create a new say verb and add attributes and values
	say2 := goexoml.NewSay().SetText("I did not receive a recording.")

	//create the recors vberb and add attributes
	rec := goexoml.NewRecord().SetAction("http://example.exotel.in/handleRecording").SetMethod("GET").SetMaxLength(20)

	//Add the Action verbs to the response object in expected order
	err := resp.Action(say1, rec, say2)
	if err != nil {
		fmt.Println(err.Error())
		return "", err
	}
	// OR
	////Add the Action verbs to the response object in expected order
	// resp.AddSay(say1).AddRecord(rec).AddSay(say2)
	return resp.String(), nil
}

func main() {
	exoml, err := Example()
	if err != nil {
		fmt.Print("Error occured :", err.Error())
		return
	}
	fmt.Println(exoml)
	return
}

Index

Constants

This section is empty.

Variables

View Source
var CallStatus = struct {
	EXOQueued     string
	EXORinging    string
	EXOInProgress string
	EXOCompleted  string
	EXOBusy       string
	EXOFailed     string
	EXONoAnswer   string
	EXOCanceled   string
}{
	EXOQueued:     "queued",
	EXORinging:    "ringing",
	EXOInProgress: "in-progress",
	EXOCompleted:  "completed",
	EXOBusy:       "busy",
	EXOFailed:     "failed",
	EXONoAnswer:   "no-answer",
	EXOCanceled:   "canceled",
}

Constants for CallStatus

Functions

This section is empty.

Types

type Dial

type Dial struct {
	XMLName      xml.Name `xml:"Dial"`
	Action       string   `xml:"action,attr,omitempty"`
	Method       string   `xml:"method,attr,omitempty"`
	Timeout      int      `xml:"timeout,attr,omitempty"`
	HangupOnStar bool     `xml:"hangupOnStar,attr,omitempty"`
	TimeLimit    int      `xml:"timeLimit,attr,omitempty"`
	CallerID     string   `xml:"callerId,attr,omitempty"`
	Record       bool     `xml:"record,attr,omitempty"`
	PlainNumber  string   `xml:",innerxml"`
	Number       *Number  `xml:",innerxml"`
}

Dial struct for the verb Dial which allows a number as plain test

func NewDial

func NewDial() *Dial

NewDial return a new Dial pointer

func (*Dial) SetAction

func (__dial__ *Dial) SetAction(action string) *Dial

SetAction sets Action for Dial struct instance

func (*Dial) SetCallerID

func (__dial__ *Dial) SetCallerID(callerid string) *Dial

SetCallerID sets CallerID for Dial struct instance

func (*Dial) SetHangupOnStar

func (__dial__ *Dial) SetHangupOnStar(hanguponstar bool) *Dial

SetHangupOnStar sets HangupOnStar for Dial struct instance

func (*Dial) SetMethod

func (__dial__ *Dial) SetMethod(method string) *Dial

SetMethod sets Method for Dial struct instance

func (*Dial) SetNumber

func (__dial__ *Dial) SetNumber(number *Number) *Dial

SetNumber sets Number for Dial struct instance

func (*Dial) SetPlainNumber

func (__dial__ *Dial) SetPlainNumber(plainnumber string) *Dial

SetPlainNumber sets PlainNumber for Dial struct instance

func (*Dial) SetRecord

func (__dial__ *Dial) SetRecord(record bool) *Dial

SetRecord sets Record for Dial struct instance

func (*Dial) SetTimeLimit

func (__dial__ *Dial) SetTimeLimit(timelimit int) *Dial

SetTimeLimit sets TimeLimit for Dial struct instance

func (*Dial) SetTimeout

func (__dial__ *Dial) SetTimeout(timeout int) *Dial

SetTimeout sets Timeout for Dial struct instance

type Gather

type Gather struct {
	XMLName     xml.Name `xml:"Gather"`
	Action      string   `xml:"action,attr,omitempty"`
	Method      string   `xml:"method,attr,omitempty"`
	Timeout     int      `xml:"timeout,attr,omitempty"`
	FinishOnKey string   `xml:"finishOnKey,attr,omitempty"`
	NumDigits   int      `xml:"numDigits,attr,omitempty"`
	Say         *Say     `xml:",innerxml"`
	Play        *Play    `xml:",innerxml"`
}

Gather struct for the verb Gather

func NewGather

func NewGather() *Gather

NewGather return a new Gather pointer

func (*Gather) SetAction

func (__gather__ *Gather) SetAction(action string) *Gather

SetAction sets Action for Gather struct instance

func (*Gather) SetFinishOnKey

func (__gather__ *Gather) SetFinishOnKey(finishonkey string) *Gather

SetFinishOnKey sets FinishOnKey for Gather struct instance

func (*Gather) SetMethod

func (__gather__ *Gather) SetMethod(method string) *Gather

SetMethod sets Method for Gather struct instance

func (*Gather) SetNumDigits

func (__gather__ *Gather) SetNumDigits(numdigits int) *Gather

SetNumDigits sets NumDigits for Gather struct instance

func (*Gather) SetPlay

func (__gather__ *Gather) SetPlay(play *Play) *Gather

SetPlay sets Play for Gather struct instance

func (*Gather) SetSay

func (__gather__ *Gather) SetSay(say *Say) *Gather

SetSay sets Say for Gather struct instance

func (*Gather) SetTimeout

func (__gather__ *Gather) SetTimeout(timeout int) *Gather

SetTimeout sets Timeout for Gather struct instance

type Hangup

type Hangup struct {
	XMLName xml.Name `xml:"Hangup"`
}

Hangup struct for the verb Hangup

func NewHangup

func NewHangup() *Hangup

NewHangup return a new Hangup pointer

type IDial

type IDial interface {
	SetAction(action string) *Dial
	SetMethod(method string) *Dial
	SetTimeout(timeout int) *Dial
	SetHangupOnStar(hanguponstar bool) *Dial
	SetTimeLimit(timelimit int) *Dial
	SetCallerID(callerid string) *Dial
	SetRecord(record bool) *Dial
	SetPlainNumber(plainnumber string) *Dial
	SetNumber(number *Number) *Dial
}

IDial The interface that satisfies all the methods for this struct IDial asserts implementation of setters for all the fields of Dial

type IGather

type IGather interface {
	SetAction(action string) *Gather
	SetMethod(method string) *Gather
	SetTimeout(timeout int) *Gather
	SetFinishOnKey(finishonkey string) *Gather
	SetNumDigits(numdigits int) *Gather
	SetSay(say *Say) *Gather
	SetPlay(play *Play) *Gather
}

IGather The interface that satisfies all the methods for this struct IGather asserts implementation of setters for all the fields of Gather

type IHangup

type IHangup interface {
}

IHangup The interface that satisfies all the methods for this struct IHangup asserts implementation of setters for all the fields of Hangup

type INumber

type INumber interface {
	SetSendDigits(senddigits string) *Number
	SetURL(url string) *Number
	SetMethod(method string) *Number
	SetStatusCallbackEvent(statuscallbackevent string) *Number
	SetStatusCallback(statuscallback string) *Number
	SetStatusCallbackMethod(statuscallbackmethod string) *Number
	SetNoun(noun string) *Number
}

INumber The interface that satisfies all the methods for this struct INumber asserts implementation of setters for all the fields of Number

type IPlay

type IPlay interface {
	SetLoop(loop int) *Play
	SetDigits(digits int) *Play
	SetURL(url string) *Play
}

IPlay The interface that satisfies all the methods for this struct IPlay asserts implementation of setters for all the fields of Play

type IRecord

type IRecord interface {
	SetAction(action string) *Record
	SetMethod(method string) *Record
	SetTimeout(timeout int) *Record
	SetFinishOnKey(finishonkey string) *Record
	SetMaxLength(maxlength int) *Record
	SetTranscribe(transcribe bool) *Record
	SetTranscribeCallback(transcribecallback string) *Record
	SetPlayBeep(playbeep bool) *Record
	SetTrim(trim string) *Record
}

IRecord The interface that satisfies all the methods for this struct IRecord asserts implementation of setters for all the fields of Record

type IRedirect

type IRedirect interface {
	SetMethod(method string) *Redirect
	SetURL(url string) *Redirect
}

IRedirect The interface that satisfies all the methods for this struct IRedirect asserts implementation of setters for all the fields of Redirect

type ISay

type ISay interface {
	SetVoice(voice string) *Say
	SetLanguage(language string) *Say
	SetLoop(loop int) *Say
	SetText(text string) *Say
}

ISay The interface that satisfies all the methods for this struct ISay asserts implementation of setters for all the fields of Say

type Number

type Number struct {
	XMLName              xml.Name `xml:"Number"`
	SendDigits           string   `xml:"sendDigits,attr,omitempty"`
	URL                  string   `xml:"URL,attr,omitempty"`
	Method               string   `xml:"method,attr,omitempty"`
	StatusCallbackEvent  string   `xml:"statusCallbackEvent,attr,omitempty"`
	StatusCallback       string   `xml:"StatusCallback,attr,omitempty"`
	StatusCallbackMethod string   `xml:"StatusCallbackMethod,attr,omitempty"`
	Noun                 string   `xml:",innerxml"`
}

Number struct for the noun Number

func NewNumber

func NewNumber() *Number

NewNumber return a new Number pointer

func (*Number) SetMethod

func (__number__ *Number) SetMethod(method string) *Number

SetMethod sets Method for Number struct instance

func (*Number) SetNoun

func (__number__ *Number) SetNoun(noun string) *Number

SetNoun sets Noun for Number struct instance

func (*Number) SetSendDigits

func (__number__ *Number) SetSendDigits(senddigits string) *Number

SetSendDigits sets SendDigits for Number struct instance

func (*Number) SetStatusCallback

func (__number__ *Number) SetStatusCallback(statuscallback string) *Number

SetStatusCallback sets StatusCallback for Number struct instance

func (*Number) SetStatusCallbackEvent

func (__number__ *Number) SetStatusCallbackEvent(statuscallbackevent string) *Number

SetStatusCallbackEvent sets StatusCallbackEvent for Number struct instance

func (*Number) SetStatusCallbackMethod

func (__number__ *Number) SetStatusCallbackMethod(statuscallbackmethod string) *Number

SetStatusCallbackMethod sets StatusCallbackMethod for Number struct instance

func (*Number) SetURL

func (__number__ *Number) SetURL(url string) *Number

SetURL sets URL for Number struct instance

type Play

type Play struct {
	XMLName xml.Name `xml:"Play"`
	Loop    int      `xml:"loop,attr,omitempty"`
	Digits  int      `xml:"digits,attr,omitempty"`
	URL     string   `xml:",innerxml"`
}

Play struct for the verb Play

func NewPlay

func NewPlay() *Play

NewPlay return a new Play pointer

func (*Play) SetDigits

func (__play__ *Play) SetDigits(digits int) *Play

SetDigits sets Digits for Play struct instance

func (*Play) SetLoop

func (__play__ *Play) SetLoop(loop int) *Play

SetLoop sets Loop for Play struct instance

func (*Play) SetURL

func (__play__ *Play) SetURL(url string) *Play

SetURL sets URL for Play struct instance

type Record

type Record struct {
	XMLName            xml.Name `xml:"Record"`
	Action             string   `xml:"action,attr,omitempty"`
	Method             string   `xml:"method,attr,omitempty"`
	Timeout            int      `xml:"timeout,attr,omitempty"`
	FinishOnKey        string   `xml:"finishOnKey,attr,omitempty"`
	MaxLength          int      `xml:"maxLength,attr,omitempty"`
	Transcribe         bool     `xml:"transcribe,attr,omitempty"`
	TranscribeCallback string   `xml:"transcribeCallback,attr,omitempty"`
	PlayBeep           bool     `xml:"playBeep,attr,omitempty"`
	Trim               string   `xml:"trim,attr,omitempty"`
}

Record struct for the verb Record

func NewRecord

func NewRecord() *Record

NewRecord return a new Record pointer

func (*Record) SetAction

func (__record__ *Record) SetAction(action string) *Record

SetAction sets Action for Record struct instance

func (*Record) SetFinishOnKey

func (__record__ *Record) SetFinishOnKey(finishonkey string) *Record

SetFinishOnKey sets FinishOnKey for Record struct instance

func (*Record) SetMaxLength

func (__record__ *Record) SetMaxLength(maxlength int) *Record

SetMaxLength sets MaxLength for Record struct instance

func (*Record) SetMethod

func (__record__ *Record) SetMethod(method string) *Record

SetMethod sets Method for Record struct instance

func (*Record) SetPlayBeep

func (__record__ *Record) SetPlayBeep(playbeep bool) *Record

SetPlayBeep sets PlayBeep for Record struct instance

func (*Record) SetTimeout

func (__record__ *Record) SetTimeout(timeout int) *Record

SetTimeout sets Timeout for Record struct instance

func (*Record) SetTranscribe

func (__record__ *Record) SetTranscribe(transcribe bool) *Record

SetTranscribe sets Transcribe for Record struct instance

func (*Record) SetTranscribeCallback

func (__record__ *Record) SetTranscribeCallback(transcribecallback string) *Record

SetTranscribeCallback sets TranscribeCallback for Record struct instance

func (*Record) SetTrim

func (__record__ *Record) SetTrim(trim string) *Record

SetTrim sets Trim for Record struct instance

type Redirect

type Redirect struct {
	XMLName xml.Name `xml:"Redirect"`
	Method  string   `xml:"method,attr,omitempty"`
	URL     string   `xml:",innerxml"`
}

Redirect struct for the verb Redirect

func NewRedirect

func NewRedirect() *Redirect

NewRedirect return a new Redirect pointer

func (*Redirect) SetMethod

func (__redirect__ *Redirect) SetMethod(method string) *Redirect

SetMethod sets Method for Redirect struct instance

func (*Redirect) SetURL

func (__redirect__ *Redirect) SetURL(url string) *Redirect

SetURL sets URL for Redirect struct instance

type Response

type Response struct {
	XMLName  xml.Name `xml:"Response"`
	Response []interface{}
}

Response struct for the verb Response the wrapper struct that accomodates all the Verbs as a sequence of verbs

func NewResponse

func NewResponse() *Response

NewResponse returns a pointer to the reposne structure

func (*Response) Action

func (r *Response) Action(verbs ...interface{}) error

Action appends action verb structs to response. The verbs has to be given in the order in which they are expected to be executed if there is any invalid verb the function will repond with error but still Response would have all the other verbs till the invalid one

func (*Response) AddDial

func (r *Response) AddDial(dial IDial) *Response

AddDial appends the verb to response

func (*Response) AddGather

func (r *Response) AddGather(gather IGather) *Response

AddGather appends the verb to response

func (*Response) AddHangup

func (r *Response) AddHangup(hangup IHangup) *Response

AddHangup appends the verb to response

func (*Response) AddNumber

func (r *Response) AddNumber(number INumber) *Response

AddNumber appends the verb to response

func (*Response) AddPlay

func (r *Response) AddPlay(play IPlay) *Response

AddPlay appends the verb to response

func (*Response) AddRecord

func (r *Response) AddRecord(record IRecord) *Response

AddRecord appends the verb to response

func (*Response) AddRedirect

func (r *Response) AddRedirect(redirect IRedirect) *Response

AddRedirect appends the verb to response

func (*Response) AddSay

func (r *Response) AddSay(say ISay) *Response

AddSay appends the verb to response

func (Response) String

func (r Response) String() string

String returns a formatted xml response String implements the fmt.Stringer and it returns the ExoML Response struct as an XMLMarshalled string

type Say

type Say struct {
	XMLName  xml.Name `xml:"Say"`
	Voice    string   `xml:"voice,attr,omitempty"`
	Language string   `xml:"language,attr,omitempty"`
	Loop     int      `xml:"loop,attr,omitempty"`
	Text     string   `xml:",innerxml"`
}

Say struct for the verb Say

func NewSay

func NewSay() *Say

NewSay return a new Say pointer

func (*Say) SetLanguage

func (__say__ *Say) SetLanguage(language string) *Say

SetLanguage sets Language for Say struct instance

func (*Say) SetLoop

func (__say__ *Say) SetLoop(loop int) *Say

SetLoop sets Loop for Say struct instance

func (*Say) SetText

func (__say__ *Say) SetText(text string) *Say

SetText sets Text for Say struct instance

func (*Say) SetVoice

func (__say__ *Say) SetVoice(voice string) *Say

SetVoice sets Voice for Say struct instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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