| | import os |
| | from flask import Flask, request |
| | from notification import send_notification |
| | from config import prayer_times |
| | from dotenv import load_dotenv |
| |
|
| | |
| | load_dotenv() |
| |
|
| | API_KEY = os.getenv("API_KEY") |
| |
|
| | app = Flask(__name__) |
| |
|
| | @app.route('/incoming_call', methods=['POST']) |
| | def incoming_call(): |
| | |
| | request_api_key = request.headers.get("Authorization") |
| | if request_api_key != f"Bearer {API_KEY}": |
| | return {"error": "Unauthorized"}, 403 |
| |
|
| | data = request.get_json() |
| | |
| | if not data or 'caller_id' not in data or 'current_time' not in data: |
| | return {"error": "Invalid request data"}, 400 |
| |
|
| | caller_id = data['caller_id'] |
| | current_time = data['current_time'] |
| |
|
| | if current_time in prayer_times: |
| | message = "I am currently in prayer. Please call later." |
| | send_notification(caller_id, message) |
| | return {"status": "Notification sent"}, 200 |
| |
|
| | return {"status": "No notification needed"}, 200 |
| |
|
| | if __name__ == '__main__': |
| | app.run(host="0.0.0.0", port=7860, debug=False) |
| |
|