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).
- 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.
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 |
-
First clone this repository and
cd
into it.git clone git@github.com:TwilioDevEd/employee-directory-servlets.git cd employee-directory-servlets
-
Set your environment variables
cp .env.example .env
See Twilio Account Settings to locate the necessary environment variables.
-
Make sure the tests succeed.
./gradlew check
-
Start the server.
./gradlew appRun
-
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/
-
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.
That's it!
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.
-
You can query the employees by sending SMSs to your Twilio Phone Number.
-
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.
-
Text your twilio number the name "Iron".
-
Should get the following response.
We found multiple people, reply with: 1 for Iron Man 2 for Iron Clad Or start over
-
Reply with 1.
-
Should get the following response.
Iron Man +14155559368 +1-202-555-0143 IronMan@heroes.example.com [the image goes here]
-
If your query matches only one employee, he/she will be returned immediately.
Eg.: "Spider" will return in the web version:
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio Developer Education.