File size: 1,132 Bytes
3f894d0
5d14a84
 
 
3f894d0
 
 
 
 
 
5d14a84
 
 
 
 
3f894d0
 
 
 
 
 
 
 
 
 
 
 
5d14a84
 
 
 
3f894d0
5d14a84
3f894d0
5d14a84
 
3f894d0
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
import os
from flask import Flask, request
from notification import send_notification
from config import prayer_times
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

API_KEY = os.getenv("API_KEY")

app = Flask(__name__)

@app.route('/incoming_call', methods=['POST'])
def incoming_call():
    # Validate API Key from request headers
    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)  # Port 7860 for Hugging Face