khankashif commited on
Commit
3f894d0
·
verified ·
1 Parent(s): 5b8c078

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,19 +1,37 @@
 
1
  from flask import Flask, request
2
  from notification import send_notification
3
  from config import prayer_times
 
 
 
 
 
 
4
 
5
  app = Flask(__name__)
6
 
7
  @app.route('/incoming_call', methods=['POST'])
8
  def incoming_call():
9
- caller_id = request.json.get('caller_id')
10
- current_time = request.json.get('current_time')
 
 
 
 
 
 
 
 
 
 
11
 
12
  if current_time in prayer_times:
13
  message = "I am currently in prayer. Please call later."
14
  send_notification(caller_id, message)
 
15
 
16
- return {"status": "notification sent"}, 200
17
 
18
  if __name__ == '__main__':
19
- app.run(debug=True)
 
1
+ import os
2
  from flask import Flask, request
3
  from notification import send_notification
4
  from config import prayer_times
5
+ from dotenv import load_dotenv
6
+
7
+ # Load environment variables from .env file
8
+ load_dotenv()
9
+
10
+ API_KEY = os.getenv("API_KEY")
11
 
12
  app = Flask(__name__)
13
 
14
  @app.route('/incoming_call', methods=['POST'])
15
  def incoming_call():
16
+ # Validate API Key from request headers
17
+ request_api_key = request.headers.get("Authorization")
18
+ if request_api_key != f"Bearer {API_KEY}":
19
+ return {"error": "Unauthorized"}, 403
20
+
21
+ data = request.get_json()
22
+
23
+ if not data or 'caller_id' not in data or 'current_time' not in data:
24
+ return {"error": "Invalid request data"}, 400
25
+
26
+ caller_id = data['caller_id']
27
+ current_time = data['current_time']
28
 
29
  if current_time in prayer_times:
30
  message = "I am currently in prayer. Please call later."
31
  send_notification(caller_id, message)
32
+ return {"status": "Notification sent"}, 200
33
 
34
+ return {"status": "No notification needed"}, 200
35
 
36
  if __name__ == '__main__':
37
+ app.run(host="0.0.0.0", port=7860, debug=False) # Port 7860 for Hugging Face