Using this guide, you can set up a development environment in five minutes to trigger a PHLO.

Install Java, Spring, and the Plivo Java SDK

To get started, install Java 1.8 or higher and Plivo’s Java SDK. You probably already have Java installed. In macOS, Linux, or Windows you can check the version by running the command java -version in a terminal window. If you need to update it, download and install it. You should also download and install IntelliJ IDEA.

Install Spring and the Plivo Java SDK using IntelliJ Idea

  • Use Spring Initializr to create a boilerplate project with Spring Boot framework.

  • Add the Spring Web dependency. Give the project a friendly name, set the Java target as 8, then click Generate to download the boilerplate code and open it in IntelliJ Idea.

  • Install the Plivo Java package by adding the dependency in pom.xml

    <dependency>
        <groupId>com.plivo</groupId>
        <artifactId>plivo-java</artifactId>
        <version>4.14.0</version>
    </dependency>
    

Trigger the PHLO

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, locate the PlivoVoiceApplication.java file in the src/main/java/com.example.demo/ folder and paste into it the code below for either a static or dynamic payload.

Note: Here, the demo application name is PlivoVoiceApplication.java because the friendly name provided in the Spring Initializr was Plivo Voice.

Static payload

package com.example.demo;
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import com.plivo.api.models.phlo.PhloUpdateResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@RestController
public class PlivoVoiceApplication {


	public static void main(String[] args) {
		SpringApplication.run(PlivoVoiceApplication.class, args);
	}
	
	@GetMapping("/outbound")
	public PhloUpdateResponse triggerPhlo() throws IOException, PlivoRestException {
		final String authId = "<auth_id>";
		final String authToken = "<auth_token>";
		PlivoClient client = new PlivoClient(authId, authToken);
		String phloId = "<phlo_id>";
		Plivo.init(authId, authToken);
		Phlo phlo = Phlo.getter(phloId).client(client).get();
		Map<String, Object> payload = new HashMap<>();
		payload.put("from", "<Caller_ID>");
		payload.put("to", "<Destination_Number>");
		PhloUpdateResponse response = Phlo.updater(phloId).payload(payload).run();
		return response;
	}

}

Dynamic payload

package com.example.demo;
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import com.plivo.api.models.phlo.PhloUpdateResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@SpringBootApplication
@RestController
public class PlivoVoiceApplication {


	public static void main(String[] args) {
		SpringApplication.run(PlivoVoiceApplication.class, args);
	}
	
	@GetMapping("/outbound")
	public PhloUpdateResponse triggerPhlo() throws IOException, PlivoRestException {
		final String authId = "<auth_id>";
		final String authToken = "<auth_token>";
		PlivoClient client = new PlivoClient(authId, authToken);
		String phloId = "<phlo_id>";
		Plivo.init(authId, authToken);
		Phlo phlo = Phlo.getter(phloId).client(client).get();
		PhloUpdateResponse response = Phlo.updater(phloId).run();
		return response;
	}

}
  • Replace the placeholders &lt;auth_id> and &lt;auth_token> with your authentication credentials, which you can find on the overview page of the Plivo console.
  • We recommend that you store your credentials in the auth_id and auth_token environment variables to avoid the possibility of accidentally committing them to source control. If you do this, you can initialize the client with no arguments and it will automatically fetch the values from the environment variables.
  • Replace the placeholder &lt;phlo_id> with the PHLO_ID from the PHLO list screen of the Plivo console.
  • Replace the placeholder &lt;Caller_ID> with a phone number you’ve purchased, and &lt;Destination_Number> with the phone number you’ll be calling. Both phone numbers should be in E.164 format.

Save the file and run it from IntelliJ.

You should see your server app in action on http://localhost:8080/outbound/.

Note: If you’re using a free trial account you must verify (sandbox) your destination number, unless you use the phone number you used for signup verification as your destination number. We require this as a security measure to avoid abuse. To sandbox a number in a Plivo trial account, visit Phone Numbers > Sandbox Numbers and click on Add Sandbox Number.