support HTML-mode in Pushover node #467 (#468)

* support HTML-mode in Pushover node #467

* drop option to set whether Pushover uses HTML mode based on incoming node msg
This commit is contained in:
cowchimp 2018-08-13 13:17:51 +03:00 committed by Dave Conway-Jones
parent b94e3eb5fd
commit 771a49a8b0
2 changed files with 11 additions and 1 deletions

View File

@ -48,6 +48,11 @@
<label for="node-input-url_title"><i class="fa fa-anchor"></i> URL title</label>
<input type="text" id="node-input-url_title" placeholder="optional url title">
</div>
<div class="form-row">
<label for="node-input-html"><i class="fa fa-code"></i> HTML</label>
<input type="checkbox" id="node-input-html" style="display:inline-block; width:15px; vertical-align:baseline;" />
<span>Message is <a href="https://pushover.net/api#html" target="_blank">HTML formatted</a></span>
</div>
<div class="form-row">
<label for="node-input-deviceid"><i class="fa fa-user"></i> User key</label>
<input type="text" id="node-input-deviceid">
@ -86,6 +91,7 @@
sound: {value:""},
url: {value:""},
url_title: {value:""},
html: {value:false}
},
credentials: {
deviceid: {type:"text"},

View File

@ -10,6 +10,7 @@ module.exports = function(RED) {
this.device = n.device;
this.priority = n.priority;
this.sound = n.sound;
this.html = n.html;
if (this.sound === '') { this.sound = null; }
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
@ -35,6 +36,7 @@ module.exports = function(RED) {
var sound = this.sound || msg.sound || null;
var url = this.url || msg.url || null;
var url_title = this.url_title || msg.url_title || null;
var html = this.html || false;
if (isNaN(pri)) {pri=0;}
if (pri > 2) {pri = 2;}
if (pri < -2) {pri = -2;}
@ -48,12 +50,14 @@ module.exports = function(RED) {
title: titl,
priority: pri,
retry: 30,
expire: 600
expire: 600,
html: html
};
if (dev) { pushmsg.device = dev; }
if (typeof(sound) === 'string') { pushmsg.sound = sound; }
if (typeof(url) === 'string') { pushmsg.url = url; }
if (typeof(url_title) === 'string') { pushmsg.url_title = url_title; }
if (html) { pushmsg.html = 1; }
//node.log("Sending "+JSON.stringify(pushmsg));
pusher.send( pushmsg, function(err, response) {
if (err) { node.error("Pushover Error: "+err); }