From b064c78a8aec1875574be41fda2832a399e4d753 Mon Sep 17 00:00:00 2001 From: JnTon <84038748+JnTon@users.noreply.github.com> Date: Sun, 14 Apr 2024 19:06:01 +0200 Subject: [PATCH] Update ToEnWikipediaBot.py --- ToEnWikipediaBot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ToEnWikipediaBot.py b/ToEnWikipediaBot.py index 866ecf2..077029e 100644 --- a/ToEnWikipediaBot.py +++ b/ToEnWikipediaBot.py @@ -214,7 +214,8 @@ def start(update: Update, context: ContextTypes.DEFAULT_TYPE): application.add_handler(inline_query_handler) # Define the Lambda handler -async def lambda_handler(event, context): +async def lambda_handler_async(event, context): + """Asynchronous handler processing updates from Telegram""" token = os.getenv("YOUR_TELEGRAM_BOT_TOKEN") if not token: logger.error("Telegram bot token not found. Please set it in the Lambda environment variables.") @@ -236,6 +237,11 @@ async def lambda_handler(event, context): logger.error("No body found in the event.") return {'statusCode': 400, 'body': json.dumps('No request body found')} +# Synchronous wrapper to handle the async handler +def lambda_handler(event, context): + """Synchronous wrapper for the asynchronous handler""" + return asyncio.run(lambda_handler_async(event, context)) + # Ensure this part is not executed when the script is imported as a module in Lambda #if __name__ == '__main__': # Run the bot normally if this script is executed locally