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 and Gin-Gonic packages

    • 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 and Gin-Gonic Go packages using the go command.

      $ go get github.com/plivo/plivo-go
      $ go get github.com/gin-gonic/gin
      
    • You can also install by cloning the Plivo Go repository and Gin-Gonic repository into your GOPATH.

    Trigger the PHLO

    Once you have created and configured your PHLO, copy the PHLO_ID from here. Integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload.

    With Static Payload

    Once you have created and setup your Go dev envrironment, you can go to your Plivo Consolse and copy the PHLO_ID. Integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload.

    Note: When you configure the params while creating the PHLO, the values are hardcoded and act as static payload.

    With Static Payload

    Code

    Now, create a file called TriggerPhlo.go and paste the following 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
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/gin-gonic/gin"
    	"github.com/plivo/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() {
    	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 {
    			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)
    		c.JSON(200, response)
    	})
    	r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
    }
    

    With Dynamic Payload

    To use dynamic values for the parameters, use the liquid templating params while creating the PHLO and pass the values while triggering the PHLO.

    With Dynamic Payload

    Code

    Now, create a file called TriggerPhlo.go and paste the following 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
    39
    40
    41
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/gin-gonic/gin"
    	"github.com/plivo/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() {
    	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 {
    			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)
    		c.JSON(200, response)
    	})
    	r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
    }
    

    Get your Auth_ID and Auth_token from your dashboard AUTHID

    You can find the PHLO_ID on the PHLO Listing page. PHLO Listing

    Test and Validate

    Save the file and use the below command to run it.

    $ go run TriggerPhlo.go
    
    Note: If you are using a Plivo Trial account for this example, you can only make calls to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.