-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (39 loc) · 1.38 KB
/
app.py
File metadata and controls
51 lines (39 loc) · 1.38 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
49
50
51
from config import MY_NR, ACCOUNT_SID, AUTH_TOKEN
from twilio.rest import TwilioRestClient
import twilio.twiml
from flask import Flask, request, redirect, render_template
app = Flask(__name__)
@app.route('/')
def index():
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
recordings = client.recordings.list()
return render_template('index.html', posts=recordings)
@app.route("/new", methods=['GET', 'POST'])
def new_post():
from_number = request.values.get('From', None)
resp = twilio.twiml.Response()
if from_number == MY_NR:
resp.say("Hi!")
with resp.gather(numDigits=1, action="/handle-key", method="POST") as g:
g.say("To record a post, press 1.")
return str(resp)
else:
resp.say("Go away intruder!")
return str(resp)
@app.route("/handle-key", methods=['GET', 'POST'])
def handle_key():
digit_pressed = request.values.get('Digits', None)
if digit_pressed == "1":
resp = twilio.twiml.Response()
resp.say("Record your post after the tone.")
resp.record(maxLength="10", action="/handle-recording")
return str(resp)
else:
return redirect("/new")
@app.route("/handle-recording", methods=['GET', 'POST'])
def handle_recording():
resp = twilio.twiml.Response()
resp.say("Your post is now live! Goodbye")
return str(resp)
if __name__ == "__main__":
app.run()