Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

TwilioDevEd/task-router-servlets

Repository files navigation

Twilio

TaskRouter on Servlets

Java Servlet CI

Use Twilio to provide your user with multiple options through phone calls, so they can be assisted by an agent specialized in the chosen topic. This is basically a call center created with the TaskRouter API of Twilio. This example uses a SQLite database to log phone calls which were not assisted.

Read the full tutorial here

Prerequisites

  1. Java 8 installed in your operative system.
  2. A Twilio account with a verified phone number. (Get a free account here.). If you are using a Twilio Trial Account, you can learn all about it [here] (https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work).

Local Development

  1. First clone this repository and cd into it.
git clone git@github.com:TwilioDevEd/task-router-servlets.git
cd task-router-servlets
  1. Copy the sample configuration file and edit it to match your configuration.
cp .env.example .env

You can find your TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN in your Twilio Account Settings. You will also need a TWILIO_NUMBER that you may find here.

  1. Make sure the tests succeed.
./gradlew check
  1. Configure the phone number of the agents which are going to answer the calls.
./gradlew -q createWorkspace -Pconfig="https://<sub-domain>.ngrok.io <agent1-phone> <agent2-phone>"

You will receive a message telling you to export 2 environment variables.

export WORKFLOW_SID=<hashvalue-workflow-sid>
export POST_WORK_ACTIVITY_SID=<hashvalue-post-work-activity-sid>

When the user calls, he will choose one option which will redirect him to the first agent whose phone number is agent1-phone. If the user's call is not responded in 30 seconds he will be redirected to the second agent whose phone number is agent2-phone.

  1. Start the server.
./gradlew appRun
  1. Expose your local web server to the internet using ngrok.

You can click here for more details. This step is important because the application won't work as expected if you run it using localhost.

ngrok http 8000

Once ngrok is running open up your browser and go to your ngrok URL. It will look something like this:

http://<sub-domain>.ngrok.io/

  1. Configure Twilio to call your webhooks.

    You will also need to configure Twilio to call your application via POST when phone calls are received on your Twilio Number. The configuration of Voice should look something like this:

    http://<sub-domain>.ngrok.io/call/incoming
    

    Configure SMS

How To Demo?

  1. Call your Twilio Phone Number. You will get a voice response:

For Programmable SMS, press one. For Voice, press any other key.

  1. Reply with 1.
  2. The specified phone for agent 1 will be called: agent1-phone.
  3. If agent1-phone is not answered in 30 seconds then agent2-phone will be called.
  4. In case the second agent doesn't answer the call, it will be logged as a missed call. You can see all missed calls in the main page of the running server at http://{sub-domain}.ngrok.io.
  5. Repeat the process but enter any key different to 1 to choose Voice.

Meta

  • No warranty expressed or implied. Software is as is. Diggity.
  • MIT License
  • Lovingly crafted by Twilio Developer Education.

About

Task Router with Servlets and Twilio

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 8

Languages