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-serverlesspluginnpx 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_TOKENand theTWILIO_NUMBER(i.e. the phone number that you bought earlier) to the.env.twiliofile -
Important: do not add the
.env.twiliofile 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 step8above. 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 deployAfter 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
keyis the dictionary entry and one must be provided with all dictionary interactions. - The
definitionpart 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.