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

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2013-10-30 21:38:23 +01:00
module.exports = function(RED) {
"use strict";
var notifier = require('node-notifier');
var path = require('path');
var fs = require('fs');
var image = path.join(__dirname, "/node-red.png");
2013-10-30 21:38:23 +01:00
function NotifyNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var node = this;
node.on("input",function(msg) {
var title = node.title || msg.topic;
if (typeof msg.payload === 'object') {
msg.payload = JSON.stringify(msg.payload);
}
var icon = image;
if (msg.icon) {
if (fs.existsSync(msg.icon)) { icon = msg.icon; }
else { node.error("Bad Icon file: "+msg.icon,msg); }
}
var icon = msg.icon || image;
if (typeof(title) !== 'undefined') {
notifier.notify({ message:msg.payload, title:title, icon:icon });
}
else {
notifier.notify({ message:msg.payload, icon:imagefile });
}
});
}
2013-10-30 21:38:23 +01:00
RED.nodes.registerType("nnotify",NotifyNode);
}