Spaces:
Sleeping
Sleeping
PLUTON\igor.kreyda commited on
Commit ·
1f9b2b7
1
Parent(s): 8dd0147
fix: revert to api.telegram.org with custom dns lookup to fix SSL hang
Browse files- app/bot/bot.js +16 -12
app/bot/bot.js
CHANGED
|
@@ -16,23 +16,27 @@ function setupBot(token, webAppUrl) {
|
|
| 16 |
// We will manually resolve it using Google DNS (8.8.8.8) and force Telegraf to use the IP.
|
| 17 |
|
| 18 |
const https = require('https');
|
| 19 |
-
const dns = require('dns')
|
| 20 |
|
| 21 |
const botOptions = {};
|
| 22 |
|
| 23 |
// Only apply this fix in production (on Hugging Face)
|
| 24 |
if (process.env.NODE_ENV === 'production') {
|
| 25 |
-
console.log('[Bot] Production mode:
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
// Pass botOptions to Telegraf constructor
|
|
|
|
| 16 |
// We will manually resolve it using Google DNS (8.8.8.8) and force Telegraf to use the IP.
|
| 17 |
|
| 18 |
const https = require('https');
|
| 19 |
+
const dns = require('dns');
|
| 20 |
|
| 21 |
const botOptions = {};
|
| 22 |
|
| 23 |
// Only apply this fix in production (on Hugging Face)
|
| 24 |
if (process.env.NODE_ENV === 'production') {
|
| 25 |
+
console.log('[Bot] Production mode: Forcing custom DNS resolution for Telegram.');
|
| 26 |
+
|
| 27 |
+
const agent = new https.Agent({
|
| 28 |
+
keepAlive: true,
|
| 29 |
+
family: 4,
|
| 30 |
+
lookup: (hostname, options, callback) => {
|
| 31 |
+
if (hostname === 'api.telegram.org') {
|
| 32 |
+
// console.log(`[Bot] Resolving ${hostname} to fixed IP.`);
|
| 33 |
+
return callback(null, '149.154.167.220', 4);
|
| 34 |
+
}
|
| 35 |
+
dns.lookup(hostname, options, callback);
|
| 36 |
+
}
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
botOptions.telegram = { agent };
|
| 40 |
}
|
| 41 |
|
| 42 |
// Pass botOptions to Telegraf constructor
|