Code Monkey home page Code Monkey logo

twilio-flex-sample-backend's Introduction

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

twilio-flex-sample-backend's People

Contributors

jared-hunter avatar sagarvd01 avatar temitope avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

twilio-flex-sample-backend's Issues

Moving to twilio-labs

Hi @jhunter-twilio :)

I'm happy to move this into Twilio Labs. Could you please check the following things first.

  • Clearly mark a core maintainer in the repo. One way to do this to specify the "author" in the package.json file or by specifying a Maintainer in the Readme somewhere
  • Link to the Code of Conduct. You can see an example in twilio-labs/plugin-serverless

Thank you,
Dominik

"npm install" fails. Is a specific node version required ?

Im trying to run npm install

I have used nvm to attempt this command on multiple versions with various results. none of which have been successful. I can share more output if helpful, but if there is a target version for success that will be helpful


11.15.0
10.4.0
9.10.0
8.14.0
8.9.3
6.11.5

Output errors on node 8 and higher

12 warnings and 15 errors generated.
make: *** [Release/obj.target/validation/src/validation.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit
...
gyp ERR! command "/.nvm/versions/node/v9.10.0/bin/node" ".nvm/versions/node/v9.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /outbound-dialing-backend/node_modules/utf-8-validate

results from npm audit

npm audit
                                                                                
                       === npm audit security report ===                        
                                                                                
# Run  npm install [email protected]  to resolve 1 vulnerability
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ clean-css                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ pug                                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ pug > pug-filters > clean-css                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/785                             │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Denial of Service                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ws                                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >= 1.1.5 <2.0.0 || >=3.3.1                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ express-websocket                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ express-websocket > ws                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/550                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ DoS due to excessively large websocket message               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ws                                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=1.1.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ express-websocket                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ express-websocket > ws                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/120                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Remote Memory Disclosure                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ws                                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >= 1.0.1                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ express-websocket                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ express-websocket > ws                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/67                              │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 4 vulnerabilities (2 low, 2 high) in 489 scanned packages
  run `npm audit fix` to fix 1 of them.
  3 vulnerabilities require manual review. See the full report for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.