Added Zulip messaging integration (#4694)

Ylian Saint-Hilaire committed Nov 1, 2022 at 12:27 UTC 7f183ac2fd24b9ea2b061d077521fa2d823795c6
6 files changed +45 -3
meshcentral-config-schema.json
+8
@@ -1417,6 +1417,14 @@
1417 "userurl": { "type": "string", "description": "A URL given to users to help them setup this service." }
1418 },
1419 "description": "Enabled ntfy.sh integration support."
1420 + },
1421 + "zulip": {
1422 + "type": "object",
1423 + "properties": {
1424 + "email": { "type": "string", "description": "Bot email address to login as." },
1425 + "api_key": { "type": "string", "description": "Bot api key." }
1426 + },
1427 + "description": "Enabled Zulip integration support."
1428 }
1429 }
1430 }
meshcentral.js
+1
@@ -4032,6 +4032,7 @@ function mainStart() {
4032 if (config.messaging.discord != null) { if (nodeVersion >= 17) { modules.push('discord.js@14.6.0'); } else { delete config.messaging.discord; addServerWarning('This NodeJS version does not support Discord.js.', 26); } }
4033 if (config.messaging.xmpp != null) { modules.push('@xmpp/client'); }
4034 if (config.messaging.pushover != null) { modules.push('node-pushover'); }
4035 + if (config.messaging.zulip != null) { modules.push('zulip'); }
4036 }
4037
4038 // Setup web based push notifications
meshmessaging.js
+25 -1
@@ -78,13 +78,21 @@
78 }
79 }
80
81 +// For zulip
82 +{
83 + "messaging": {
84 + email: "your-bot@zulip.com",
85 + api_key: "your_32_character_api_key"
86 + }
87 +}
88 +
89 */
90
91 // Construct a messaging server object
92 module.exports.CreateServer = function (parent) {
93 var obj = {};
94 obj.parent = parent;
87 - obj.providers = 0; // 1 = Telegram, 2 = Signal, 4 = Discord, 8 = XMPP, 16 = CallMeBot, 32 = Pushover
95 + obj.providers = 0; // 1 = Telegram, 2 = Signal, 4 = Discord, 8 = XMPP, 16 = CallMeBot, 32 = Pushover, 64 = ntfy, 128 = Zulip
96 obj.telegramClient = null;
97 obj.discordClient = null;
98 obj.discordUrl = null;
@@ -92,6 +100,7 @@ module.exports.CreateServer = function (parent) {
100 var xmppXml = null;
101 obj.callMeBotClient = null;
102 obj.pushoverClient = null;
103 + obj.zulipClient = null;
104
105 // Telegram client setup
106 if (parent.config.messaging.telegram) {
@@ -228,6 +237,13 @@ module.exports.CreateServer = function (parent) {
237 obj.providers += 64; // Enable ntfy messaging
238 }
239
240 + // Zulip client setup (https://zulip.com/)
241 + if (typeof parent.config.messaging.zulip == 'object') {
242 + var zulip = require('zulip');
243 + obj.zulipClient = new zulip.Client(parent.config.messaging.zulip);
244 + obj.providers += 128; // Enable zulip messaging
245 + }
246 +
247 // Send a direct message to a specific userid
248 async function discordSendMsg(userId, message) {
249 const user = await obj.discordClient.users.fetch(userId).catch(function () { return null; });
@@ -296,6 +312,14 @@ module.exports.CreateServer = function (parent) {
312 const req = require('https').request(new URL(url), { method: 'POST' }, function (res) { if (func != null) { func(true); } });
313 req.on('error', function (err) { if (func != null) { func(false); } });
314 req.end(msg);
315 + } else if ((to.startsWith('zulip:')) && (obj.zulipClient != null)) { // zulip
316 + obj.zulipClient.sendMessage({
317 + type: 'private',
318 + content: msg,
319 + to: [ to.substring(6) ],
320 + subject: domain.title ? domain.title : 'MeshCentral'
321 + });
322 + if (func != null) { func(true); }
323 } else {
324 // No providers found
325 func(false, "No messaging providers found for this message.");
meshuser.js
+2
@@ -6706,6 +6706,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6706 if ((command.service == 16) && ((parent.parent.msgserver.providers & 16) != 0)) { handle = parent.parent.msgserver.callmebotUrlToHandle(command.handle); }
6707 if ((command.service == 32) && ((parent.parent.msgserver.providers & 32) != 0)) { handle = 'pushover:' + command.handle; }
6708 if ((command.service == 64) && ((parent.parent.msgserver.providers & 64) != 0)) { handle = 'ntfy:' + command.handle; }
6709 + if ((command.service == 128) && ((parent.parent.msgserver.providers & 128) != 0)) { handle = 'zulip:' + command.handle; }
6710 if (handle == null) return;
6711
6712 // Send a verification message
@@ -6851,6 +6852,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6852 if ((parent.parent.msgserver.providers & 8) != 0) { r.push("Usage: MSG \"xmpp:[username@server.com]\" \"Message\"."); }
6853 if ((parent.parent.msgserver.providers & 32) != 0) { r.push("Usage: MSG \"pushover:[userkey]\" \"Message\"."); }
6854 if ((parent.parent.msgserver.providers & 64) != 0) { r.push("Usage: MSG \"ntfy:[topic]\" \"Message\"."); }
6855 + if ((parent.parent.msgserver.providers & 128) != 0) { r.push("Usage: MSG \"zulip:[topic]\" \"Message\"."); }
6856 cmdData.result = r.join('\r\n');
6857 } else {
6858 parent.parent.msgserver.sendMessage(cmdData.cmdargs['_'][0], cmdData.cmdargs['_'][1], domain, function (status, msg) {
package.json
+3 -2
@@ -37,6 +37,7 @@
37 "sample-config-advanced.json"
38 ],
39 "dependencies": {
40 + "@yetzt/nedb": "^1.8.0",
41 "archiver": "^5.3.1",
42 "body-parser": "^1.19.0",
43 "cbor": "~5.2.0",
@@ -48,10 +49,10 @@
49 "ipcheck": "^0.1.0",
50 "minimist": "^1.2.5",
51 "multiparty": "^4.2.1",
51 - "@yetzt/nedb": "^1.8.0",
52 "node-forge": "^1.0.0",
53 "ws": "^5.2.3",
54 - "yauzl": "^2.10.0"
54 + "yauzl": "^2.10.0",
55 + "zulip": "^0.1.0"
56 },
57 "engines": {
58 "node": ">=10.0.0"
views/default.handlebars
+6
@@ -11988,6 +11988,7 @@
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 + if ((serverinfo.userMsgProviders & 128) != 0) { y += '<option value=128>' + "Zulip" + '</option>'; }
11992 y += '</select>';
11993 x += '<table><tr><td>' + "Service" + '<td>' + y;
11994 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)">';
@@ -12013,6 +12014,7 @@
12014 else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; }
12015 else if (Q('d2serviceselect').value == 32) { Q('d2handleinput')['placeholder'] = "User key"; }
12016 else if (Q('d2serviceselect').value == 64) { Q('d2handleinput')['placeholder'] = "Topic"; }
12017 + else if (Q('d2serviceselect').value == 128) { Q('d2handleinput')['placeholder'] = "username@sample.com"; }
12018 else { Q('d2handleinput')['placeholder'] = "Username"; }
12019 var ok = (Q('d2handleinput').value.length > 0); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); }
12020 }
@@ -15878,6 +15880,7 @@
15880 if ((serverinfo.userMsgProviders & 16) != 0) { y += '<option value=16>' + "CallMeBot" + '</option>'; }
15881 if ((serverinfo.userMsgProviders & 32) != 0) { y += '<option value=32>' + "Pushover" + '</option>'; }
15882 if ((serverinfo.userMsgProviders & 64) != 0) { y += '<option value=64>' + "ntfy" + '</option>'; }
15883 + if ((serverinfo.userMsgProviders & 128) != 0) { y += '<option value=128>' + "Zulip" + '</option>'; }
15884 y += '</select>';
15885 x += '<table style=margin-top:12px><tr><td>' + "Service" + '<td>' + y;
15886 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)">';
@@ -15901,6 +15904,7 @@
15904 }
15905 if (userinfo.msghandle.startsWith('pushover:') && ((serverinfo.userMsgProviders & 32) != 0)) { Q('d2serviceselect').value = 32; Q('d2handleinput').value = userinfo.msghandle.substring(9); }
15906 if (userinfo.msghandle.startsWith('ntfy:') && ((serverinfo.userMsgProviders & 64) != 0)) { Q('d2serviceselect').value = 64; Q('d2handleinput').value = userinfo.msghandle.substring(5); }
15907 + if (userinfo.msghandle.startsWith('zulip:') && ((serverinfo.userMsgProviders & 128) != 0)) { Q('d2serviceselect').value = 128; Q('d2handleinput').value = userinfo.msghandle.substring(6); }
15908 }
15909 p30editMessagingValidate();
15910 }
@@ -15917,6 +15921,7 @@
15921 else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; }
15922 else if (Q('d2serviceselect').value == 32) { Q('d2handleinput')['placeholder'] = "User key"; }
15923 else if (Q('d2serviceselect').value == 64) { Q('d2handleinput')['placeholder'] = "Topic"; }
15924 + else if (Q('d2serviceselect').value == 128) { Q('d2handleinput')['placeholder'] = "username@sample.com"; }
15925 else { Q('d2handleinput')['placeholder'] = "Username"; }
15926 if (x == 1) { dialogclose(1); }
15927 }
@@ -15931,6 +15936,7 @@
15936 else if (Q('d2serviceselect').value == 16) { handle = 'callmebot:' + Q('d2handleinput').value; }
15937 else if (Q('d2serviceselect').value == 32) { handle = 'pushover:' + Q('d2handleinput').value; }
15938 else if (Q('d2serviceselect').value == 64) { handle = 'ntfy:' + Q('d2handleinput').value; }
15939 + else if (Q('d2serviceselect').value == 128) { handle = 'zulip:' + Q('d2handleinput').value; }
15940 if (handle != null) { meshserver.send({ action: 'edituser', id: currentUser._id, msghandle: handle }); }
15941 }
15942