Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,8 +50,20 @@ def handle_update():
|
|
| 50 |
|
| 51 |
return jsonify({'status': 'ok'}), 200
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
async def set_telegram_webhook():
|
| 54 |
"""Sets the webhook for the Telegram bot with proxy configuration."""
|
|
|
|
|
|
|
| 55 |
webhook_url = f"https://measmonysuon-flyingbird.hf.space/webhooks/{WEBHOOK_SECRET}"
|
| 56 |
retry_attempts = 5
|
| 57 |
retry_delay = 1 # seconds
|
|
|
|
| 50 |
|
| 51 |
return jsonify({'status': 'ok'}), 200
|
| 52 |
|
| 53 |
+
async def delete_webhook():
|
| 54 |
+
"""Deletes any existing webhook."""
|
| 55 |
+
async with httpx.AsyncClient(proxies=PROXY_URL) as client:
|
| 56 |
+
response = await client.post(f"https://api.telegram.org/bot{BOT_TOKEN}/deleteWebhook")
|
| 57 |
+
result = response.json()
|
| 58 |
+
if result.get('ok'):
|
| 59 |
+
logger.info("Existing webhook deleted.")
|
| 60 |
+
else:
|
| 61 |
+
logger.error(f"Failed to delete existing webhook: {result}")
|
| 62 |
+
|
| 63 |
async def set_telegram_webhook():
|
| 64 |
"""Sets the webhook for the Telegram bot with proxy configuration."""
|
| 65 |
+
await delete_webhook() # Delete existing webhook before setting a new one
|
| 66 |
+
|
| 67 |
webhook_url = f"https://measmonysuon-flyingbird.hf.space/webhooks/{WEBHOOK_SECRET}"
|
| 68 |
retry_attempts = 5
|
| 69 |
retry_delay = 1 # seconds
|