This repository has been archived by the owner on Oct 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
106 lines (92 loc) · 2.5 KB
/
app.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
import os
import json
from flask import Flask, request, jsonify
app = Flask(__name__)
NEXMO_NUMBER = "447520647999"
intro_message = """Thank you for calling Hack The Midlands. For our Emergency line press 0.
For event information press 1. For tickets 2. For sponsorship enquiries press 3. For anything else press 4."""
options = """For our Emergency line press 0.
For event information press 1. For tickets 2. For sponsorship enquiries press 3. For anything else press 4."""
event_url = "http://056f9b36.ngrok.io/ivr/"
@app.route('/')
def start_call():
return jsonify([
{
'action': 'talk',
'text': intro_message,
'voice_name': 'Amy',
'bargeIn': 'true'
},
{
'action': 'input',
'maxDigits': 1,
"eventUrl": [event_url]
}
])
@app.route('/emergency/', methods=['POST'])
def emergency():
ncco = [
{
"action": "talk",
"text": "One moment, We are finding someone to answer your call",
"voice_name": "Amy"
},
{
"action": "connect",
"from": NEXMO_NUMBER,
"endpoint": [{
"type": "phone",
"number": '447751312580'
}]
},
{
"action": "connect",
"from": NEXMO_NUMBER,
"endpoint": [{
"type": "phone",
"number": '44751312580'
}]
}]
@app.route('/sponsorship/')
@app.route('/other/')
@app.route('/ivr/', methods=['POST'])
def ivr():
inbound = json.loads(request.data)
print(inbound['dtmf'])
if inbound['dtmf'] == '0':
emergency()
elif inbound['dtmf'] == '1':
ncco = [
{
'action': 'talk',
'text': 'Event information',
'voice_name': 'Amy'
},
]
return jsonify(ncco)
elif inbound['dtmf'] == '2':
tickets()
elif inbound['dtmf'] == '3':
sponsorship()
elif inbound['dtmf'] == '4':
other()
else:
ncco = [
{
'action': 'talk',
'text': 'Sorry I did not understand that. Please try again',
'voice_name': 'Amy'
},
{
'action': 'talk',
'text': options,
'voice_name': 'Amy',
'bargeIn': 'true'
},
{
'action': 'input',
'maxDigits': 1,
"eventUrl": [event_url]
}
]
return jsonify(ncco)