Skip to content

Commit

Permalink
Update ToEnWikipediaBot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jnton authored Apr 14, 2024
1 parent a178ad0 commit b064c78
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ToEnWikipediaBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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
Expand Down

0 comments on commit b064c78

Please sign in to comment.