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
Files changed (1) hide show
  1. 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').promises;
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: Using direct IP connection to Telegram API.');
26
-
27
- // Use a direct IP for api.telegram.org to bypass DNS
28
- // 149.154.167.220 is a known Telegram API IP.
29
- botOptions.telegram = {
30
- apiRoot: 'https://149.154.167.220',
31
- agent: new https.Agent({
32
- keepAlive: true,
33
- family: 4
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