Get Started with Java Using the Spring Framework
Sign up for a Plivo account
When you sign up with Plivo, we give you a free trial account and free credits to experiment with and learn about our services. You can add a number to your account to start testing the full range of our voice and SMS service features.Follow these steps to get a free trial account:- Sign up with your work email address.
- Check your inbox for an activation email message from Plivo. Click on the link in the message to activate your account.
- Enter your mobile number to complete the phone verification step.
Sign up with your work email address

Set up your Java Spring dev environment
You must set up and install Java 1.8 or higher and Plivo’s Java SDK before you send your first message.You can check your Java version under macOS or Linux by running the commandjava -version
in a terminal window. Under Windows there are several ways to check. If you don’t have Java installed or need a more current version, download and install it.You should also download and install IntelliJ Idea.Install Spring and the Plivo Java package using IntelliJ Idea
Use Spring Initializr to create a boilerplate project with the Spring Boot framework.
Spring Web
dependency. Give the project a friendly name and click Generate to download the boilerplate code and open it in IntelliJ Idea.
Note: Set the Java target as 8.
pom.xml

Send your first outbound SMS/MMS message
You can create and deploy a PHLO to send your first outbound SMS message with a few clicks on the PHLO canvas, and trigger it with some simple code.Create the PHLO

- On the side navigation bar, click PHLO. The PHLO page will appear and display your existing PHLOs, if any exist. If this is your first PHLO, then the PHLO page will be empty.
- Click Create New PHLO to build a new PHLO.
- In the Choose your use-case window, click Build my own. The PHLO canvas will appear with the Start node.
Note: The Start node is the starting point of any PHLO. You can choose between the four available trigger states of the start node; Incoming SMS, Incoming Call, and API Request. For this PHLO, we will use the
API Request
trigger state. - From the list of components on the left-hand side, drag and drop the Send Message component onto the canvas. This will add an
Send Message
node onto the canvas. - Connect the Start node with the Send Message node, using the API Request trigger state.
- Configure the Send Message node with the source/from number using the From field. Enter the destination number you wish to send message in the To field.
- If you’d like to send MMS then Configure the Media URLs node with the Media files you’d like to send using the Media URLs field.
- Once you have configured the node, click Validate to save the configurations.
- After you complete the configurations, provide a recognizable name for your PHLO and click Save. Your PHLO is now ready. You can trigger the PHLO and test it out. For more information, refer to the following section.
Trigger the PHLO
You integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload — the set of parameters you pass to the PHLO. You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through parameters when you trigger the PHLO from your application.In either case, you need your Auth ID and Auth Token, which you can get from the overview page of the Plivo console.

With a static payload
When you configure values when creating the PHLO, they act as a static payload.
Code
Edit the PlivoSMSApplication.java file in the src/main/java/com.example.demo/ folder and paste into it this code.Note:* Here, the demo application name is
PlivoSMSApplication.java
because the friendly name we provided in Spring Initializr was Plivo SMS
.With a dynamic payload
To use dynamic values for the parameters, use Liquid templating parameters when you create the PHLO …

Code
Edit the PlivoSMSApplication.java file in the src/main/java/com.example.demo/ folder and paste into it this code.Note: Here, the demo application name is
PlivoSMSApplication.java
because the friendly name we provided in the Spring Initializr was Plivo SMS
.Test
Save the file and run it from IntelliJ.Receive your first inbound SMS/MMS message
You can create and deploy a PHLO to receive an inbound text message with a few clicks on the PHLO canvas, without writing a single line of code.Prerequisite
To receive incoming text messages, you must have an SMS-enabled Plivo phone number. You can rent numbers from the Numbers page of the Plivo console, or by using the Numbers API.Create the PHLO

- Click Create New PHLO.
-
In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.
Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
- From the list of components on the left-hand side, drag and drop the HTTP Request component onto the canvas. When a component is placed on the canvas it becomes a node.
- Draw a line to connect the Start node’s Incoming Message trigger state to the HTTP Request node.
-
In the Configuration pane at the right of the canvas, configure the HTTP Request node. Specify the address of your web server and specify that
from
,to
, andtext
fields should be passed along with the request. - Once you’ve configured the node, click Validate to save the configuration.
- After you complete the configuration, give the PHLO a name by clicking in the upper left, then click Save.
Assign the PHLO to a Plivo number
Once you’ve created and configured your PHLO, assign it to a Plivo number.- On the Numbers page of the console, under Your Numbers, click the phone number you want to use for the PHLO.
- In the Number Configuration box, select PHLO from the Application Type drop-down.
- From the PHLO Name drop-down, select the PHLO you want to use with the number, then click Update Number.

Test
You can now send a text message to your Plivo phone number and see how the inbound text is handled.For more information about creating a PHLO application, see the PHLO Getting Started guide. For information on components and their variables, see the PHLO Components Library.Forward an incoming SMS/MMS message
You can create and deploy a workflow to implement text message forwarding with a few clicks on the PHLO canvas.Prerequisite
To receive incoming text messages, you must have an SMS-enabled Plivo phone number. You can rent numbers from the Numbers page of the Plivo console, or by using the Numbers API.Create the PHLO

- Click Create New PHLO.
-
In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.
Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
- From the list of components on the left-hand side, drag and drop the Send Message component onto the canvas. When a component is placed on the canvas it becomes a node.
- Draw a line to connect the Start node’s Incoming Message trigger state to the Send Message node.
- In the Configuration pane at the right of the canvas, configure the Send Message node with the phone number to which you want to forward the message.
- Once you’ve configured the node, click Validate to save the configuration.
- After you complete the configuration, give the PHLO a name by clicking in the upper left, then click Save.
Assign the PHLO to a Plivo number
Once you’ve created and configured your PHLO, assign it to a Plivo number.- On the Numbers page of the console, under Your Numbers, click the phone number you want to use for the PHLO.
- In the Number Configuration box, select PHLO from the Application Type drop-down.
- From the PHLO Name drop-down, select the PHLO you want to use with the phone number, then click Update Number.
