Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
Latest commit
40 lines (30 loc) · 1.08 KB
/
Copy pathlambda_function.py
File metadata and controls
40 lines (30 loc) · 1.08 KB
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
importbase64
importlogging
importos
fromurllib.parseimportparse_qs
fromservice.compliment_botimportComplimentBot
fromservice.slack_serviceimportSlackService
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO, force=True)
defrespond(err, res=None):
rsp= {
"statusCode": "400"iferrelse"200",
"headers": {
"Content-Type": "application/json",
},
}
ifres:
rsp.update({"body": err.messageiferrelsejson.dumps(res).encode("utf8")})
returnrsp
deflambda_handler(event, context):
slack_token=os.environ["SLACK_TOKEN"]
params=parse_qs(base64.b64decode(event["body"]))
user=params[b"user_id"][0].decode("utf-8")
response_url=params[b"response_url"][0].decode("utf-8")
ifb"text"inparams:
command_text=params[b"text"][0].decode("utf-8")
else:
command_text=""
slack_service=SlackService(slack_token)
compliment_bot=ComplimentBot(slack_service)
compliment_bot.compliment(user, command_text, response_url)
returnrespond(None)