Skip to content

Commit

Permalink
Add support for SMS, clipboard and dismissal
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwhitman committed Jan 6, 2016
1 parent ca8affe commit e75096a
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Default `devices` to active only.
- Default `subscriptions` to active only.
- Add chats functions.
- Add ephemerals support for sending SMS messages, clipboard messages and dismissals.

### 1.4.3

Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,50 @@ Unmute a chat.
```javascript
pusher.unmuteChat('udprOsjAsLtNTRAG', function(error, response) {});

### PushBullet.sendSMS(options, callback)

Send an SMS through a device.

```javascript
var options = {
source_user_iden: 'ujpah72o0', // The user iden of the user sending this message
target_device_iden: 'ujpah72o0sjAoRtnM0jc', // The iden of the device corresponding to the phone that should send the SMS
conversation_iden: '+1 303 555 1212', // Phone number to send the SMS to
message: 'Hello!' // The SMS message to send
};
pusher.sendSMS(options, function(error, response) {});
```

### PushBullet.sendClipboard(options, callback)

Send clipboard content.

```javascript
var options = {
source_user_iden: "ujpah72o0", // The iden of the user sending this message
source_device_iden: "ujpah72o0sjAoRtnM0jc", // The iden of the device sending this message
body: "http://www.google.com", // The text to copy to the clipboard
};
pusher.sendClipboard(options, function(error, response) {});
```

### PushBullet.dismissEphemeral(options, callback)

Dismiss an ephemeral.

```javascript
var options = {
package_name: 'com.pushbullet.android', // Set to the package_name field from the mirrored notification
notification_id: '-8', // Set to the notification_id field from the mirrored notification
notification_tag: null, // Set to the notification_tag field from the mirrored notification
source_user_iden: 'ujpah72o0', // Set to the source_user_iden field from the mirrored notification
};
pusher.dismissEphemeral(options, function(error, response) {});
```

### PushBullet.stream()

Returns a new stream listener which will emit events from the stream.
Expand Down
76 changes: 76 additions & 0 deletions lib/internal/ephemerals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var clone = require('clone');

var PushBullet = require('../pushbullet');

/**
* Send an SMS.
*
* The options require source_user_iden, target_device_iden, conversation_iden and message.
* See https://docs.pushbullet.com/#send-sms for details.
*
* @param {Object} smsOptions SMS options.
* @param {Function} callback Callback for when the request is complete.
*/
PushBullet.prototype.sendSMS = function sendSMS(smsOptions, callback) {
var options = clone(smsOptions);

options.package_name = 'com.pushbullet.android';
options.type = 'messaging_extension_reply';

this.sendEphemeral(options, callback);
};

/**
* Send clipboard content.
*
* The options require body, source_user_iden and source_device_iden.
* See https://docs.pushbullet.com/#universal-copypaste for details.
*
* @param {Object} clipOptions Clipboard options.
* @param {Function} callback Callback for when the request is complete.
*/
PushBullet.prototype.sendClipboard = function sendClipboard(clipOptions, callback) {
var options = clone(clipOptions);

options.type = 'clip';

this.sendEphemeral(options, callback);
};

/**
* Dismiss an ephemeral.
*
* The options require package_name, notification_id, notification_tag and source_user_iden.
* See https://docs.pushbullet.com/#dismissal-ephemeral for details.
*
* @param {Object} ephemerealOptions Ephemeral dismissal options.
* @param {Function} callback Callback for when the request is complete.
*/
PushBullet.prototype.dismissEphemeral = function dismissEphemeral(ephemerealOptions, callback) {
var options = clone(ephemerealOptions);

options.type = 'dismissal';

this.sendEphemeral(options, callback);
};

/**
* Send an ephemeral.
*
* @param {Object} ephemerealOptions Ephemeral options.
* @param {Function} callback Callback for when the request is complete.
*/
PushBullet.prototype.sendEphemeral = function sendEphemeral(ephemerealOptions, callback) {
var self = this;

var options = {
json: {
type: 'push',
push: ephemerealOptions
}
};

self.request.post(PushBullet.EPHEMERALS_END_POINT, options, function(error, response, body) {
self.handleResponse(error, response, body, callback);
});
};
2 changes: 2 additions & 0 deletions lib/pushbullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ PushBullet.USERS_END_POINT = PushBullet.API_BASE + '/users';
PushBullet.SUBS_END_POINT = PushBullet.API_BASE + '/subscriptions';
PushBullet.CHANNELS_END_POINT = PushBullet.API_BASE + '/channel-info';
PushBullet.CHATS_END_POINT = PushBullet.API_BASE + '/chats';
PushBullet.EPHEMERALS_END_POINT = PushBullet.API_BASE + '/ephemerals';

module.exports = PushBullet;

Expand Down Expand Up @@ -138,6 +139,7 @@ PushBullet.prototype.handleError = function handleError(error, response, body, c

require('./internal/chats');
require('./internal/devices');
require('./internal/ephemerals');
require('./internal/pushes');
require('./internal/subscriptions');
require('./internal/users');
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"author": "Alex Whitman <[email protected]>",
"license": "BSD",
"dependencies": {
"clone": "^1.0.2",
"mime": "~1.2.11",
"request": "~2.44.0",
"websocket": "~1.0.8"
Expand Down

0 comments on commit e75096a

Please sign in to comment.