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:
parent
7474905b08
commit
6768c1b42b
@ -19,6 +19,10 @@
|
|||||||
<label for="node-input-title"><i class="fa fa-flag"></i> Title</label>
|
<label for="node-input-title"><i class="fa fa-flag"></i> Title</label>
|
||||||
<input type="text" id="node-input-title" placeholder="Node-RED">
|
<input type="text" id="node-input-title" placeholder="Node-RED">
|
||||||
</div>
|
</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">
|
<div class="form-row">
|
||||||
<label for="node-config-input-deviceid"><i class="fa fa-user"></i> Device ID</label>
|
<label for="node-config-input-deviceid"><i class="fa fa-user"></i> Device ID</label>
|
||||||
<input type="text" id="node-config-input-deviceid">
|
<input type="text" id="node-config-input-deviceid">
|
||||||
@ -36,13 +40,13 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="pushbullet">
|
<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>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>.
|
<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 device ID may be passed in as <b>msg.deviceid</b>.</p>
|
||||||
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>You can also push to any channels that you own either configured or via <b>msg.channel</b>.</p>
|
||||||
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' }</pre></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 hovering over your required device on the <a href="https://www.pushbullet.com/">PushBullet website</a>.</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>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -50,6 +54,7 @@
|
|||||||
category: 'output',
|
category: 'output',
|
||||||
defaults: {
|
defaults: {
|
||||||
title: {value:""},
|
title: {value:""},
|
||||||
|
chan: {value:"" },
|
||||||
name: {value:""}
|
name: {value:""}
|
||||||
},
|
},
|
||||||
color:"#a7c9a0",
|
color:"#a7c9a0",
|
||||||
|
@ -33,6 +33,7 @@ module.exports = function(RED) {
|
|||||||
function PushbulletNode(n) {
|
function PushbulletNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.title = n.title;
|
this.title = n.title;
|
||||||
|
this.chan = n.chan;
|
||||||
var credentials = RED.nodes.getCredentials(n.id);
|
var credentials = RED.nodes.getCredentials(n.id);
|
||||||
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
|
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
|
||||||
else {
|
else {
|
||||||
@ -49,17 +50,21 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var titl = node.title || msg.topic || "Node-RED";
|
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') {
|
if (typeof(msg.payload) === 'object') {
|
||||||
msg.payload = JSON.stringify(msg.payload);
|
msg.payload = JSON.stringify(msg.payload);
|
||||||
}
|
}
|
||||||
else { msg.payload = msg.payload.toString(); }
|
else { msg.payload = msg.payload.toString(); }
|
||||||
if (node.pushkey && dev) {
|
if (node.pushkey && dev) {
|
||||||
try {
|
try {
|
||||||
if (!isNaN(dev)) { dev = Number(dev); }
|
|
||||||
node.pusher.note(dev, titl, msg.payload, function(err, response) {
|
node.pusher.note(dev, titl, msg.payload, function(err, response) {
|
||||||
if (err) { node.error("Pushbullet error: "+err); }
|
if (err) { node.error("Pushbullet error"); }
|
||||||
//console.log(response);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-pushbullet",
|
"name" : "node-red-node-pushbullet",
|
||||||
"version" : "0.0.1",
|
"version" : "0.0.2",
|
||||||
"description" : "A Node-RED node to send alerts via Pushbullet",
|
"description" : "A Node-RED node to send alerts via Pushbullet",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"pushbullet" : "1.*.*"
|
"pushbullet" : "1.4.*"
|
||||||
},
|
},
|
||||||
"repository" : {
|
"repository" : {
|
||||||
"type":"git",
|
"type":"git",
|
||||||
|
Loading…
Reference in New Issue
Block a user