Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Employee directory implementation with Java Servlets and Twilio

License

Notifications You must be signed in to change notification settings

TwilioDevEd/employee-directory-servlets

Repository files navigation

Twilio

Employee Directory with Servlets

Java Servlet CI

Use Twilio to accept SMS messages and translate them into queries against a SQLite database. These example functions show how to access an Employee Directory via SMS. A mobile phone user can send a text message with a partial string of the person's name and it will return their picture and contact information (Email address and Phone number).

Setup

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.

Twilio Account Settings

This application should give you a ready-made starting point for writing your own appointment reminder application. Before we begin, we need to collect all the config values we need to run the application:

Config Value Description
Account Sid Your primary Twilio account identifier - find this in the Console.
Auth Token Used to authenticate - just like the above, you'll find this here.
Phone number A Twilio phone number in E.164 format - you can get one here

Local Development

  1. First clone this repository and cd into it.

    git clone git@github.com:TwilioDevEd/employee-directory-servlets.git
    cd employee-directory-servlets
    
  2. Set your environment variables

    cp .env.example .env

See Twilio Account Settings to locate the necessary environment variables.

  1. Make sure the tests succeed.

    ./gradlew check
  2. Start the server.

    ./gradlew appRun

Expose the Application to the Wider Internet

  1. Expose your local web server to the internet using a tool like 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 8080

    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/

  2. Configure Twilio to call your webhooks.

    You will also need to configure Twilio to call your application when SMSs are received on your Twilio Number. The SMS & MMS Request URL should look something like this:

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

    The used method is HTTP POST.

    Configure SMS

That's it!

Running the app

Each time the applications loads the IndexServlet#init function will create a new SQLite database called employee_db.sqlite, seeded with data from the seed-data.json file, i.e., Data provided by Marvel. © 2016 MARVEL.

  1. You can query the employees by sending SMSs to your Twilio Phone Number.

  2. To query employees in your application directly from the web check http://localhost:8080 or the http://<sub-domain>.ngrok.io domain generated by ngrok.

How To Demo?

  1. Text your twilio number the name "Iron".

  2. Should get the following response.

    We found multiple people, reply with:
    1 for Iron Man
    2 for Iron Clad
    Or start over
    
  3. Reply with 1.

  4. Should get the following response.

    Iron Man
    +14155559368
    +1-202-555-0143
    IronMan@heroes.example.com
    [the image goes here]
    
  5. If your query matches only one employee, he/she will be returned immediately.

    Eg.: "Spider" will return in the web version:

    Query an employee partially

Meta

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

About

Employee directory implementation with Java Servlets and Twilio

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published