-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
99 lines (75 loc) · 3.14 KB
/
app.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from flask import Flask, request
import os
from send_sms import SMSClient
from initiate_call import VOICE
from med_ai import med_ai
app = Flask(__name__)
@app.route('/ussd', methods=['POST', 'GET'])
def ussd_callback():
session_id = request.values.get("sessionId", None)
service_code = request.values.get("serviceCode", None)
phone_number = request.values.get("phoneNumber", None)
text = request.values.get("text", "default")
response = ""
# ussd logic
if text == "":
# main menu
response = "CON Welcome to TelAfya. Choose your service:\n"
response += "1. Connect to telemedicine service\n"
response += "2. Reach out to a hospital\n"
response += "3. Reach out for an ambulance\n"
response += "4. Exit"
# sub menu
elif text == "1":
response = "CON Please describe your symptoms:\n"
elif text == "2":
response = "CON Please select the hospital you would like to reach out to:\n"
response += "1. Kenyatta Hospital\n"
response += "2. Mama lucy Hospital\n"
response += "3. Mbagathi Hospital\n"
response += "4. Mater Hospital"
elif text == "3":
call_to = "+254742079321"
make_call = VOICE(call_to)
make_call.call()
response = "END Call has been initiated. Please be patient as we connect you to an ambulance service."
elif text == "4":
response = "END Thank you for using our services. Welcome back again."
# sub sub menu
elif text == "2*1":
call_to = "+254742079321"
make_call = VOICE(call_to)
make_call.call()
response = "END Call has been initiated. Please be patient as we connect you to Kenyatta Hospital."
elif text == "2*2":
call_to = "+254742079321"
make_call = VOICE(call_to)
make_call.call()
response = "END Call has been initiated. Please be patient as we connect you to Mama Lucy Hospital."
elif text == "2*3":
call_to = "+254742079321"
make_call = VOICE(call_to)
make_call.call()
response = "END Call has been initiated. Please be patient as we connect you to Mbagathi Hospital."
elif text == "2*4":
call_to = "+254742079321"
make_call = VOICE(call_to)
make_call.call()
response = "END Call has been initiated. Please be patient as we connect you to Mater Hospital."
else:
try:
# sending the sms
symptom = med_ai(text)
message =f"Hello, doctor. I've been experiencing {symptom} lately. What could be the possible causes?"
sms_client = SMSClient(phone_number, message)
sms_client.send_sms()
response = "END Message has been sent to your phone number about your enquiry, welcome back again."
except Exception as e:
# show us what went wrong
print(f"We have a problem: {e}")
return response
@app.route('/call', methods=['POST'])
def call_back_client():
return '<Response> <Dial phoneNumbers="" maxDuration="5"/></Response>'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=os.environ.get("PORT"))