[Deprecated] - The REST service used here is not active any more
GoExotel is a exotel platform api client written in golang
- Account
- IncomingPhoneNumber
- OutgoingCallerID
- AvailablePhoneNumber
- Call
- Recording
Install the library using go get
go get github.com/exotel/goapi
or for keeping the version number
go get gopkg.in/exotel/goapi.v0 //for version v0.x.x
initiate the client
credentials := types.Credentials{
UserCredentials: types.UserCredentials{AccessToken: "APIAccessToken", UserName: "APIUsername"},
ClientCredentials: types.ClientCredentials{ClientID: "CLIENT_id", ClientSecret: "CLIENT_SECRET"},
}
client = api.New(credentials)
client.SetAccountSid("<ACCOUNT_SID>") //parent working
for adding a sub account
c := client.
Account().
Create().
Details(resources.AccountDetails{FriendlyName: "SARATH TESTING", CountryCode: "SNG"})
if status, data, err := c.Do(); err != nil {
fmt.Printf(err.Error())
} else {
fmt.Printf("No Error occured while doing the operation\nstatus : %d\ndata%v", status, data)
}
consider resource is Resource
and the CRUD is allowed for Resource
1 . Create Request
client.Resource().Create().Details(resources.ResourceDetails{}).Do
2 . Read Request
- bulk
client.Resource().Get().Filter(resources.ResourceFilter{}).Do()
- Single
client.Resource().ID(string).Get().Do
3 . Update Request
client.Resource().ID(string).Update().UpdateDetails(resources.ResourceUpdatableDetails{}).Do
4 . Delete Request
client.Resource().ID(string).Delete().Do()
package main
import (
"fmt"
api "github.com/exotel/goapi"
"github.com/exotel/goapi/assets/types"
"github.com/exotel/goapi/resources"
)
func initClient() (client *api.Client) {
credentials := types.Credentials{
UserCredentials: types.UserCredentials{AccessToken: "APIAccessToken", UserName: "APIUsername"},
ClientCredentials: types.ClientCredentials{ClientID: "CLIENT_id", ClientSecret: "CLIENT_SECRET"},
}
client = api.New(credentials)
client.SetAccountSid("<ACCOUNT_SID>") //parent working
return
}
//ExampleCall Create call example
func ExampleCall(client *api.Client) {
var callDetails resources.CallDetails
callDetails.From = "+918030752401"
callDetails.To = "+919742033616"
callDetails.URL = "http://98ae7c6f.ngrok.io/dial/+919742033616"
callDetails.Method = "GET"
if status, data, err := client.Debug(true).Call().Create().Details(callDetails).Do(); err != nil {
fmt.Println("error occured", err.Error())
} else {
fmt.Printf("No Error occured while doing the operation\nstatus : %d\ndata%v", status, data)
}
}
func main() {
client := initClient()
//makes a call
ExampleCall(client)
}
This is how you can install go in linux [this is for version 1.8 of golang]
wget https://storage.googleapis.com/golang/go1.8.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
export GOROOT=/usr/local/go
Add these two export statements in ~/.bashrc so that it is set all the time Now you are ready to test goapi,get the library using go get ie,
go get github.com/exotel/goapi
Now you can copy paste the sample codes from example folder to path/to/filename.go
and test by running as
go run path/to/filename.go