app90 commited on
Commit
aea3661
·
verified ·
1 Parent(s): 40089fc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, Response
2
+
3
+ app = Flask(__name__)
4
+
5
+ @app.route("/voice", methods=['POST'])
6
+ def voice():
7
+ # Step 1: First response with menu options
8
+ twiml = """
9
+ <Response>
10
+ <Gather numDigits="1" action="/gather" method="POST">
11
+ <Say>Welcome! Press 1 to hear Hi. Press 2 for Good Morning. Press 3 for Good Night.</Say>
12
+ </Gather>
13
+ <Say>No input received. Goodbye!</Say>
14
+ </Response>
15
+ """
16
+ return Response(twiml, mimetype='text/xml')
17
+
18
+ @app.route("/gather", methods=['POST'])
19
+ def gather():
20
+ digit = request.form.get('Digits')
21
+
22
+ if digit == "1":
23
+ message = "Hi!"
24
+ elif digit == "2":
25
+ message = "Good Morning!"
26
+ elif digit == "3":
27
+ message = "Good Night!"
28
+ else:
29
+ message = "Invalid choice. Please try again."
30
+
31
+ twiml = f"""
32
+ <Response>
33
+ <Say>{message}</Say>
34
+ </Response>
35
+ """
36
+ return Response(twiml, mimetype='text/xml')
37
+
38
+
39
+ if __name__ == "__main__":
40
+ app.run(debug=True)