1.2.4 • Published 1 year ago

twilio-pbx v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.

    • The email for missed call looks like below:

      Subject:    Missed call: +12120007890
      From:       12120007890@example.com
      To:         jmkim@jongmin.dev
      
      Missed call: +12120007890

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)

  • With the text forwarding, Text Alert email will be sent to TEXT_ALERT_TO_EMAIL_ADDRESS.

    • The email for incoming text looks like below:

      Subject:    New message: +12120007890
      From:       12120007890@example.com
      To:         jmkim@jongmin.dev
      
      Hey, this is Jongmin.
      Happy holiday o/

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.