-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (55 loc) · 2.44 KB
/
main.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
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello from Flask!'
@app.route("/ussd", methods = ['POST'])
def ussd():
# Read the variables sent via POST from our API
session_id = request.values.get("sessionId", None)
serviceCode = request.values.get("serviceCode", None)
phone_number = request.values.get("phoneNumber", None)
text = request.values.get("text", "default")
print("phone number", phone_number)
if text == '':
# This is the first request. Note how we start the response with CON
response = "CON Welcome to the platform, kindly pick your preferred option \n"
response += "1. Nairobi Traffic Services \n"
response += "2. Learn about what we're doing to aid traffic conditions in Nairobi \n"
elif text == '1':
# Business logic for first level response
response = "CON Please Choose your specific Service \n"
response += "1. Traffic Conditions \n"
response += "2. Parking \n"
response += "3. View Weather Conditions \n"
response += "4. Report an Incident e.g Fatal accident on Moi Av.\n"
elif text == '1*1':
# Business logic for third level response
response = "END From our Info, the traffic flow exiting Nairobi is moderate, Expect 15+ min Delays \n"
return response
elif text == '1*2':
# Business logic for third level response
response = "END Acccording to our info all major parking hubs are available as Traffic is flowing away from the city \n"
return response
elif text == '1*3':
# Business logic for third level response
response = "END The NBO Region is projected to have 20mm of rainfall in April , possibility of flood"
return response
elif text == '1*4':
# Business logic for third level response
response = "CON Submit Input e.g Train accident at Kasarani \n"
return response
elif text == '':
response= "END Info Submitted successfully, Necessary Authorities will be notified \n"
elif text == '2':
# Business logic for second level response
response = "END To get detailed Nairobi Traffic Info visit www.GroupZeroTraffic.co.ke or text our WhatsApp bot on +254745665647\n"
else:
# Default fallback response
response = "END Invalid input, please try again"
# Print the response to the console for debugging
print(response)
# Return the response to the API
return response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)