Skip to content

twilio-labs/twilio-flex-sample-backend

Repository files navigation

twilio-flex-sample-backend

This project is a demo backend service that supports various sample front end plugins to twilio flex

Services

To support outbound dialing with conference

It exposes a secure websocket with authentication that can be used to:

  • trigger a call from a client
  • push updates of the call status back to that client
  • hang up a call for a given client

It also exposes two end points that are called by twilio when:

  • providing updates to the status of calls generated by this server
  • twilio retrieves a twiml document to describe how to handle a call when it is answered

To support realtime statistics dashboard for queues

It exposes a secure websocket with authentication that can be used to:

  • recieve updates of stat changes
    • current queue stats updated every 5 seconds
    • todays overall stats updated every 30 seconds
    • turn stats on/off per channel
    • define your own SLA thresholds (max 3)

Dependencies

Before setting up this server you must first created a dedicated TaskRouter workflow for outbound calls. You can do this here. Make sure it is part of your Flex Task Assignment workspace.

  • ensure there is the following matching workers expression for the only filter on the workspace
    • task.targetWorker==worker.contact_uri
  • ensure the priorty of the filter is set to 1000 (or at least the highest in the system)
  • make sure the filter matches to a queue with Everyone on it. The default Everyone queue will work but if you want to seperate real time reporting for outbound calls, you should make a dedicated queue for it with a queue expression
    • 1==1

alt text

Setup

You can now setup the server, you can either deploy to heroku (which is free, you just need a login) or you can setup locally and expose via ngrok

Deploying to heroku

  1. Use this link to begin Deploy

  2. Populate the given variables when prompted

    • TWILIO_OUTBOUND_WORKFLOW_SID - the SID of the workflow you just created - used for creating tasks
    • TWILIO_ACCOUNT_SID - the account sid of your twilio account - used for calling Twilio APIs
    • TWILIO_AUTH_TOKEN - the auth token of your twilio account - used for calling Twilio APIs
    • TWILIO_FLEX_WORKSPACE_SID - TaskRouter Flex Assignment Workspace Sid, generated when creating a twilio flex project
    • EXTERNAL_HOST - the host that exposes this service - used for telling Twilio where to make callbacks when calling the Twilio APIs. Should be of the form <HEROKU_APP_NAME>.herokuapp.com
  3. You're all set, the backend is ready. You can access it on https://<HEROKU_APP_NAME>.herokuapp.com

Deploying locally

  1. Clone repository using git clone
  2. run npm install
  3. clone the .env.sample to .env
  4. update .env as approproate, descriptions above
  5. run ngrok http 3000
  6. start server using npm start

change log

v1.4 - added service that polls for real time stats ever 5 seconds and cumulative stats every 30 seconds, exposted via websocket

v1.3 - added authentication provider for websocket using api token provided by twilio via flex

v1.2 - migrated repository over to "twilio-flex-sample-backend" to be used with other plugins other than outbound dial, inroduced dotenv

v1.1 - updated websocket endpoint to reflect its dedicated to outbound calling

v1.0 - initial release

Code of Conduct

Please be aware that this project has a Code of Conduct. The tldr; is to just be excellent to each other ❤️

TODOs

About

Sample backend for a suite of Twilio Flex Plugin solutions

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages