-
Notifications
You must be signed in to change notification settings - Fork 0
/
callcenter.py
113 lines (88 loc) · 2.61 KB
/
callcenter.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# coding: utf-8
import json
import os
import requests
import boto3
from twilio.twiml.voice_response import VoiceResponse, Say
from google.cloud import speech
from google.cloud.speech import types
stage = os.getenv('STAGE')
bucket_name = os.getenv('BUCKET_NAME')
sqs_queue_url = os.getenv('SQS_QUEUE_URL')
slack_webhook_url = os.getenv('SLACK_WEBHOOK_URL')
class Rec():
def __init___(self):
pass
def response_xml(self):
response = VoiceResponse()
response.say(
' ピーっという発信音の後、お問い合わせ内容をお申し付けください。',
voice='alice',
language='ja-JP')
response.record(
timeout=10,
maxLength=180,
playBeep=True,
trim='trim-silence',
recordingStatusCallback='/' + stage + '/callback',
recordingStatusCallbackMethod='POST'
)
return str(response)
class File():
def __init__(self):
pass
def download(self, url):
response = requests.get(url)
return response.content
def upload(self, key, data):
s3 = boto3.client('s3')
return s3.put_object(
Body=data,
Bucket=bucket_name,
Key=key)
# return s3.upload_fileobj(data, bucket_name, key)
def remove(self):
# remove from twilio storage
pass
def move(self, url, key):
content = self.download(url)
self.upload(key, content)
self.remove()
return True
class S3():
def __init__(self):
pass
def get_object(self, key):
s3 = boto3.client('s3')
response = s3.get_object(
Bucket=bucket_name,
Key=key)
return response['Body'].read()
class Speech():
def __init__(self):
pass
def to_text(self, content):
client = speech.SpeechClient()
audio = types.RecognitionAudio(content=content)
config = types.RecognitionConfig(language_code='ja-JP')
response = client.recognize(config, audio)
r = []
for result in response.results:
r.append(result.alternatives[0].transcript)
return '. '.join(r)
class Sqs():
def __init__(self):
pass
def send(self, message):
sqs = boto3.client('sqs')
sqs.send_message(
QueueUrl=sqs_queue_url,
MessageBody=(message))
return True
class Slack():
def __init__(self):
pass
def post(self, message):
payload = {"text": message}
data = json.dumps(payload)
requests.post(slack_webhook_url, data)