Skip to content

Commit

Permalink
Add Pushbullet Device ID Support (#503)
Browse files Browse the repository at this point in the history
* Add Pushbullet Device ID Support

* Fix accidental remove of Telegram settings section
  • Loading branch information
JagandeepBrar authored and RickyGrassmuck committed Oct 28, 2017
1 parent 48c7b25 commit f99df59
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
5 changes: 4 additions & 1 deletion client/templates/admin/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ <h1>Admin</h1>
<p class="text-muted">Enter your API from Pushbullet. It can be found in Pushbullet Settings -> Access Token.</p>
<br>
{{> afQuickField name='pushbulletChannel' size="40"}}
<p class="text-muted"> Push Notifications to a channel. Must be the owner of the channel, click <a href="https://www.pushbullet.com/my-channel"> here </a> to create a new channel.</p>
<p class="text-muted"> Push Notifications to a channel (optional). Must be the owner of the channel, click <a href="https://www.pushbullet.com/my-channel"> here </a> to create a new channel. <i>Cannot be used in conjunction with a device ID.</i></p>
<br>
{{> afQuickField name='pushbulletDeviceID' size="40"}}
<p class="text-muted"> Push Notifications to a specific device (optional). <i>Cannot be used in conjunction with a channel tag.</i></p>
<br>

<p><button class="btn btn-secondary-outline" id="pushbulletTest">Test Pushbullet</button></p>
Expand Down
6 changes: 6 additions & 0 deletions lib/collections/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ var settings = new SimpleSchema ({
defaultValue: '',
optional: true
},
pushbulletDeviceID: {
type: String,
label: 'Pushbullet Device ID',
defaultValue: '',
optional: true
},
pushbulletENABLED: {
type: Boolean,
label: 'Enable Pushbullet notifications',
Expand Down
60 changes: 27 additions & 33 deletions server/methods/notifications/pushbulletNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,41 @@ Meteor.methods({

var access_token = settings.pushbulletAPI
var channel_tag = settings.pushbulletChannel
var device_id = settings.pushbulletDeviceID
var pushbullet_url = 'https://api.pushbullet.com/v2/pushes'
var payload = {}

//////// Create JSON object of http.post Parameters
if(typeof channel_tag === 'undefined' ) {
payload = {
headers: {
'Access-Token': access_token
},
params: {
type: 'note',
title: title,
body: body
},
timeout: 4000
}
logger.debug('Empty Channel')
} else {
payload = {
headers: {
'Access-Token': access_token
},
params: {
type: 'note',
title: title,
body: body,
channel_tag: channel_tag
},
timeout: 4000
}
logger.debug('channel_tag: ' + channel_tag)
//Return with error if both channel and device are defined
if(typeof channel_tag !== 'undefined' && typeof device_id !== 'undefined') {
var err = 'Please only use either a channel or a device ID in Pushbullet!'
logger.error('Pushbullet notification error: ' + err)
throw err
}

//Build base payload
var payload = {
headers: {
'Access-Token': access_token
},
params: {
type: 'note',
title: title,
body: body
},
timeout: 4000
}

////// Attempt to send notification with HTTP.post()
//Add channel or device id parameters to the payload if applicable
if(typeof channel_tag !== 'undefined' ) {
payload['params'].channel_tag = channel_tag
} else if(typeof device_id !== 'undefined') {
payload['params'].device_iden = device_id
}

//Attempt to send notification with HTTP.post()
try {
HTTP.post(pushbullet_url, payload)
return true
}

catch (error) {
} catch (error) {
var err = error.response.data.error.message
logger.error('Pushbullet notification error: ' + err)
throw err
Expand Down

0 comments on commit f99df59

Please sign in to comment.