2013-10-30 21:38:23 +01:00
<!--
2015-01-27 08:08:54 +01:00
Copyright 2013,2015 IBM Corp.
2013-10-30 21:38:23 +01:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
2015-01-27 08:08:54 +01:00
<!-- PUSHBULLET CONFIG -->
< script type = "text/x-red" data-template-name = "pushbullet-config" >
< div class = "form-row" >
< label for = "node-config-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
< input type = "text" id = "node-config-input-name" placeholder = "Name" >
< / div >
< div class = "form-row" >
< label for = "node-config-input-apikey" > < i class = "fa fa-lock" > < / i > API-key< / label >
< input type = "password" id = "node-config-input-apikey" >
< / div >
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('pushbullet-config', {
category: 'config',
color: "rgb(218, 196, 180)",
defaults: {
name: {value: ""}
},
credentials: {
apikey: {type: "password"}
},
label: function() {
return this.name || "Pushbullet config";
}
});
< / script >
<!-- PUSHBULLET OUT -->
2013-10-30 21:38:23 +01:00
< script type = "text/x-red" data-template-name = "pushbullet" >
< div class = "form-row" >
2015-01-27 08:08:54 +01:00
< label for = "node-input-config" > < i class = "fa fa-user" > < / i > Config< / label >
< input type = "text" id = "node-input-config" >
< / div >
< div class = "form-row" >
< label for = "node-input-deviceid" > < i class = "fa fa-mobile" > < / i > Device ID< / label >
< select id = "node-input-deviceid" >
< option value = "" > All< / option >
< option value = "_msg_" > - set from msg.deviceid -< / option >
< / select >
2013-10-30 21:38:23 +01:00
< / div >
2014-11-10 17:42:49 +01:00
< div class = "form-row" >
< label for = "node-input-chan" > < i class = "fa fa-random" > < / i > Channel< / label >
< input type = "text" id = "node-input-chan" placeholder = "channel name" >
< / div >
2014-04-23 22:06:36 +02:00
< div class = "form-row" >
2015-01-27 08:08:54 +01:00
< label for = "node-input-pushtype" > < i class = "fa fa-dot-circle-o" > < / i > Type< / label >
< select id = "node-input-pushtype" >
< optgroup label = "Push types" >
< option value = "address" > Address< / option >
< option value = "file" > File< / option >
< option value = "link" > Link< / option >
< option value = "list" > List< / option >
< option value = "note" > Note< / option >
< option value = "" > - set from msg.pushtype -< / option >
< / optgroup >
< optgroup label = "Actions" >
< option value = "delete" > Delete push< / option >
< option value = "dismissal" > Dismiss push< / option >
< option value = "updatelist" > Update list< / option >
< / optgroup >
< / select >
2014-04-23 22:06:36 +02:00
< / div >
< div class = "form-row" >
2015-01-27 08:08:54 +01:00
< label for = "node-input-title" > < i class = "fa fa-random" > < / i > Title< / label >
< input type = "text" id = "node-input-title" placeholder = "Node-RED" >
2014-04-23 22:06:36 +02:00
< / div >
2013-10-30 21:38:23 +01:00
< div class = "form-row" >
2014-09-03 17:12:26 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
2013-10-30 21:38:23 +01:00
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
2015-01-27 08:08:54 +01:00
< div class = "form-tips" id = "pushbullet-migration-info" style = "display: none;" >
< p > < i class = "fa fa-random" > < / i > Configuration node has been migrated, please click Ok and then re-deploy flow to save settings.< / p >
< / div >
2013-10-30 21:38:23 +01:00
< / script >
< script type = "text/x-red" data-help-name = "pushbullet" >
2015-01-27 08:08:54 +01:00
< p > Uses PushBullet to push < code > msg.payload< / code > to a device that has the PushBullet app installed.< / p >
< p > Optionally uses < code > msg.topic< / code > to set the title, if not already set in the properties.< / p >
< p > Optionally uses < code > msg.pushtype< / code > to set the type of the push, if not already set in the properties.< / p >
< p > Optionally uses < code > msg.deviceid< / code > to set the device ID, if not already set in the properties.< / p >
< p > You can also push to any channels that you own either configured or via < code > msg.channel< / code > .< / p >
< p > The node can also < i > dismiss< / i > and < i > delete< / i > and < i > update< / i > items in a pushed list. In this case < code > msg.data.iden< / code > must be set to a valid push id, if < code > msg< / code > originates from the Pushbullet input node this value is already set.< / p >
< p > The old method of storing your credentials in the pushkey.js file in the directory above /node-red is deprecated.< / p >
2013-10-30 21:38:23 +01:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('pushbullet',{
2015-09-16 23:38:38 +02:00
category: 'mobile-outpit',
2013-10-30 21:38:23 +01:00
defaults: {
2015-01-27 08:08:54 +01:00
config: {type: "pushbullet-config", required: true},
pushtype: {value:"note"},
2013-10-30 21:38:23 +01:00
title: {value:""},
2014-11-10 17:42:49 +01:00
chan: {value:"" },
2013-10-30 21:38:23 +01:00
name: {value:""}
},
2015-01-27 08:08:54 +01:00
credentials: {
deviceid: {value: ""},
pushkey: {value: ""}
},
2013-10-30 21:38:23 +01:00
color:"#a7c9a0",
inputs:1,
outputs:0,
icon: "bullet.png",
align: "right",
label: function() {
2015-01-27 08:08:54 +01:00
var self = this;
function getName(deviceid) {
if(!self.devicename & & deviceid & & self.config) {
$.getJSON('pushbullet/'+self.config+'/devices', function(data) {
for(var i=0; i< data.length ; i + + ) {
if(data[i].iden === deviceid) {
self.devicename = data[i].nickname;
self.dirty = true;
RED.view.redraw();
return;
}
}
});
}
}
2015-04-16 11:58:34 +02:00
try {
2015-01-27 08:08:54 +01:00
getName(this.credentials.deviceid);
}
catch(err) {
$.getJSON('credentials/pushbullet/'+this.id, function(data) {
getName(data.deviceid);
});
}
return this.name||this.devicename||this.title||"pushbullet";
2013-10-30 21:38:23 +01:00
},
labelStyle: function() {
return this.name?"node_label_italic":"";
2014-04-23 22:06:36 +02:00
},
2015-01-27 08:08:54 +01:00
oneditsave: function() {
this.devicename = undefined;
if(this.migrationData) {
$.ajax('pushbullet/'+this.id+'/migrate?save=true');
}
},
2014-04-23 22:06:36 +02:00
oneditprepare: function() {
2015-01-27 08:08:54 +01:00
var node = this, ddConfig = $('#node-input-config'), ddDevice = $('#node-input-deviceid'), ddPushtype = $('#node-input-pushtype');
function updateDeviceList() {
if(!ddConfig.val()) {
ddDevice.children().remove();
2015-04-16 11:58:34 +02:00
ddDevice.append('< option value = "" > All< / option > ');
ddDevice.append('< option value = "_msg_" > - set from msg.deviceid -< / option > ');
2015-01-27 08:08:54 +01:00
var currentDevice;
if(node.credentials) {
currentDevice = node.credentials.deviceid;
}
if(currentDevice & & currentDevice !== "_msg_") {
ddDevice.append('< option value = "'+currentDevice+'" > '+currentDevice+'< / option > ');
ddDevice.val(currentDevice);
}
2014-04-23 22:06:36 +02:00
}
2015-01-27 08:08:54 +01:00
else {
2015-04-16 11:58:34 +02:00
var config = RED.nodes.node(ddConfig.val()),
2015-01-27 08:08:54 +01:00
url = 'pushbullet/'+ddConfig.val()+'/devices';
if(config & & config.credentials & & config.credentials.apikey) {
url += '?apikey='+config.credentials.apikey;
}
$.getJSON(url, function(data) {
ddDevice.children().remove();
2015-04-16 11:58:34 +02:00
ddDevice.append('< option value = "" > All< / option > ');
ddDevice.append('< option value = "_msg_" > - set from msg.deviceid -< / option > ');
2015-01-27 08:08:54 +01:00
var currentDevice, addCurrent = true;
if(node.credentials) {
currentDevice = node.credentials.deviceid;
}
for(var i=0; i< data.length ; i + + ) {
var dev = data[i];
ddDevice.append('< option value = "'+dev.iden+'" > '+dev.nickname+' ('+dev.kind+')< / option > ');
if(dev.iden === currentDevice) {
addCurrent = false;
}
}
if(currentDevice) {
if(addCurrent & & currentDevice !== "_msg_") {
ddDevice.append('< option value = "'+currentDevice+'" > '+currentDevice+'< / option > ');
}
ddDevice.val(currentDevice);
}
2015-04-16 11:58:34 +02:00
});
2014-04-23 22:06:36 +02:00
}
}
2015-01-27 08:08:54 +01:00
function checkMigration(cb) {
$.getJSON('pushbullet/'+node.id+'/migrate', function(data) {
var showMigration = false;
node.migrationData = data.config;
if(data.migrated) {
if(data.config) {
var configId = data.config;
var configType = 'pushbullet-config';
var configTypeDef = RED.nodes.getType(configType);
RED.nodes.add({
type: configType,
id: configId,
name: "Imported",
users: [node.id],
label: configTypeDef.label,
_def: configTypeDef,
});
}
if(node.credentials) {
if(node.credentials.pushkey) {
if(ddConfig.find('option[value="'+data.config+'"]').length === 0) {
ddConfig.append('< option value = "'+data.config+'" > Imported< / option > ');
}
ddConfig.val(data.config);
showMigration = true;
}
else {
ddConfig.val("_ADD_");
}
if(node.credentials.deviceid) {
ddDevice.append('< option value = "'+node.credentials.deviceid+'" > Imported< / option > ');
ddDevice.val(node.credentials.deviceid);
showMigration = true;
}
else {
ddDevice.val("");
}
}
}
if(showMigration) {
ddPushtype.val("note");
node.dirty = true;
$('#pushbullet-migration-info').show();
}
if(cb) {
cb(showMigration);
}
});
}
checkMigration(function(migrated) {
if(!migrated) {
ddConfig.change(function() {
if(ddConfig.val() & & ddConfig.val() !== "_ADD_") {
updateDeviceList();
}
});
}
2014-04-23 22:06:36 +02:00
});
2015-01-27 08:08:54 +01:00
}
});
< / script >
<!-- PUSHBULLET IN -->
< script type = "text/x-red" data-template-name = "pushbullet in" >
< div class = "form-row" >
< label for = "node-input-config" > < i class = "fa fa-user" > < / i > Config< / label >
< input type = "text" id = "node-input-config" placeholder = "Node-RED" >
< / div >
< div class = "form-row" >
< label for = "node-input-filters" > < i class = "fa fa-mobile" > < / i > Device filter< / label >
< select id = "node-input-filters" style = "width: 60%;" multiple = "multiple" > < / select >
< / div >
< div class = "form-row" >
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > Name< / label >
< input type = "text" id = "node-input-name" placeholder = "Name" >
< / div >
< div class = "form-tips" >
< i class = "fa fa-mobile" > < / i > Device filter list is multi-selectable. No selections means no filtering, i.e. all pushes are emitted.
< / div >
< / script >
2015-04-16 11:58:34 +02:00
< script type = "text/x-red" data-help-name = "pushbullet in" >
2015-01-27 08:08:54 +01:00
< p > Receives Pushbullets from all devices. Messages contain the following data:< / p >
< p > < code > msg.pushtype< / code > : type of message< / p >
< p > < code > msg.topic< / code > : topic information from the push< / p >
< p > < code > msg.payload< / code > : main content of the push< / p >
< p > < code > msg.data< / code > : original object from the pushbullet API containing e.g. sender, receiver and message ids.< / p >
< p > Pushes of type < i > link< / i > and < i > file< / i > will also have < code > msg.message< / code > containing the message associated with the push.< / p >
< p > For further details of see < a href = "https://docs.pushbullet.com/stream/" > Pushbullet Stream API< / a > and < a href = "https://docs.pushbullet.com/v2/pushes/" > Pushbullet Push API< / a > .< / p >
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('pushbullet in',{
2015-09-16 23:38:38 +02:00
category: 'mobile-input',
2015-01-27 08:08:54 +01:00
defaults: {
config: {type: "pushbullet-config", required: true},
name: {value:""}
},
credentials: {
filters: {value: []}
},
color:"#a7c9a0",
inputs:0,
outputs:1,
icon: "bullet.png",
label: function() {
return this.name||"pushbullet";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
2014-04-23 22:06:36 +02:00
},
2015-01-27 08:08:54 +01:00
oneditprepare: function() {
var node = this, ddConfig = $('#node-input-config'), ddDevice = $('#node-input-filters');
function updateDeviceList() {
2015-04-16 11:58:34 +02:00
var config = RED.nodes.node(ddConfig.val()),
2015-01-27 08:08:54 +01:00
url = 'pushbullet/'+ddConfig.val()+'/devices';
if(config & & config.credentials & & config.credentials.apikey) {
url += '?apikey='+config.credentials.apikey;
}
$.getJSON(url, function(data) {
var currentDevices = [], addDevices = [];
if(node.credentials & & node.credentials.filters) {
currentDevices = node.credentials.filters;
addDevices = node.credentials.filters.splice();
}
var idx;
ddDevice.children().remove();
for(var i=0; i< data.length ; i + + ) {
var dev = data[i];
ddDevice.append('< option value = "'+dev.iden+'" > '+dev.nickname+' ('+dev.kind+')< / option > ');
2015-04-16 11:58:34 +02:00
2015-01-27 08:08:54 +01:00
idx = addDevices.indexOf(dev.iden);
if (idx > -1) {
addDevices.splice(idx, 1);
}
}
for(var j=0;j< addDevices.length ; j + + ) {
ddDevice.append('< option value = "'+addDevices[j]+'" > '+addDevices[j]+'< / option > ');
}
ddDevice.val(currentDevices);
2015-04-16 11:58:34 +02:00
});
2015-01-27 08:08:54 +01:00
}
ddConfig.change(function() {
if(ddConfig.val() & & ddConfig.val() !== "_ADD_") {
updateDeviceList();
}
2014-04-23 22:06:36 +02:00
});
2013-10-30 21:38:23 +01:00
}
});
< / script >