Our call center uses two of Twilio's orchestration products, Studio and TaskRouter. To support our Studio environment, we use Twilio's runtime for serverless functions. To support our TaskRouter environment, we use a NodeJS server, presently on Heroku.
This repo supports both. We have three main root folders: src, test, and twilio_serverless. src contains our NodeJS server. twilio_serverless contains the serverless dev environment. Lastly test will contain the tests for both halves.
- Readme for the NodeJS Server
- Readme for the serverless runtime
For the NodeJS server, the root of the project (not code) is the root of the
repo, you would npm install
& npm run
in the same folder as this readme.
A web api server for managing a Twilio IVR system and using airtable as a front end for configurations.
- Have NodeJS 12.16.x or greater installed
- Copy
.env-sample
to.env
(.env is git ignored)$ cp .env-sample .env
- Replace the values in your new
.env
file- PORT: The port the server will listen on
- ACCOUNT_SID: Twilio account sid
- AUTH_TOKEN: Twilio auth token
- WORKSPACE_SID: Twilio taskrouter workspace sid
- PHONE_BASE: base id for a phone Airtable base
- AIRTABLE_VM_PHONE_BASE: base id for the VM base
- AIRTABLE_DELAY: delay in milliseconds between checking the airtable bases
- AIRTABLE_API_KEY: airtable api key
- TWILIO_TASKROUTER_VM_SID: SID of the worker that represents VM
- HOST_NAME: Your hostname for example www.google.com
- CALLER_ID: Your caller ID from which text messages are sent. Must be an available Caller ID for the account
- Optional variables, omittance = false
- ENABLE_VM:
true
orfalse
, enables or disables voicemail recordings - ENABLE_VM_ENGLISH_TRANSCRIPTION:
true
orfalse
enables of disable transcription of english VMs - ENABLE_ANSWER_MACHINE_DETECTION:
true
orfalse
enables automatic answer machine detection (AMD) when calling volunteers
- ENABLE_VM:
- Run
$ npm install
$ npm test
- Runs the mocha test suite$ npn run debug
- Used by VSCode$ npm start
- Starts a local server using nodemon which will re-run the project on every file save$ npm run coverage
- Starts an Istanbul test coverage report.- Will generate a simplified report to console
- Will generate and open in browser a more detailed report
- Generated files are git ignored
- A
launch.json
file is included with some settings to debug the server with VSCode- Select 'Launch via NPM' in the debugger menu This will start a local server and attach it to vscode. Output will be in the debug console instead of terminal.
- Select 'Mocha Tests' to run the tests and attach it to the vscode debugger
- Ensure your .env file is created, heroku will load the environment variables
- Run
heroku local
For the serverless runtime, the root of the project is in ./twilio_serverless
relative to this
readme. You would npm install
& npm run
from that folder.
Twilio Studio Flows are great but their default abilities are not very fancy. If we need to have fancy customized features like a dynamic schedule (as we do) Twilio allows for serverless functions in their runtime environment for customized behavior.
While twilio allows for functions to be written using their UI only website to create new functions(need access to a Twilio account), there is no version control to see revisions within Twilio. As such we have decided to use their api (needs access to a Twilio account) to allow us to deploy from git repositories that do have revision history.
-
Have nodeJS installed locally
-
Have NVM installed locally and use node version of 10.17.0 while developing. Verify using the command
node -v
-
Have NPM installed, verify with the command
npm -v
-
Clone the repository to your local machine
-
Within the repo, run:
npm install
-
In the root directory of the project, create a
.env
file -
Request from an admin, API key and the secret
-
Create
.env
in the root of the project file- Copy
.env-sample
to.env
with the command:$ cp .env-sample .env
- Change the values in
.env
file, by getting the Twilio API sid and auth_token or having an administrator provide it to you. This will NOT be committed to git for security as it is git ignored.ACCOUNT_SID
: The Account SIDAUTH_TOKEN
: Auth Token
- If you add any addition key=value pairs, they will be uploaded to twilio as a environment variable within the twilio api serverless environment. It will also be available during local development.
- Copy
- Can only be used for functions that service webhooks, not for functions used in Twilio Studio
- Start a locally running server with the command '$ npm start`
- Do note any warnings like wrong version of NodeJS and resolve as needed.
- Use a tool to expose your computer's local server using something like ngrok
- Point twilio services i.e Phone numbers, TaskRouter or Studio Redirect Widgets to use the locally running server instead of the serverless functions or hosted private/public assets
- This will only work if you provide Twiml responses such as TwiML™ for Programmable Voice
- JSON responses such as
Twilio.Response()
don't appear to work for passing variables back into Studio flows
$ npm run deploy
$ npm run deploy-dev