shivamkr00902 commited on
Commit
b33569a
·
verified ·
1 Parent(s): 46f09ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -1,13 +1,13 @@
1
  import logging
 
2
  from telegram import Update
3
  from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
4
  from telegram.request import HTTPXRequest
5
 
6
  # --- CONFIGURATION ---
7
- BOT_TOKEN = "YOUR_BOT_TOKEN_HERE" # <--- PASTE YOUR TOKEN HERE
8
 
9
  # Telegram API IP Address (Bypasses DNS blocking)
10
- # Note: If this IP changes in the future, the bot will stop working.
11
  TELEGRAM_IP_URL = "https://149.154.167.220/bot"
12
 
13
  # --- LOGGING SETUP ---
@@ -16,21 +16,30 @@ logging.basicConfig(
16
  level=logging.INFO
17
  )
18
 
 
 
 
 
 
 
 
 
 
 
 
19
  async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
20
  await context.bot.send_message(chat_id=update.effective_chat.id, text="Method 2 (IP Hardcode) is Working!")
21
 
22
  if __name__ == '__main__':
23
- # 1. Create a custom request object
24
- # We MUST set verify=False because we are connecting to an IP address,
25
- # so the SSL certificate for "api.telegram.org" won't match.
26
- request = HTTPXRequest(connection_pool_size=8, verify=False)
27
 
28
  # 2. Build the application
29
  application = (
30
  ApplicationBuilder()
31
  .token(BOT_TOKEN)
32
  .base_url(TELEGRAM_IP_URL) # Point to the IP address
33
- .request(request) # Use our custom unverified request
34
  .build()
35
  )
36
 
@@ -38,7 +47,7 @@ if __name__ == '__main__':
38
  start_handler = CommandHandler('start', start)
39
  application.add_handler(start_handler)
40
 
41
- print(f"Bot started pointing to {TELEGRAM_IP_URL}...")
42
 
43
  # 4. Run
44
  application.run_polling()
 
1
  import logging
2
+ import httpx # Required to build the custom client
3
  from telegram import Update
4
  from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
5
  from telegram.request import HTTPXRequest
6
 
7
  # --- CONFIGURATION ---
8
+ BOT_TOKEN = "7848829657:AAH4xGpRPfrdNavu30XRRd3v1zvtAtWl7Ew" # <--- PASTE YOUR TOKEN HERE
9
 
10
  # Telegram API IP Address (Bypasses DNS blocking)
 
11
  TELEGRAM_IP_URL = "https://149.154.167.220/bot"
12
 
13
  # --- LOGGING SETUP ---
 
16
  level=logging.INFO
17
  )
18
 
19
+ # --- CUSTOM CLASS TO DISABLE SSL ---
20
+ class InsecureRequest(HTTPXRequest):
21
+ """
22
+ A custom request class that disables SSL verification.
23
+ This is necessary because the SSL certificate for 'api.telegram.org'
24
+ will not match the IP address '149.154.167.220'.
25
+ """
26
+ def _build_client(self):
27
+ # We override the client builder to force verify=False
28
+ return httpx.AsyncClient(**self._client_kwargs, verify=False)
29
+
30
  async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
31
  await context.bot.send_message(chat_id=update.effective_chat.id, text="Method 2 (IP Hardcode) is Working!")
32
 
33
  if __name__ == '__main__':
34
+ # 1. Initialize our custom insecure request
35
+ request = InsecureRequest(connection_pool_size=8)
 
 
36
 
37
  # 2. Build the application
38
  application = (
39
  ApplicationBuilder()
40
  .token(BOT_TOKEN)
41
  .base_url(TELEGRAM_IP_URL) # Point to the IP address
42
+ .request(request) # Use our custom insecure request
43
  .build()
44
  )
45
 
 
47
  start_handler = CommandHandler('start', start)
48
  application.add_handler(start_handler)
49
 
50
+ print(f"Bot started pointing to {TELEGRAM_IP_URL} with SSL disabled...")
51
 
52
  # 4. Run
53
  application.run_polling()