Added free ntfy.sh notification service integration.

Ylian Saint-Hilaire committed Oct 31, 2022 at 12:17 UTC 8f84c5d2d3e144932d86108e6dcc1c9663ca44e9
3 files changed +40 -6
meshmessaging.js
+18 -1
@@ -71,6 +71,13 @@
71 }
72 }
73
74 +// For ntfy
75 +{
76 + "messaging": {
77 + "ntfy": true
78 + }
79 +}
80 +
81 */
82
83 // Construct a messaging server object
@@ -196,7 +203,7 @@ module.exports.CreateServer = function (parent) {
203 }
204 }
205
199 - // CallMeBot client setup
206 + // CallMeBot client setup (https://www.callmebot.com/)
207 if (parent.config.messaging.callmebot) {
208 obj.callMeBotClient = true;
209 obj.providers += 16; // Enable CallMeBot messaging
@@ -215,6 +222,12 @@ module.exports.CreateServer = function (parent) {
222 }
223 }
224
225 + // ntfy client setup (https://ntfy.sh/)
226 + if (parent.config.messaging.ntfy) {
227 + obj.ntfyClient = true;
228 + obj.providers += 64; // Enable ntfy messaging
229 + }
230 +
231 // Send a direct message to a specific userid
232 async function discordSendMsg(userId, message) {
233 const user = await obj.discordClient.users.fetch(userId).catch(function () { return null; });
@@ -278,6 +291,10 @@ module.exports.CreateServer = function (parent) {
291 const Pushover = require('node-pushover');
292 const push = new Pushover({ token: parent.config.messaging.pushover.token, user: to.substring(9) });
293 push.send(domain.title ? domain.title : 'MeshCentral', msg, function (err, res) { if (func != null) { func(err == null); } });
294 + } else if ((to.startsWith('ntfy:')) && (obj.ntfyClient != null)) { // ntfy
295 + const req = require('https').request(new URL('https://ntfy.sh/' + encodeURIComponent(to.substring(5))), { method: 'POST' }, function (res) { if (func != null) { func(true); } });
296 + req.on('error', function (err) { if (func != null) { func(false); } });
297 + req.end(msg);
298 } else {
299 // No providers found
300 func(false, "No messaging providers found for this message.");
meshuser.js
+7 -5
@@ -6702,6 +6702,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6702 if ((command.service == 8) && ((parent.parent.msgserver.providers & 8) != 0)) { handle = 'xmpp:' + command.handle; }
6703 if ((command.service == 16) && ((parent.parent.msgserver.providers & 16) != 0)) { handle = parent.parent.msgserver.callmebotUrlToHandle(command.handle); }
6704 if ((command.service == 32) && ((parent.parent.msgserver.providers & 32) != 0)) { handle = 'pushover:' + command.handle; }
6705 + if ((command.service == 64) && ((parent.parent.msgserver.providers & 64) != 0)) { handle = 'ntfy:' + command.handle; }
6706 if (handle == null) return;
6707
6708 // Send a verification message
@@ -6841,11 +6842,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6842 } else {
6843 if (cmdData.cmdargs['_'].length != 2) {
6844 var r = [];
6844 - if ((parent.parent.msgserver.providers & 1) != 0) { r.push("Usage: MSG \"telegram:@UserHandle\" \"Message\"."); }
6845 - if ((parent.parent.msgserver.providers & 2) != 0) { r.push("Usage: MSG \"signal:UserHandle\" \"Message\"."); }
6846 - if ((parent.parent.msgserver.providers & 4) != 0) { r.push("Usage: MSG \"discord:Username#0000\" \"Message\"."); }
6847 - if ((parent.parent.msgserver.providers & 8) != 0) { r.push("Usage: MSG \"xmpp:username@server.com\" \"Message\"."); }
6848 - if ((parent.parent.msgserver.providers & 32) != 0) { r.push("Usage: MSG \"pushover:userkey\" \"Message\"."); }
6845 + if ((parent.parent.msgserver.providers & 1) != 0) { r.push("Usage: MSG \"telegram:[@UserHandle]\" \"Message\"."); }
6846 + if ((parent.parent.msgserver.providers & 2) != 0) { r.push("Usage: MSG \"signal:[UserHandle]\" \"Message\"."); }
6847 + if ((parent.parent.msgserver.providers & 4) != 0) { r.push("Usage: MSG \"discord:[Username#0000]\" \"Message\"."); }
6848 + if ((parent.parent.msgserver.providers & 8) != 0) { r.push("Usage: MSG \"xmpp:[username@server.com]\" \"Message\"."); }
6849 + if ((parent.parent.msgserver.providers & 32) != 0) { r.push("Usage: MSG \"pushover:[userkey]\" \"Message\"."); }
6850 + if ((parent.parent.msgserver.providers & 64) != 0) { r.push("Usage: MSG \"ntfy:[topic]\" \"Message\"."); }
6851 cmdData.result = r.join('\r\n');
6852 } else {
6853 parent.parent.msgserver.sendMessage(cmdData.cmdargs['_'][0], cmdData.cmdargs['_'][1], domain, function (status, msg) {
views/default.handlebars
+15
@@ -11987,12 +11987,15 @@
11987 if ((serverinfo.userMsgProviders & 8) != 0) { y += '<option value=8>' + "XMPP" + '</option>'; }
11988 if ((serverinfo.userMsgProviders & 16) != 0) { y += '<option value=16>' + "CallMeBot" + '</option>'; }
11989 if ((serverinfo.userMsgProviders & 32) != 0) { y += '<option value=32>' + "Pushover" + '</option>'; }
11990 + if ((serverinfo.userMsgProviders & 64) != 0) { y += '<option value=64>' + "ntfy" + '</option>'; }
11991 y += '</select>';
11992 x += '<table><tr><td>' + "Service" + '<td>' + y;
11993 x += '<tr><td>' + "Handle" + '<td><input maxlength=1024 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=account_manageMessagingValidate() onkeypress="if (event.key==\'Enter\') account_manageMessagingValidate(1)">';
11994 x += '</table>';
11995 if (serverinfo.discordUrl) { x += '<div id=d2discordurl style=display:none><br /><a href=' + serverinfo.discordUrl + ' target="_discord">' + "Join this Discord server to receive notifications." + '</a></div>'; }
11996 x += '<div id=d2callmebotinfo style=display:none><br /><a href=https://www.callmebot.com/blog/free-api-signal-send-messages/ target="_callmebot">' + "Signal" + '</a>, <a href=https://www.callmebot.com/blog/free-api-whatsapp-messages/ target="_callmebot">' + "Whatsapp" + '</a>, <a href=https://www.callmebot.com/blog/free-api-facebook-messenger/ target="_callmebot">' + "Facebook" + '</a></div>';
11997 + x += '<div id=d2pushoverinfo style=display:none><br /><a href=https://pushover.net/ target="_pushover">' + "Information at Pushover.net" + '</a></div>';
11998 + x += '<div id=d2ntfyinfo style=display:none><br /><a href=https://ntfy.sh/ target="_ntfy">' + "Free service at ntfy.sh" + '</a></div>';
11999 setDialogMode(2, "Messaging Notifications", 3, account_manageMessagingAdd, x, 'verifyMessaging');
12000 Q('d2handleinput').focus();
12001 account_manageMessagingValidate();
@@ -12002,10 +12005,13 @@
12005 function account_manageMessagingValidate(x) {
12006 if (serverinfo.discordUrl) { QV('d2discordurl', Q('d2serviceselect').value == 4); }
12007 QV('d2callmebotinfo', Q('d2serviceselect').value == 16);
12008 + QV('d2pushoverinfo', Q('d2serviceselect').value == 32);
12009 + QV('d2ntfyinfo', Q('d2serviceselect').value == 64);
12010 if (Q('d2serviceselect').value == 4) { Q('d2handleinput')['placeholder'] = "Username:0000"; }
12011 else if (Q('d2serviceselect').value == 8) { Q('d2handleinput')['placeholder'] = "username@server.com"; }
12012 else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; }
12013 else if (Q('d2serviceselect').value == 32) { Q('d2handleinput')['placeholder'] = "User key"; }
12014 + else if (Q('d2serviceselect').value == 64) { Q('d2handleinput')['placeholder'] = "Topic"; }
12015 else { Q('d2handleinput')['placeholder'] = "Username"; }
12016 var ok = (Q('d2handleinput').value.length > 0); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); }
12017 }
@@ -15870,12 +15876,15 @@
15876 if ((serverinfo.userMsgProviders & 8) != 0) { y += '<option value=8>' + "XMPP" + '</option>'; }
15877 if ((serverinfo.userMsgProviders & 16) != 0) { y += '<option value=16>' + "CallMeBot" + '</option>'; }
15878 if ((serverinfo.userMsgProviders & 32) != 0) { y += '<option value=32>' + "Pushover" + '</option>'; }
15879 + if ((serverinfo.userMsgProviders & 64) != 0) { y += '<option value=64>' + "ntfy" + '</option>'; }
15880 y += '</select>';
15881 x += '<table style=margin-top:12px><tr><td>' + "Service" + '<td>' + y;
15882 x += '<tr><td>' + "Handle" + '<td><input maxlength=1024 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=p30editMessagingValidate() onkeypress="if (event.key==\'Enter\') p30editMessagingValidate(1)">';
15883 x += '</table>';
15884 if (serverinfo.discordUrl) { x += '<div id=d2discordurl style=display:none><br /><a href=' + serverinfo.discordUrl + ' target="_discord">' + "Join this Discord server to receive notifications." + '</a></div>' }
15885 x += '<div id=d2callmebotinfo style=display:none><br /><a href=https://www.callmebot.com/blog/free-api-signal-send-messages/ target="_callmebot">' + "Signal" + '</a>, <a href=https://www.callmebot.com/blog/free-api-whatsapp-messages/ target="_callmebot">' + "Whatsapp" + '</a>, <a href=https://www.callmebot.com/blog/free-api-facebook-messenger/ target="_callmebot">' + "Facebook" + '</a></div>';
15886 + x += '<div id=d2pushoverinfo style=display:none><br /><a href=https://pushover.net/ target="_pushover">' + "Information at Pushover.net" + '</a></div>';
15887 + x += '<div id=d2ntfyinfo style=display:none><br /><a href=https://ntfy.sh/ target="_ntfy">' + "Free service at ntfy.sh" + '</a></div>';
15888 setDialogMode(2, "Messaging Notifications", 3, p30editMessagingEx, x, 'verifyMessaging');
15889 Q('d2handleinput').focus();
15890 if (userinfo.msghandle) {
@@ -15890,6 +15899,7 @@
15899 if ((toData[0] == 'facebook') && (toData.length == 2)) { Q('d2handleinput').value = 'https://api.callmebot.com/facebook/send.php?apikey=' + decodeURIComponent(toData[1]); }
15900 }
15901 if (userinfo.msghandle.startsWith('pushover:') && ((serverinfo.userMsgProviders & 32) != 0)) { Q('d2serviceselect').value = 32; Q('d2handleinput').value = userinfo.msghandle.substring(9); }
15902 + if (userinfo.msghandle.startsWith('ntfy:') && ((serverinfo.userMsgProviders & 64) != 0)) { Q('d2serviceselect').value = 64; Q('d2handleinput').value = userinfo.msghandle.substring(5); }
15903 }
15904 p30editMessagingValidate();
15905 }
@@ -15898,11 +15908,14 @@
15908 QE('d2handleinput', Q('d2serviceselect').value != 0);
15909 if (serverinfo.discordUrl) { QV('d2discordurl', Q('d2serviceselect').value == 4); }
15910 QV('d2callmebotinfo', Q('d2serviceselect').value == 16);
15911 + QV('d2pushoverinfo', Q('d2serviceselect').value == 32);
15912 + QV('d2ntfyinfo', Q('d2serviceselect').value == 64);
15913 if (Q('d2serviceselect').value == 0) { Q('d2handleinput')['placeholder'] = ''; }
15914 else if (Q('d2serviceselect').value == 4) { Q('d2handleinput')['placeholder'] = "Username:0000"; }
15915 else if (Q('d2serviceselect').value == 8) { Q('d2handleinput')['placeholder'] = "username@server.com"; }
15916 else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; }
15917 else if (Q('d2serviceselect').value == 32) { Q('d2handleinput')['placeholder'] = "User key"; }
15918 + else if (Q('d2serviceselect').value == 64) { Q('d2handleinput')['placeholder'] = "Topic"; }
15919 else { Q('d2handleinput')['placeholder'] = "Username"; }
15920 if (x == 1) { dialogclose(1); }
15921 }
@@ -15915,6 +15928,8 @@
15928 else if (Q('d2serviceselect').value == 4) { handle = 'discord:' + Q('d2handleinput').value; }
15929 else if (Q('d2serviceselect').value == 8) { handle = 'xmpp:' + Q('d2handleinput').value; }
15930 else if (Q('d2serviceselect').value == 16) { handle = 'callmebot:' + Q('d2handleinput').value; }
15931 + else if (Q('d2serviceselect').value == 32) { handle = 'pushover:' + Q('d2handleinput').value; }
15932 + else if (Q('d2serviceselect').value == 64) { handle = 'ntfy:' + Q('d2handleinput').value; }
15933 if (handle != null) { meshserver.send({ action: 'edituser', id: currentUser._id, msghandle: handle }); }
15934 }
15935