-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_function.py
51 lines (46 loc) · 1.57 KB
/
lambda_function.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
43
44
45
46
47
48
49
50
51
import json
import settings
from function_routes import message_to_function
from message_handlers.default_handler import help
from platform_adaptors.factory import get_adaptor
def lambda_handler(event, context):
print event
messaging_adaptor = get_adaptor(settings.MESSAGING_PLATFORM)
req_body = messaging_adaptor.to_dict(event["body"])
if messaging_adaptor.should_respond(req_body):
user, command, other_text, channel = messaging_adaptor.parse_request(req_body)
route_request(messaging_adaptor, user, command, other_text, channel)
return create_lambda_proxy_response(False, 200, {}, {})
def route_request(messaging_adaptor, user, command, other_text, channel):
func = message_to_function.get(command.strip().lower(), help)
func(messaging_adaptor, user, channel, other_text)
def create_lambda_proxy_response(is_base_64_encoded, status_code, headers, payload):
return {
"isBase64Encoded": is_base_64_encoded,
"statusCode": status_code,
"headers": headers,
"body": json.dumps(payload)
}
req = {
"body" : json.dumps({
"token": "one-long-verification-token",
"team_id": "T061EG9R6",
"api_app_id": "A0PNCHHK2",
"event": {
"type": "message",
"user": "U061F7AUR",
"text": "Activate",
"ts": "1525215129.000001",
"channel": "D0PNCRP9N",
"event_ts": "1525215129.000001",
"channel_type": "app_home"
},
"type": "event_callback",
"authed_teams": [
"T061EG9R6"
],
"event_id": "Ev0PV52K25",
"event_time": 1525215129
})
}
lambda_handler(req, None)