npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twilio-pbx

v1.2.4

Published

A Virtual PBX Server for Twilio (Supports standalone Node.js server and Firebase Cloud Functions)

Downloads

9

Readme

twilio-pbx: A Virtual PBX Server for Twilio

A Virtual PBX Server for Twilio. Supports standalone Node.js server and Firebase Cloud Functions.

  1. How to use
    1. Call modes
    2. Text modes
  2. How to install
    1. Node.js Standalone server
    2. Firebase Cloud Functions
  3. APIs
  4. Environmental variables

How to use

Call modes

Call Command mode

(Make a call)

  • To make a call:
    1. Call to your Twilio number, from one of CALL_COMMAND_PHONE_NUMBER.
    2. In the call, you can dial the number.
    3. In the call, a new call will be made with your Twilio number, to the dialed number.

Call Forwarding mode

(Receive a call)

Call Alert

(Alert the call: incoming call and missed call)

  • With the call forwarding, Call Alert will be sent to your Twilio number.

    • If you have multiple Twilio numbers, this will help you identify the number which has the call.

    • The message for incoming call looks like below:

      Incoming call: +12120007890 (US)
      Name: KIM,JONGMIN
      Carrier: T-Mobile USA, Inc. (mobile)
      • You can control the information included in the message:
        • CALL_SHOW_CARRIER controls the carrier lookup (0.005 USD per a call, billed by Twilio)

          Incoming call: +12120007890 (US)
          Carrier: T-Mobile USA, Inc. (mobile)
        • CALL_SHOW_CALLER_ID controls the Caller ID lookup (0.01 USD per a call, billed by Twilio)

          Incoming call: +12120007890 (US)
          Name: KIM,JONGMIN
        • If both flags disabled, the message would be like below:

          Incoming call: +12120007890 (US)
  • When you missed the call, Call Alert will be sent to your email CALL_ALERT_TO_EMAIL_ADDRESS.

Text modes

Text Command mode

(Send a message)

  • Text to your Twilio number, from one of TEXT_COMMAND_PHONE_NUMBER.

  • The message format should follow below:

    TO_NUMBER:MESSAGE_BODY
  • Examples:

    • Single-line text example:

      +12120007890:Hi
      • will send below message to +1 (212) 000-7890:

        Hi
    • Multi-line text example:

      +821000337890:Hey, this is Jongmin.
      Happy holiday o/
      • will send below message to +82 10-0033-7890:

        Hey, this is Jongmin.
        Happy holiday o/

Text Forwarding mode

(Receive a message)

Text Alert

(Alert the text: incoming text)

How to install

twilio-pbx supports two ways for deployment: one is Node.js Standalone server and another is Firebase Cloud Functions.

Option 1: Node.js Standalone server

  1. Install npm dependencies

    npm install
  2. Copy the .env file from .env.template

    cp .env.template .env
  3. Edit the .env file

  4. Run the server

    npm run start

Option 2: Firebase Cloud Functions

  1. Make ready the Firebase Cloud Functions

    • Create the project at firebase.google.com.

    • Make sure the billing is activated, which is required by the Firebase Cloud Functions.

      • Note: Firebase Cloud Functions is only available with paid account. It does not offer the free trial.
    • Install and login to Firebase

      npm install -g firebase-tools # Globally install the Firebase CLI Tools
      firebase login                # Login
  2. Copy the .firebaserc file from .firebaserc.template

    cp .firebaserc.template .firebaserc
  3. Set the actual project name in .firebaserc

    • Replace FIREBASE_PROJECT_NAME_HERE with the actual project name
  4. Copy the .env file from .env.template

    cp .env.template .env
  5. Edit the .env file

  6. Emulate the server in local machine

    npm run serve
  7. Deploy the server to the Firebase Cloud Functions

    npm run deploy

APIs

POST /calls

POST /calls/command

POST /calls/dial

POST /calls/dial/result

  • Speak back the result of the call, and then hang up

POST /calls/forward

POST /calls/forward/result

  • Speak back the result of the call, and then hang up

