-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
42 lines (28 loc) · 1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import json
import logging
from telegram import Update
from telegram.ext import Application
from gobot.log_utils import setup_logging
from gobot.telegram.telegram_interface import setup_app
logger = logging.getLogger(__name__)
setup_logging()
# handler for AWS Lambda
def lambda_handler(event, context):
"""Called when AWS Lambda is triggered"""
application = setup_app()
logger.info("Running in lambda...")
return asyncio.get_event_loop().run_until_complete(async_handler(event, application))
async def async_handler(event, application: Application):
try:
await application.initialize()
await application.process_update(Update.de_json(json.loads(event["body"]), application.bot))
return {"statusCode": 200, "body": "Success"}
except Exception as exc:
return {"statusCode": 500, "body": str(exc)}
def main():
application = setup_app()
logger.info("Start polling...")
application.run_polling()
if __name__ == "__main__":
main()