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.
- Java 8 installed in your operative system.
- 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).
- First clone this repository and
cd
into it.
git clone git@github.com:TwilioDevEd/task-router-servlets.git
cd task-router-servlets
- 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.
- Make sure the tests succeed.
./gradlew check
- 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.
- Start the server.
./gradlew appRun
- 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/
-
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
- Call your Twilio Phone Number. You will get a voice response:
For Programmable SMS, press one. For Voice, press any other key.
- Reply with 1.
- The specified phone for agent 1 will be called: agent1-phone.
- If agent1-phone is not answered in 30 seconds then agent2-phone will be called.
- 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.
- Repeat the process but enter any key different to 1 to choose Voice.
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio Developer Education.