@@ -16,20 +16,21 @@ def main():
1616 # Initialize the database
1717 init_db ()
1818
19- # Get webhook URL from environment, but don't fail if it's not there
20- webhook_url = os .environ .get ("WEBHOOK_URL" )
21- if webhook_url :
22- webhook_url = f'{ webhook_url } /{ os .environ ["TELEGRAM_BOT_TOKEN" ]} '
23-
19+ # Get webhook URL from environment.
20+ webhook_url_from_env = os .environ .get ("WEBHOOK_URL" )
21+
22+ # Prepare the webhook_url parameter. It must be None if the env var is missing or empty.
23+ webhook_url_param = None
24+ if webhook_url_from_env : # This is only true if the string is not None and not empty.
25+ webhook_url_param = f'{ webhook_url_from_env } /{ os .environ ["TELEGRAM_BOT_TOKEN" ]} '
2426
2527 # Start the Bot
26- # On the first deploy, webhook_url will be None, and the bot will just start listening.
27- # On the second deploy (after the workflow updates the env var), it will be set correctly.
28+ # If webhook_url_param is None, run_webhook will only start the webserver without setting a webhook.
2829 application .run_webhook (
2930 listen = "0.0.0.0" ,
3031 port = int (os .environ .get ("PORT" , 8080 )),
31- url_path = os .environ ["TELEGRAM_BOT_TOKEN" ],
32- webhook_url = webhook_url ,
32+ # url_path=os.environ["TELEGRAM_BOT_TOKEN"],
33+ # webhook_url=webhook_url_param ,
3334 )
3435
3536if __name__ == "__main__" :
0 commit comments