Using this guide, you can set up a development environment in five minutes to trigger a PHLO.
To get started, install Go, Gin, and Plivo’s Go SDK.
You can install Go from the official installer. To set up the other packages, first create a project directory using the command mkdir mygoapp
, then change to that directory and install the Gin and Plivo packages using the go
command.
go get github.com/gin-gonic/gin
go get github.com/plivo/plivo-go/v7
Alternatively, you can install them by cloning the Plivo Go repository and Gin repository into your GOPATH
.
Create and configure a PHLO, then integrate the PHLO into your application workflow by making an API request to trigger the PHLO with the required payload.
You can run a PHLO with static payload values by entering specific values in fields like from and to on the PHLO console.
To deliver a dynamic payload instead of a static one, define the payload keys as Liquid templates on the PHLO console and pass the values at runtime.
To trigger a PHLO, create a file — we called ours TriggerPhlo.go
— and paste into it the code below for either a static or dynamic payload.
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
39
40
41
42
43
44
45
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/plivo/plivo-go/v7"
)
// Initialize these constants with their corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"
func main() {
r := gin.Default()
r.GET("/trigger-phlo", func(c *gin.Context) {
c.Header("Content-Type", "application/JSON")
phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
if err != nil {
fmt.Print("Error", err.Error())
return
}
phloGet, err := phloClient.Phlos.Get(phloId)
if err != nil {
fmt.Print("Error", err.Error())
return
}
//pass corresponding from and to values
type params map[string]interface{}
response, err := phloGet.Run(params{
"from": "<Caller_ID>",
"to": "<Destination_Number>",
})
if err != nil {
println(err)
}
fmt.Printf("Response: %#v\n", response)
c.JSON(200, response)
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
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
39
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/plivo/plivo-go/v7"
)
// Initialize these constants with their corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"
func main() {
r := gin.Default()
r.GET("/trigger-phlo", func(c *gin.Context) {
c.Header("Content-Type", "application/JSON")
phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
if err != nil {
fmt.Print("Error", err.Error())
return
}
phloGet, err := phloClient.Phlos.Get(phloId)
if err != nil {
fmt.Print("Error", err.Error())
return
}
response, err := phloGet.Run(nil)
if err != nil {
fmt.Print("Error", err.Error())
return
}
fmt.Printf("Response: %#v\n", response)
c.JSON(200, response)
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
Save the file and run it.
go run TriggerPhlo.go