1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

add telegram to callmebot (#5480)

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
Simon Smith 2023-10-28 19:27:11 +01:00 committed by GitHub
parent c6ebcc6e8e
commit b52da08c84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View file

@ -328,6 +328,9 @@ module.exports.CreateServer = function (parent) {
} else if ((toData[0] == 'facebook') && (toData.length == 2)) {
var url = 'https://api.callmebot.com/facebook/send.php?apikey=' + encodeURIComponent(toData[1]) + '&text=' + encodeURIComponent(msg);
require('https').get(url, function (r) { if (func != null) { func(r.statusCode == 200); } });
} else if ((toData[0] == 'telegram') && (toData.length == 2)) {
var url = 'https://api.callmebot.com/text.php?user=' + encodeURIComponent(toData[1]) + '&text=' + encodeURIComponent(msg);
require('https').get(url, function (r) { if (func != null) { func(r.statusCode == 200); } });
}
} else if ((to.startsWith('pushover:')) && (obj.pushoverClient != null)) { // Pushover
const Pushover = require('node-pushover');
@ -357,15 +360,17 @@ module.exports.CreateServer = function (parent) {
obj.callmebotUrlToHandle = function (xurl) {
var url = null;
try { url = require('url').parse(xurl); } catch (ex) { return; }
if ((url == null) || (url.host != 'api.callmebot.com') || (url.protocol != 'https:') || (url.query == null)) return;
if ((url == null) || (url.host != 'api.callmebot.com') || (url.query == null)) return;
var urlArgs = {}, urlArgs2 = url.query.split('&');
for (var i in urlArgs2) { var j = urlArgs2[i].indexOf('='); if (j > 0) { urlArgs[urlArgs2[i].substring(0, j)] = urlArgs2[i].substring(j + 1); } }
if ((urlArgs['phone'] != null) && (urlArgs['phone'].indexOf('|') >= 0)) return;
if ((urlArgs['apikey'] != null) && (urlArgs['apikey'].indexOf('|') >= 0)) return;
// Signal Messenger, Whatapp and Facebook
if ((urlArgs['user'] != null) && (urlArgs['user'].indexOf('|') >= 0)) return;
// Signal Messenger, Whatapp, Facebook and Telegram
if (url.path.startsWith('/signal') && (urlArgs['phone'] != null) && (urlArgs['apikey'] != null)) { return 'callmebot:signal|' + urlArgs['phone'] + '|' + urlArgs['apikey']; }
if (url.path.startsWith('/whatsapp') && (urlArgs['phone'] != null) && (urlArgs['apikey'] != null)) { return 'callmebot:whatsapp|' + urlArgs['phone'] + '|' + urlArgs['apikey']; }
if (url.path.startsWith('/facebook') && (urlArgs['apikey'] != null)) { return 'callmebot:facebook|' + urlArgs['apikey']; }
if (url.path.startsWith('/text') && (urlArgs['user'] != null)) { return 'callmebot:telegram|' + urlArgs['user']; }
return null;
}