A serverless dictionary completely hosted in a Twilio account.
The backend architecture has been implemented using the following four services:
- Twilio Phone Numbers for registering and managing a virtual phone number
- Twilio Functions for backend application hosting
- Twilio Sync for data persistence
- Twilio Assets for hosting the app landing page
- Node.js (see the .nvmrc file for current version)
- A Twilio account at https://www.twilio.com
- jq
-
Install npm dependencies
npm install
-
Install the
@twilio-labs/plugin-serverless
pluginnpx twilio plugins:install @twilio-labs/plugin-serverless
-
Log in to your Twilio account
-
Buy a Twilio phone number, take note of the number.
-
Rename the .env.twilio.example file to just
.env.twilio
-
Copy the values of
ACCOUNT_SID
,AUTH_TOKEN
and theTWILIO_NUMBER
(i.e. the phone number that you bought earlier) to the.env.twilio
file -
Important: do not add the
.env.twilio
file to version control because it contains your Twilio account credentials -
Execute the ./scripts/setup.sh script, take note of the url output after
Setup complete! See landing page url for more instructions: [landing page url]
-
Optional, you can seed the dictionary with some entries using the ./scripts/upload.sh script
-
You can verify the deployment by opening the
[landing page url]
mentioned in step8
above. You will see your Twilio phone number as well as links to your Twilio Sync Service and Twilio Functions in your Twilio account where these services have been deployed.
After the initial deployment you can execute the following command to update your function:
npx twilio-run deploy
After installation, you can interact with the dictionary by sending SMS CRUD (create, read update and delete) commands to you Twilio phone number:
[command] key [definition]
- There are four commands (see list below). You can use either the full command or just a single character abbreviation. If omitted, the command defaults to
read
. - The
key
is the dictionary entry and one must be provided with all dictionary interactions. - The
definition
part is used when creating or updating the meaning of different words.
Command | Abbreviation | Comment |
---|---|---|
create |
c |
Creates a new entry in the dictionary |
read |
r |
Reads an entry from dictionary (default command) |
update |
u |
Updates a dictionary entry |
delete |
d |
Deletes a dictionary entry |
Examples:
create TLA Three Letter Acronym
Adds the entry TLA
with the definition Three Letter Acronym
to the dictionary
read TLA
or just
TLA
reads the value of the TLA
entry.
For convenience, the service also has a public API endpoint and you can use the ./scripts/post.sh script and the same command syntax as above to send commands, e.g.
./scripts/post.sh delete TLA
Execute the ./scripts/teardown.sh script
Tool | Example | Reference |
---|---|---|
Twilio CLI tool | npx twilio --help |
twilio |
Twilio Run CLI tool | npx twilio-run --help |
twilio-run |
Twilio Serverless CLI plugin | npx twilio-run serverless --cwd . |
plugin-serverless |
Thanks to Stefan Judis for support. Please also see his GitHub repo for a demo implementation of s Twilio SMS Serverless group chat.