0.3.3 • Published 11 years ago

twilio-api v0.3.3

Weekly downloads
45
License
-
Repository
github
Last release
11 years ago

Add voice and SMS messaging capabilities to your Node.JS applications with node-twilio-api!

node-twilio-api

A high-level Twilio helper library to make Twilio API requests, handle incoming requests, and generate TwiML.

Also ships with Connect/Express middleware to handle incoming Twilio requests.

IMPORTANT: You will need a Twilio account to get started (it's not free). Click here to sign up for an account

Install

This project is in an alpha stage. You cannot install it (yet). Use at your own risk!

Features and Library Overview

Only voice calls are supported at this time, but I plan to implement the entire Twilio API over the next few months.

  • Manage accounts and subaccounts - Client.getAccount - Client.createSubAccount - Client.listAccounts - Account.load - Account.save - Account.closeAccount - Account.suspendAccount - Account.activateAccount
  • List available local and toll-free numbers - Account.listAvailableLocalNumbers - Account.listAvailableTollFreeNumbers
  • Manage Twilio applications - Account.getApplication - Account.createApplication - Account.listApplications - Application.load - Application.save - Application.delete
  • List calls and modify live calls
  • Place calls - Application.makeCall
  • Receive calls - Application incomingCall Event
  • Generate TwiML responses without writing any XML - I am a XML hater.

Todo

  • List and manage valid outgoing phone numbers
  • List and provision incoming phone numbers
  • Support for Twilio Connect Applications
  • List and manage conferences, conference details, and participants
  • Send/receive SMS messages - List SMS short codes and details
  • Access recordings, transcriptions, and notifications
  • Respond to fallback URLs

Usage

  1. Create a Client using your Account SID and Auth Token.
  2. Select your main account or a subaccount.
  3. Do stuff...
    • Call API functions against that account (i.e. place a call)
    • Write logic to generate TwiML when Twilio sends a request to your application (i.e. when an incoming call rings)
var express = require('express'),
    app = express.createServer();
var twilioAPI = require('twilio-api'),
	twilio = new twilioAPI.Client(ACCOUNT_SID, AUTH_TOKEN);
twilio.function(err, twapp) {
	if(err) throw err;
	var from = "+15105555555", to = "+16175551212";
	twapp.makeCall(from, to, {
		'timeout': 40
	});
	app.use(twapp.middleware() );
});

API Overview

Applications

twilio.createApp(...)

Creates an application

twilio.loadApp(account_sid, auth_token, app_sid, callback)

Loads an Application instance and returns it to the callback. callback is of the form: callback(err, twapp) where twapp is the loaded twilio.Application instance

A valid application must have a VoiceUrl, VoiceMethod, StatusCallback, StatusCallbackMethod, SmsUrl, SmsMethod, and SmsStatusCallback. Fallback URLs are ignored at this time.

twilio.Application

twapp.makeCall(from, to, options, onConnectCallback)

from - The phone number or client identifier to use as the caller id. If using a phone number, it must be a Twilio number or a Verified outgoing caller id for your account to - The phone number or client identifier to call. options - An object containing any additional options - sendDigits - A string of keys to dial after connecting to the number. Valid digits in the string include: any digit (0-9), '#', '*' and 'w' (to insert a half second pause). - ifMachine - Tell Twilio to try and determine if a machine (like voicemail) or a human has answered the call. Possible values are 'Continue', 'Hangup', and null (the default). - timeout - The integer number of seconds that Twilio should allow the phone to ring before assuming there is no answer. Default is 60 seconds, the maximum is 999 seconds.

Phone numbers should be formatted with a '+' and country code e.g., +16175551212 (E.164 format).

voiceRequest Event

Triggered when Twilio contacts this server and requests a TwiML response. This event will be triggered for incoming and outgoing calls.

outgoingCall Event

Triggered when Twilio connects an outgoing call placed with makeCall. You typically do not need to listen for this event; Instead, pass a onConnectCallback to the makeCall function.

incomingCall Event

Triggered when the Twilio

twapp.middleware()

Returns Connect/Express middleware that handles any request to VoiceURL, StatusCallback, SmsUrl, or SmsStatusCallback using the appropriate GET/POST methods for each.

Disclaimer

Blake Miner is not affliated with Twilio, Inc. in any way. Use this software AT YOUR OWN RISK. See LICENSE for more details.

0.3.3

11 years ago

0.3.2

11 years ago

0.3.1

12 years ago

0.3.0

12 years ago

0.2.2

12 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.1

12 years ago