ProfessorCEO commited on
Commit
ecc71c6
·
verified ·
1 Parent(s): a2ba05c

Upload gateway.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. gateway.py +17 -0
gateway.py CHANGED
@@ -20,9 +20,20 @@ import uuid
20
  import base64
21
  import argparse
22
  import urllib.parse
 
23
  from typing import List, Optional, Dict, Any, Union
24
  from threading import Thread
25
 
 
 
 
 
 
 
 
 
 
 
26
  if hasattr(sys.stdout, "reconfigure"):
27
  sys.stdout.reconfigure(encoding="utf-8")
28
 
@@ -593,10 +604,16 @@ async def telegram_webhook(request: Request):
593
  print(f"❌ Telegram Webhook error: {e}", flush=True)
594
  return {"status": "error", "detail": str(e)}
595
 
 
 
596
  def start_telegram_daemon():
 
 
 
597
  bot_token = os.environ.get("TELEGRAM_BOT_TOKEN", "").strip()
598
  if not bot_token:
599
  return
 
600
 
601
  print("🤖 TELEGRAM BOT ACTIVATED! Setting up Webhook & Listener...", flush=True)
602
  webhook_url = "https://professorceo-kora-ai.hf.space/api/telegram"
 
20
  import base64
21
  import argparse
22
  import urllib.parse
23
+ import socket
24
  from typing import List, Optional, Dict, Any, Union
25
  from threading import Thread
26
 
27
+ # Force IPv4 resolution for outbound requests (prevents IPv6 handshake timeouts on cloud containers)
28
+ _old_getaddrinfo = socket.getaddrinfo
29
+ def _getaddrinfo_ipv4_only(host, port, family=0, type=0, proto=0, flags=0):
30
+ try:
31
+ return _old_getaddrinfo(host, port, socket.AF_INET, type, proto, flags)
32
+ except Exception:
33
+ return _old_getaddrinfo(host, port, family, type, proto, flags)
34
+
35
+ socket.getaddrinfo = _getaddrinfo_ipv4_only
36
+
37
  if hasattr(sys.stdout, "reconfigure"):
38
  sys.stdout.reconfigure(encoding="utf-8")
39
 
 
604
  print(f"❌ Telegram Webhook error: {e}", flush=True)
605
  return {"status": "error", "detail": str(e)}
606
 
607
+ _telegram_started = False
608
+
609
  def start_telegram_daemon():
610
+ global _telegram_started
611
+ if _telegram_started:
612
+ return
613
  bot_token = os.environ.get("TELEGRAM_BOT_TOKEN", "").strip()
614
  if not bot_token:
615
  return
616
+ _telegram_started = True
617
 
618
  print("🤖 TELEGRAM BOT ACTIVATED! Setting up Webhook & Listener...", flush=True)
619
  webhook_url = "https://professorceo-kora-ai.hf.space/api/telegram"