Trash Twilio
This commit is contained in:
parent
054d4aaba4
commit
c80ddfacd9
2 changed files with 1 additions and 94 deletions
|
@ -1,5 +1,4 @@
|
||||||
Flask==3.1.0
|
Flask==3.1.0
|
||||||
flask_sqlalchemy==3.1.1
|
flask_sqlalchemy==3.1.1
|
||||||
gunicorn==23.0.0
|
gunicorn==23.0.0
|
||||||
prometheus-flask-exporter==0.23.1
|
prometheus-flask-exporter==0.23.1
|
||||||
twilio==9.4.3
|
|
|
@ -1,5 +1,4 @@
|
||||||
from flask import jsonify, request
|
from flask import jsonify, request
|
||||||
from twilio.twiml.voice_response import VoiceResponse, Gather
|
|
||||||
|
|
||||||
from utils import logger, validate_data_presence, _get_weather, _get_cords, strq
|
from utils import logger, validate_data_presence, _get_weather, _get_cords, strq
|
||||||
|
|
||||||
|
@ -8,97 +7,6 @@ from . import routes as app
|
||||||
from . import by_path_counter
|
from . import by_path_counter
|
||||||
|
|
||||||
|
|
||||||
@app.route("/voice", methods=["GET", "POST"])
|
|
||||||
@by_path_counter
|
|
||||||
def voice():
|
|
||||||
"""Respond to incoming phone calls with a menu of options"""
|
|
||||||
# Start our TwiML response
|
|
||||||
resp = VoiceResponse()
|
|
||||||
|
|
||||||
from_number = request.form["From"]
|
|
||||||
if from_number not in env_AUTHORIZED_CALLERS:
|
|
||||||
resp.say("You are calling from an unauthorized number. Goodbye.")
|
|
||||||
return str(resp)
|
|
||||||
|
|
||||||
resp.say("Welcome to Atmo Assistant.")
|
|
||||||
# Start our <Gather> verb
|
|
||||||
gather = Gather(num_digits=1, action="/gather")
|
|
||||||
gather.say(
|
|
||||||
"Main menu. Enter one for Asheboro. Two for Lynchburg. Three for Cullowhee. Zero for another zipcode."
|
|
||||||
)
|
|
||||||
resp.append(gather)
|
|
||||||
|
|
||||||
# If the user doesn't select an option, redirect them into a loop
|
|
||||||
resp.redirect("/voice")
|
|
||||||
|
|
||||||
return str(resp)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/gather", methods=["GET", "POST"])
|
|
||||||
@by_path_counter
|
|
||||||
def gather():
|
|
||||||
"""Processes results from the <Gather> prompt in /voice"""
|
|
||||||
# Start our TwiML response
|
|
||||||
resp = VoiceResponse()
|
|
||||||
|
|
||||||
# If Twilio's request to our app included already gathered digits,
|
|
||||||
# process them
|
|
||||||
if "Digits" in request.values:
|
|
||||||
# Get which digit the caller chose
|
|
||||||
choice = request.values["Digits"]
|
|
||||||
|
|
||||||
# <Say> a different message depending on the caller's choice
|
|
||||||
if choice == "1":
|
|
||||||
weather = _get_weather(35.6396, -79.8509)
|
|
||||||
resp.say(weather)
|
|
||||||
elif choice == "2":
|
|
||||||
weather = _get_weather(37.3490, -79.1787)
|
|
||||||
resp.say(weather)
|
|
||||||
elif choice == "3":
|
|
||||||
weather = _get_weather(35.3087, -83.1861)
|
|
||||||
resp.say(weather)
|
|
||||||
elif choice == "0":
|
|
||||||
custom = Gather(num_digits=5, action="/custom")
|
|
||||||
custom.say("Enter a zipcode for its weather.")
|
|
||||||
resp.append(custom)
|
|
||||||
else:
|
|
||||||
# If the caller didn't choose 1 or 2, apologize and ask them again
|
|
||||||
resp.say("Sorry, I don't understand that choice.")
|
|
||||||
|
|
||||||
# If the user didn't choose 1 or 2 (or anything), send them back to /voice
|
|
||||||
resp.redirect("/voice")
|
|
||||||
|
|
||||||
return str(resp)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/custom", methods=["GET", "POST"])
|
|
||||||
@by_path_counter
|
|
||||||
def custom():
|
|
||||||
"""Processes results from the <Gather> prompt in /gather"""
|
|
||||||
# Start our TwiML response
|
|
||||||
resp = VoiceResponse()
|
|
||||||
|
|
||||||
# If Twilio's request to our app included already gathered digits,
|
|
||||||
# process them
|
|
||||||
if "Digits" in request.values:
|
|
||||||
# Get which digit the caller chose
|
|
||||||
choice = request.values["Digits"]
|
|
||||||
|
|
||||||
# <Say> a different message depending on the caller's choice
|
|
||||||
if len(choice) == 5:
|
|
||||||
weather = _get_weather(_get_cords(choice))
|
|
||||||
resp.say(weather)
|
|
||||||
return str(resp)
|
|
||||||
else:
|
|
||||||
# If the caller didn't choose 1 or 2, apologize and ask them again
|
|
||||||
resp.say("Sorry, I don't understand that choice.")
|
|
||||||
|
|
||||||
# If the user didn't choose 1 or 2 (or anything), send them back to /voice
|
|
||||||
resp.redirect("/voice")
|
|
||||||
|
|
||||||
return str(resp)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/city", methods=["GET"])
|
@app.route("/city", methods=["GET"])
|
||||||
@by_path_counter
|
@by_path_counter
|
||||||
def city():
|
def city():
|
||||||
|
|
Loading…
Reference in a new issue