Spaces:
Running
Running
Download backend/register_global_webhook.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/register_global_webhook.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/register_global_webhook.py
-
curl -L -o register_global_webhook.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/register_global_webhook.py
1.32 kB
| import asyncio | |
| import httpx | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() # Load from .env | |
| # Token provided by user | |
| TOKEN = "7734361434:AAGGKvlHN6BaND61F1Lr-0TQiBPsRWdmrRo" | |
| APP_URL = "https://microfunnel-production.up.railway.app" | |
| async def register_webhook(): | |
| token = TOKEN | |
| if not token: | |
| print("โ Token not found in settings!") | |
| return | |
| # User's Railway domain from webhook.py logic usually | |
| # But here we hardcode the known production domain or ask user? | |
| # Based on verify_webhook_status call in logs: https://microfunnel-production.up.railway.app | |
| # Let's use that. | |
| webhook_url = f"{APP_URL}/api/v1/webhook/telegram/global" | |
| print(f"๐ Registering webhook for token {token[:5]}... to {webhook_url}") | |
| async with httpx.AsyncClient() as client: | |
| # 1. Delete | |
| # await client.get(f"https://api.telegram.org/bot{token}/deleteWebhook") | |
| # 2. Set | |
| res = await client.post( | |
| f"https://api.telegram.org/bot{token}/setWebhook", | |
| json={ | |
| "url": webhook_url, | |
| "allowed_updates": ["message", "my_chat_member", "channel_post"] | |
| } | |
| ) | |
| print(f"๐ก Response: {res.json()}") | |
| if __name__ == "__main__": | |
| asyncio.run(register_webhook()) | |