Skip to content

Commit

Permalink
Added Telegram proxy support (#4697, #4650)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylianst committed Nov 1, 2022
1 parent 0c2c557 commit 1ef5856
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
23 changes: 22 additions & 1 deletion docs/docs/messaging/index.md
Expand Up @@ -71,7 +71,28 @@ MeshCentral HTTPS relay server running on relay1.mesh.meshcentral.com:443.
MeshCentral Telegram client is bot connected.
```

Note the last line, indicating it's connected as a bot.
Note the last line, indicating it's connected as a bot. If you wish to use Telegram with a proxy, here are the possible Telegram settings. You can use the proxy settings for both user or bot login modes.

```
{
"messaging": {
"telegram": {
"apiid": 0,
"apihash": "00000000000000000000000",
"session": "aaaaaaaaaaaaaaaaaaaaaaa",
"useWSS": false, // Important. Most proxies cannot use SSL.
"proxy": {
"ip": "123.123.123.123", // Proxy host (IP or hostname)
"port": 123, // Proxy port
"MTProxy": false, // Whether it's an MTProxy or a normal Socks one
"secret": "00000000000000000000000000000000", // If used MTProxy then you need to provide a secret (or zeros).
"socksType": 5, // If used Socks you can choose 4 or 5.
"timeout": 2 // Timeout (in seconds) for connection,
}
}
}
}
```

## Discord Setup

Expand Down
28 changes: 26 additions & 2 deletions meshmessaging.js
Expand Up @@ -33,6 +33,26 @@
}
}
// For Telegram login with proxy settings, add this in config.json
{
"messaging": {
"telegram": {
"apiid": 0,
"apihash": "00000000000000000000000",
"session": "aaaaaaaaaaaaaaaaaaaaaaa",
"useWSS": false, // Important. Most proxies cannot use SSL.
"proxy": {
"ip": "123.123.123.123", // Proxy host (IP or hostname)
"port": 123, // Proxy port
"MTProxy": false, // Whether it's an MTProxy or a normal Socks one
"secret": "00000000000000000000000000000000", // If used MTProxy then you need to provide a secret (or zeros).
"socksType": 5, // If used Socks you can choose 4 or 5.
"timeout": 2 // Timeout (in seconds) for connection,
}
}
}
}
// For Discord login, add this in config.json
"messaging": {
"discord": {
Expand Down Expand Up @@ -120,18 +140,22 @@ module.exports.CreateServer = function (parent) {
const logger = new Logger({ LogLevel : 'none' });
const input = require('input');
var client;
var options = { connectionRetries: 5, baseLogger: logger };
if (parent.config.messaging.telegram.usewss == false) { options.useWSS = false; }
if (typeof parent.config.messaging.telegram.connectionretries == 'number') { options.connectionRetries = parent.config.messaging.telegram.connectionretries; }
if (typeof parent.config.messaging.telegram.proxy == 'object') { options.proxy = parent.config.messaging.telegram.proxy; }
if (parent.config.messaging.telegram.bottoken == null) {
// User login
var stringSession = new StringSession(parent.config.messaging.telegram.session);
const client = new TelegramClient(stringSession, parent.config.messaging.telegram.apiid, parent.config.messaging.telegram.apihash, { connectionRetries: 5, baseLogger: logger });
const client = new TelegramClient(stringSession, parent.config.messaging.telegram.apiid, parent.config.messaging.telegram.apihash, options);
await client.start({ onError: function (err) { console.log('Telegram error', err); } });
obj.telegramClient = client;
obj.providers += 1; // Enable Telegram messaging
console.log("MeshCentral Telegram client is user connected.");
} else {
// Bot login
var stringSession = new StringSession('');
const client = new TelegramClient(stringSession, parent.config.messaging.telegram.apiid, parent.config.messaging.telegram.apihash, { connectionRetries: 5, baseLogger: logger });
const client = new TelegramClient(stringSession, parent.config.messaging.telegram.apiid, parent.config.messaging.telegram.apihash, options);
await client.start({ botAuthToken: parent.config.messaging.telegram.bottoken, onError: function (err) { console.log('Telegram error', err); } });
obj.telegramClient = client;
obj.providers += 1; // Enable Telegram messaging
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -46,10 +46,12 @@
"express": "^4.17.0",
"express-handlebars": "^5.3.5",
"express-ws": "^4.0.0",
"input": "^1.0.1",
"ipcheck": "^0.1.0",
"minimist": "^1.2.5",
"multiparty": "^4.2.1",
"node-forge": "^1.0.0",
"telegram": "^2.13.6",
"ws": "^5.2.3",
"yauzl": "^2.10.0",
"zulip": "^0.1.0"
Expand Down

0 comments on commit 1ef5856

Please sign in to comment.