How to Record a Phone Call using Twilio Java SDK?



Setting up a Twilio Phone Number

Choose Buy a number to start purchase
Filter and choose phone number

Record a part of incoming phone call

Create a new Java project

mkdir twilio-phone-recorder
Define pom.xml

Define a web app

Define index.

Add Twilio dependency

Define Java Servlet

Run the Maven project

mvn jetty:run
curl -X POST http://localhost:8080/recordIncoming
<?xml version=”1.0" encoding=”UTF-8"?><Response><Say>Hello. Please leave a message after the tone and our customer executives will get back to you.</Say><Record/><Hangup/></Response>

Expose Servlet using Ngrok for testing

ngrok authtoken <token>
ngrok http 8080

Set incoming call webhook using Twilio console

Record outbound phone calls

Define a servlet for outbound call response

Fetch account SID and auth token

echo “export TWILIO_ACCOUNT_SID=’ACXXXXXXXXXXXX’” > twilio.env
echo “export TWILIO_AUTH_TOKEN=’your_auth_token’” >> twilio.env
source ./twilio.env

Define script to record outbound calls




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store