Skip to content

matsev/serverless-twilio-dictionary

Repository files navigation

Serverless Twilio Dictionary

A serverless dictionary completely hosted in a Twilio account.

Architecture

architecture

The backend architecture has been implemented using the following four services:

Prerequisites

Setup

  1. Install npm dependencies

    npm install
  2. Install the @twilio-labs/plugin-serverless plugin

    npx twilio plugins:install @twilio-labs/plugin-serverless
  3. Log in to your Twilio account

  4. Buy a Twilio phone number, take note of the number.

  5. Rename the .env.twilio.example file to just .env.twilio

  6. Copy the values of ACCOUNT_SID, AUTH_TOKEN and the TWILIO_NUMBER (i.e. the phone number that you bought earlier) to the .env.twilio file

  7. Important: do not add the .env.twilio file to version control because it contains your Twilio account credentials

  8. 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]

  9. Optional, you can seed the dictionary with some entries using the ./scripts/upload.sh script

  10. You can verify the deployment by opening the [landing page url] mentioned in step 8 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

Usage

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

Clean Up

Execute the ./scripts/teardown.sh script

References

Developer Resources Online

CLI Tools

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

Acknowledgements

Thanks to Stefan Judis for support. Please also see his GitHub repo for a demo implementation of s Twilio SMS Serverless group chat.

About

A serverless dictionary completely hosted in a Twilio account

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published