codeBOKER commited on
Commit
8619a68
·
1 Parent(s): 231072a

Fix: ensure UTF-8 encoding for Arabic text in direct IP routing

Browse files
Files changed (1) hide show
  1. telegram_handlers.py +10 -7
telegram_handlers.py CHANGED
@@ -59,19 +59,22 @@ async def telegram_webhook(data: WebhookData):
59
  response = await client.post(TELEGRAM_URL, json=payload)
60
  except Exception as dns_err:
61
  print(f"--- DNS Failed. Forcing Direct IP Routing to 149.154.167.220 ---")
62
-
63
  forced_ip_url = f"https://{TELEGRAM_IP}/bot{TELEGRAM_TOKEN}/sendMessage"
64
-
65
- # Explicitly define headers and serialize the JSON manually
 
 
66
  headers = {
67
  "Host": "api.telegram.org",
68
- "Content-Type": "application/json"
 
69
  }
70
-
71
- # Use 'data' instead of 'json' to ensure absolute control over the body
72
  response = await client.post(
73
  forced_ip_url,
74
- data=json.dumps(payload),
75
  headers=headers
76
  )
77
 
 
59
  response = await client.post(TELEGRAM_URL, json=payload)
60
  except Exception as dns_err:
61
  print(f"--- DNS Failed. Forcing Direct IP Routing to 149.154.167.220 ---")
62
+
63
  forced_ip_url = f"https://{TELEGRAM_IP}/bot{TELEGRAM_TOKEN}/sendMessage"
64
+
65
+ # 1. Manually dump to JSON string to ensure UTF-8 for Arabic
66
+ json_body = json.dumps(payload, ensure_ascii=False).encode('utf-8')
67
+
68
  headers = {
69
  "Host": "api.telegram.org",
70
+ "Content-Type": "application/json",
71
+ "Content-Length": str(len(json_body)) # Explicitly tell Telegram the size
72
  }
73
+
74
+ # 2. Use 'content=' or 'data=' instead of 'json='
75
  response = await client.post(
76
  forced_ip_url,
77
+ content=json_body,
78
  headers=headers
79
  )
80