POST /texts

POST /texts/command

  • Text Command mode

  • Send the outbound text, when the inbound text is following format:

    TO_NUMBER:MESSAGE_BODY

POST /texts/forward

Environmental variables

Environmental variables could be stored in .env file in the root directory. The example template is located at .env.template.

TWILIO_PBX_URI_BASE

  • Base URI to bind and run the Twilio PBX server
  • It must include the trailing /.
  • format: string
  • example:
    • / if deployed on local
    • /pbx/ if deployed on Firebase Cloud Functions
    • Again, do not forget the trailing /.

TWILIO_PBX_PORT

  • Port number to bind and run the Twilio PBX server
  • format: int
  • example: 3000

SENDGRID_API_KEY

  • SendGrid API key
  • format: string

SENDGRID_API_PATH

  • SendGrid API endpoint
  • format: uri
  • default: https://api.sendgrid.com/v3/mail/send

TWILIO_ACCOUNT_SID

  • Twilio account SID
  • format: string

TWILIO_AUTH_TOKEN

  • Twilio auth token
  • format: string

CALL_ALERT_FROM_EMAIL_ADDRESS

CALL_ALERT_FROM_EMAIL_DOMAIN_ONLY

CALL_ALERT_TO_EMAIL_ADDRESS

  • Destination email address to receive the Call Alert
  • format: string - email

CALL_COMMAND_PHONE_NUMBER

CALL_COMMAND_TIMEOUT

  • Timeout for waiting the number press in the Call Command mode
  • format: int - positive integer, in seconds

CALL_RECEIVE_US_PHONE_NUMBER

CALL_RECEIVE_INTL_PHONE_NUMBER

  • Destination phone number for non-US Twilio number Call Forwarding mode
  • format: string - E.164 formatted phone number
  • example: +821000337890
  • notes:
    • Twilio blocks the message outbound to US for non-US Twilio numbers.
    • If you set the US number here for non-US Twilio number, you cannot receive the Call Alert message.

CALL_RECEIVE_TIMEOUT

  • Timeout for waiting the destination phone response in the Call Forwarding mode
  • format: int - positive integer, in seconds

CALL_SHOW_CARRIER

  • Flag for include the carrier information in the Call Alert
  • format: int - 0 or 1
  • notes:
    • It uses Twilio Lookup API - Carrier
    • It costs additional 0.005 USD per a call

CALL_SHOW_CALLER_ID

  • Flag for include the Caller ID in the Call Alert
  • format: int - 0 or 1
  • notes:
    • It uses Twilio Lookup API - Carrier
    • It costs additional 0.01 USD per a call

TEXT_ALERT_FROM_EMAIL_ADDRESS

TEXT_ALERT_FROM_EMAIL_DOMAIN_ONLY

  • Flag if the value of TEXT_ALERT_FROM_EMAIL_ADDRESS is domain only or not
  • format: int - 0 or 1
  • notes:
    • If the value is 1, Twilio PBX will generate the email sender as following format:

TEXT_ALERT_TO_EMAIL_ADDRESS

  • Destination email address to receive the Text Alert
  • format: string - email

TEXT_COMMAND_PHONE_NUMBER

  • Source phone number for the Text Command mode
  • format: , seperated string - E.164 formatted phone number
  • example: +12120007890,+821000337890
  • notes:
    • Twilio blocks the message outbound to US for non-US Twilio numbers.
    • If you set the US number here for non-US Twilio number, you cannot receive the command response.
    • If you send to the US number from non-US Twilio number, it will be undelivered silently.

TEXT_RECEIVE_US_PHONE_NUMBER

TEXT_RECEIVE_INTL_PHONE_NUMBER

  • Destination phone number for non-US Twilio number Text Forwarding mode
  • format: string - E.164 formatted phone number
  • example: +821000337890
  • notes:
    • Twilio blocks the message outbound to US for non-US Twilio numbers.
    • If you set the US number here for non-US Twilio number, you cannot receive the Text Alert message.