Update bot.py
Browse files
    	
        bot.py
    CHANGED
    
    | @@ -39,9 +39,10 @@ if not WEBHOOK_DOMAIN: | |
| 39 | 
             
            # Webhook configuration
         | 
| 40 | 
             
            # -------------------------
         | 
| 41 | 
             
            # Define a unique webhook path using the bot token
         | 
| 42 | 
            -
            #WEBHOOK_PATH = f"/{TOKEN}"
         | 
| 43 | 
             
            # Construct the full webhook URL (must be HTTPS as required by Telegram)
         | 
| 44 | 
             
            WEBHOOK_URL = f"https://{WEBHOOK_DOMAIN}"  # {WEBHOOK_PATH}"
         | 
|  | |
| 45 |  | 
| 46 |  | 
| 47 | 
             
            # -------------------------
         | 
| @@ -114,7 +115,7 @@ async def main(): | |
| 114 | 
             
                await application.run_webhook(
         | 
| 115 | 
             
                    listen="0.0.0.0",         # Listen on all available interfaces
         | 
| 116 | 
             
                    port=443,                # Port to listen on
         | 
| 117 | 
            -
             | 
| 118 | 
             
                    webhook_url=WEBHOOK_URL   # The full webhook URL that Telegram will use to send updates
         | 
| 119 | 
             
                )
         | 
| 120 |  | 
| @@ -125,4 +126,9 @@ async def main(): | |
| 125 | 
             
            if __name__ == "__main__":
         | 
| 126 | 
             
                # Apply nest_asyncio to support nested event loops if required.
         | 
| 127 | 
             
                nest_asyncio.apply()
         | 
| 128 | 
            -
                asyncio.run(main())
         | 
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 39 | 
             
            # Webhook configuration
         | 
| 40 | 
             
            # -------------------------
         | 
| 41 | 
             
            # Define a unique webhook path using the bot token
         | 
| 42 | 
            +
            # WEBHOOK_PATH = f"/{TOKEN}"
         | 
| 43 | 
             
            # Construct the full webhook URL (must be HTTPS as required by Telegram)
         | 
| 44 | 
             
            WEBHOOK_URL = f"https://{WEBHOOK_DOMAIN}"  # {WEBHOOK_PATH}"
         | 
| 45 | 
            +
            TELEGRAM_WEBHOOK = f"https://api.telegram.org/bot{TOKEN}/setwebhook"
         | 
| 46 |  | 
| 47 |  | 
| 48 | 
             
            # -------------------------
         | 
|  | |
| 115 | 
             
                await application.run_webhook(
         | 
| 116 | 
             
                    listen="0.0.0.0",         # Listen on all available interfaces
         | 
| 117 | 
             
                    port=443,                # Port to listen on
         | 
| 118 | 
            +
                    url_path=TELEGRAM_WEBHOOK,    # The webhook path; here, we use the bot token
         | 
| 119 | 
             
                    webhook_url=WEBHOOK_URL   # The full webhook URL that Telegram will use to send updates
         | 
| 120 | 
             
                )
         | 
| 121 |  | 
|  | |
| 126 | 
             
            if __name__ == "__main__":
         | 
| 127 | 
             
                # Apply nest_asyncio to support nested event loops if required.
         | 
| 128 | 
             
                nest_asyncio.apply()
         | 
| 129 | 
            +
            #    asyncio.run(main())
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                # Instead of asyncio.run(), which may try to close an already running loop,
         | 
| 132 | 
            +
                # get the current loop and run main() until complete.
         | 
| 133 | 
            +
                loop = asyncio.get_event_loop()
         | 
| 134 | 
            +
                loop.run_until_complete(main())
         |