Set up your Go dev environment for PHLO
In this guide, you will learn how to set up a development environment in under 5 minutes to trigger a PHLO.
Prerequisites
Install Go and the Plivo Go Server SDK
You must set up and install Go and Plivo’s Go SDK to trigger a PHLO. Here’s how.
Install Go
You can install Go from the Official Installer.
Install Plivo Go Package
Create a project directory, run the following command:
$ mkdir mygoapp
Change the directory to our project directory in the command line:
$ cd mygoapp
You can install the Plivo Go package using the
go
command.$ go get github.com/plivo/plivo-go
You can also install by cloning this repository into your
GOPATH
.
Trigger a PHLO
Once you have created and configured your PHLO, copy the PHLO Run URL. You can integrate a PHLO into your application workflow by making an API request to the PHLO URL with the required payload.
With Static Payload
You can choose to either configure the mandatory params required for a PHLO while creating the PHLO itself or, you can pass the params as payload while triggering the PHLO from your app.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"fmt"
"plivo-go"
)
// Initialize the following params with corresponding values to trigger resources
const authId = "auth_id"
const authToken = "auth_token"
const phloId = "phlo_id"
func main() {
testPhloRunWithoutParams()
}
func testPhloRunWithoutParams() {
phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
if err != nil {
panic(err)
}
phloGet, err := phloClient.Phlos.Get(phloId)
if err != nil {
panic(err)
}
response, err := phloGet.Run(nil)
if err != nil {
panic(err)
}
fmt.Printf("Response: %#v\n", response)
}
With Dynamic Payload
To use dynamic values for the parameters, you can use the liquid templating params while creating the PHLO and pass the values while triggering the PHLO.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"plivo-go"
)
// Initialize the following params with corresponding values to trigger resources
const authId = "auth_id"
const authToken = "auth_token"
const phloId = "phlo_id"
func main() {
testPhloRunWithParams()
}
func testPhloRunWithParams() {
phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
if err != nil {
panic(err)
}
phloGet, err := phloClient.Phlos.Get(phloId)
if err != nil {
panic(err)
}
//pass corresponding from and to values
type params map[string]interface{}
response, err := phloGet.Run(params{
"from": "+14157778888",
"to": "+14157778889",
})
if err != nil {
println(err)
}
fmt.Printf("Response: %#v\n", response)
}
You can get your Auth_ID and Auth_token from your dashboard
You can find the PHLO_ID on the PHLO Listing page.