Spaces:
Paused
Paused
alan5543 commited on
Commit ·
8174193
1
Parent(s): b2f507e
update
Browse files
app.py
CHANGED
|
@@ -15,7 +15,8 @@ load_dotenv()
|
|
| 15 |
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
| 16 |
TELEGRAM_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
# Set up logging
|
| 21 |
logging.basicConfig(level=logging.DEBUG)
|
|
@@ -83,14 +84,21 @@ async def send_message(data: MessageData):
|
|
| 83 |
)
|
| 84 |
|
| 85 |
logger.debug(f"Sending message to chat_id: {TELEGRAM_CHAT_ID}")
|
|
|
|
| 86 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 87 |
-
bot = Bot(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
try:
|
|
|
|
| 89 |
await bot.send_message(
|
| 90 |
chat_id=TELEGRAM_CHAT_ID,
|
| 91 |
text=telegram_message,
|
| 92 |
parse_mode="Markdown",
|
| 93 |
-
disable_notification=True
|
|
|
|
| 94 |
)
|
| 95 |
logger.info("Message sent successfully")
|
| 96 |
return {"success": True, "message": "Message sent to Telegram"}
|
|
|
|
| 15 |
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
| 16 |
TELEGRAM_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")
|
| 17 |
|
| 18 |
+
# Hardcode Telegram API IP (replace with the IP you get from nslookup)
|
| 19 |
+
TELEGRAM_API_IP = "149.154.167.220" # Example IP, update with actual IP
|
| 20 |
|
| 21 |
# Set up logging
|
| 22 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
| 84 |
)
|
| 85 |
|
| 86 |
logger.debug(f"Sending message to chat_id: {TELEGRAM_CHAT_ID}")
|
| 87 |
+
# Use custom httpx client with hardcoded IP
|
| 88 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 89 |
+
bot = Bot(
|
| 90 |
+
token=TELEGRAM_BOT_TOKEN,
|
| 91 |
+
base_url=f"https://{TELEGRAM_API_IP}",
|
| 92 |
+
client=client
|
| 93 |
+
)
|
| 94 |
try:
|
| 95 |
+
# Set Host header for HTTPS
|
| 96 |
await bot.send_message(
|
| 97 |
chat_id=TELEGRAM_CHAT_ID,
|
| 98 |
text=telegram_message,
|
| 99 |
parse_mode="Markdown",
|
| 100 |
+
disable_notification=True,
|
| 101 |
+
request_kwargs={"headers": {"Host": "api.telegram.org"}}
|
| 102 |
)
|
| 103 |
logger.info("Message sent successfully")
|
| 104 |
return {"success": True, "message": "Message sent to Telegram"}
|