1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Update Pushbullet Node to allow use of Channels

This commit is contained in:
Dave C-J 2014-11-10 16:42:49 +00:00
parent 7474905b08
commit 6768c1b42b
3 changed files with 22 additions and 12 deletions

View File

@ -19,6 +19,10 @@
<label for="node-input-title"><i class="fa fa-flag"></i> Title</label>
<input type="text" id="node-input-title" placeholder="Node-RED">
</div>
<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>
<div class="form-row">
<label for="node-config-input-deviceid"><i class="fa fa-user"></i> Device ID</label>
<input type="text" id="node-config-input-deviceid">
@ -36,13 +40,13 @@
</script>
<script type="text/x-red" data-help-name="pushbullet">
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has the PushBullet app installed.</p>
<p>Uses PushBullet to push the <b>msg.payload</b> to a device that has the PushBullet app installed.</p>
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
<p>You need to configure both your <i>API key</i> and the target <i>device ID</i>.
The device ID may be passed in as <b>msg.deviceid</b>. You can set these per node in the edit dialog.
The old method of storing your credentials in the pushkey.js file in the directory <b>above</b> /node-red is being deprecated.</p>
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' }</pre></p>
<p>The deviceid can be found by hovering over your required device on the <a href="https://www.pushbullet.com/">PushBullet website</a>.</p>
The device ID may be passed in as <b>msg.deviceid</b>.</p>
<p>You can also push to any channels that you own either configured or via <b>msg.channel</b>.</p>
The old method of storing your credentials in the pushkey.js file in the directory <b>above</b> /node-red is deprecated.</p>
<p>The deviceid can be found by clicking on your required device on the <a href="https://www.pushbullet.com/">PushBullet website</a>, once you have logged in.</p>
</script>
<script type="text/javascript">
@ -50,6 +54,7 @@
category: 'output',
defaults: {
title: {value:""},
chan: {value:"" },
name: {value:""}
},
color:"#a7c9a0",

View File

@ -33,6 +33,7 @@ module.exports = function(RED) {
function PushbulletNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
this.chan = n.chan;
var credentials = RED.nodes.getCredentials(n.id);
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else {
@ -49,17 +50,21 @@ module.exports = function(RED) {
this.on("input",function(msg) {
var titl = node.title || msg.topic || "Node-RED";
var dev = msg.deviceid||node.deviceid;
var dev = node.deviceid || msg.deviceid;
var channel = node.chan || msg.chan;
if (channel != undefined) {
dev = { channel_tag : channel };
} else {
if (!isNaN(dev)) { dev = Number(dev); }
}
if (typeof(msg.payload) === 'object') {
msg.payload = JSON.stringify(msg.payload);
}
else { msg.payload = msg.payload.toString(); }
if (node.pushkey && dev) {
try {
if (!isNaN(dev)) { dev = Number(dev); }
node.pusher.note(dev, titl, msg.payload, function(err, response) {
if (err) { node.error("Pushbullet error: "+err); }
//console.log(response);
if (err) { node.error("Pushbullet error"); }
});
}
catch (err) {

View File

@ -1,9 +1,9 @@
{
"name" : "node-red-node-pushbullet",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node to send alerts via Pushbullet",
"dependencies" : {
"pushbullet" : "1.*.*"
"pushbullet" : "1.4.*"
},
"repository" : {
"type":"git",