-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
48 lines (32 loc) · 1.14 KB
/
chatbot.py
File metadata and controls
48 lines (32 loc) · 1.14 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
41
42
43
44
45
46
47
48
from __future__ import print_function
from httplib2 import Http
from json import dumps, loads
def response (message, status_code):
return {
'statusCode': str(status_code),
'body': dumps(message),
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
def lambda_handler(event, context):
try:
print("received event: " + dumps(event, indent=2))
msg=(loads(event['body'])).get('message')
bot_url = <URL_GOOGLE_CHAT>
bot_message = {
'text' : msg.get('text')
}
message_headers = {'Content-Type': 'application/json; charset=UTF-8'}
http_obj = Http()
bot_response = http_obj.request(
uri= bot_url,
method='POST',
headers=message_headers,
body=dumps(bot_message),
)
print(bot_response)
return response({'message': 'Ok'}, 200)
except Exception as e:
return response({'message': e.message}, 400)