-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.py
62 lines (49 loc) · 1.27 KB
/
handler.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
52
53
54
55
56
57
58
59
60
61
62
# coding: utf-8
import json
import urllib
from callcenter import Rec, File, S3, Speech, Sqs, Slack
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
patch_all()
rec = Rec()
file = File()
s3 = S3()
speech = Speech()
sqs = Sqs()
slack = Slack()
def record(event, context):
response = {
"statusCode": 200,
"headers": {
"Content-Type": "application/xml"
},
"body": rec.response_xml()
}
print(response)
return response
def callback(event, context):
query_params = event['body']
params = urllib.parse.parse_qs(query_params)
recordingUrl = params['RecordingUrl'][0]
filename = recordingUrl.split('/')[-1] + '.wav'
file.move(recordingUrl, filename)
response = {
"statusCode": 200,
"body": json.dumps({'result': True})
}
return response
def speech_to_text(event, context):
key = event['Records'][0]['s3']['object']['key']
content = s3.get_object(key)
text = speech.to_text(content)
sqs.send(text)
print(text)
return True
def notify_slack(event, context):
message = event['Records'][0]['body']
print(message)
slack.post(message)
return True
if __name__ == "__main__":
event = {}
print(record(event, {}))