Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[lib] now allows multiple outgoing numbers

  • Loading branch information...
commit 66a9abe3e8bfcc6481f853a3a4e401452779b73a 1 parent 81c8a86
Paolo Fragomeni authored
View
33 README.md
@@ -1,4 +1,3 @@
-# NOT READY YET! WORK IN PROGRESS!
# Synopsis
Multi-vendor cellular network services for node.js
@@ -9,7 +8,6 @@ Everything else sucks
# Features
- Send SMS
- Make and Recieve Phone calls
-- Simple API
# Providers
- Twillio (SMS, Call)
@@ -55,12 +53,32 @@ exports.Container = {
var client = new Telenode(new Telenode.providers.foobar);
//
-// This will output some text to the console.
+// This is a contrived example that will simply output text to the console,
+// but it demonstrates how the module will be attached to the instance.
//
client.Container.getTheSameInfo();
client.Container.getSomeInfo();
```
+Often your API service will want to let you know after some operation has finished. The plugin structure provides a web server to listen for API services that want to call back. In your provider module, you can add routes for this.
+
+```js
+exports.getSomeInfo = function() {
+
+ this.HTTP.route({
+
+ '/inbound/url/sample/',
+ 'POST',
+ function(data) {
+
+ //
+ // handle the inbound request from the API service.
+ //
+ }
+ });
+};
+```
+
# Installation
@@ -69,3 +87,12 @@ client.Container.getSomeInfo();
# API
# License
+(The MIT License)
+
+Copyright (c) 2010 hij1nx <http://www.twitter.com/hij1nx>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
0  credentials/credentials.sample → credentials/credentials.json.sample
File renamed without changes
View
70 lib/providers/twilio.js
@@ -87,6 +87,8 @@ exports.SMS = {
//
send: function(params, callback) {
+ var that = this;
+
if (!this.configured) {
this.configure();
}
@@ -94,37 +96,53 @@ exports.SMS = {
if (!params.from || !params.to || !params.body) {
throw new Error('Required: From, To, and Body argument');
}
- var params = {
- From: params.from.replace(/-/g, ''),
- To: params.to.replace(/-/g, ''),
- Body: params.body
- };
-
- if (params.uri) {
- params.StatusCallback = params.uri;
- }
- var body = querystring.stringify(params);
- var headers = {};
+ function sendSMS(to) {
- headers['Content-Length'] = body.length;
- headers['Content-Type'] = 'application/x-www-form-urlencoded';
- headers['Authorization'] = 'Basic ' + this.basicAuth;
+ var payload = {
+ From: params.from.replace(/-/g, ''),
+ To: to || params.to.replace(/-/g, ''),
+ Body: params.body
+ };
- request(
- {
- method: 'POST',
- uri: this.base + '/SMS/Messages.json',
- headers: headers,
- body: body
- },
- function (err, response, body) {
+ if (payload.uri) {
+ payload.StatusCallback = params.uri;
+ }
- if (callback) {
- return err ? callback(err) : callback(null, body);
+ var body = querystring.stringify(payload);
+ var headers = {};
+
+ headers['Content-Length'] = body.length;
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
+ headers['Authorization'] = 'Basic ' + this.basicAuth;
+
+ request(
+ {
+ method: 'POST',
+ uri: that.base + '/SMS/Messages.json',
+ headers: headers,
+ body: body
+ },
+ function (err, response, body) {
+
+ if (callback) {
+ return err ? callback(err) : callback(null, body);
+ }
}
- }
- );
+ );
+ }
+
+ if (Array.isArray(params.to)) {
+
+ params.to.forEach(function(recip) {
+
+ sendSMS(recip);
+ });
+ }
+ else {
+
+ sendSMS();
+ }
return this;
}
View
2  test/twilio-sms-test.js
@@ -30,6 +30,6 @@ client.SMS.send(
// sid that we sent in the original POST request.
//
data = JSON.parse(data);
- assert.equal(data.sid, cred.sid);
+ assert.equal(data.sid, creds.sid);
}
);
Please sign in to comment.
Something went wrong with that request. Please try again.