If you have ever called a company and heard “Press 1 for new customers, press 2 for existing customers…” or something to that extent, then you have encountered an IVR - Interactive Voice Response. In its most basic form, an IVR tree will look something like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<digit = request.form.["Digit"]
if digit == "1":
redirect_to_sales()
if digit == "2":
redirect_to_cs()
if digit == "3":
collect_voicemail()>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<states = {
"start": {
"transitions": {
"incoming_call": "greeting"
}
},
"greeting": {
"action": "play_greeting_message",
"transitions": {
"pressed_1": "call_sales",
"pressed_2": "call_cs",
"pressed_3": "call_complaints"
}
},
// These three states have no transitions - they are terminal states
"call_sales": {
"action": "dial_sales"
},
"call_cs": {
"action": "dial_cs"
},
"call_complaints": {
"action": "dial_complaints"
}
}>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<previous_state = request.form.get("previous_state", "")
transition = request.form.get("transition", ||)
state = None
# The very first state will not have a previous state
if not previous_state:
state = "start"
else:
# If a state does not have transitions it's a terminal state
if not states[previous_state].get("transitions", {}):
return
state = states[previous_state]["transitions"][transition]
action = states[state]["action"]
# Process the action here>
</body>
</html>