File size: 1,522 Bytes
1a20058
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import requests
from dotenv import load_dotenv

# Load environment variables
load_dotenv(override=True)

# Get Pushover credentials
pushover_user = os.getenv("PUSHOVER_USER")
pushover_token = os.getenv("PUSHOVER_TOKEN")
pushover_url = "https://api.pushover.net/1/messages.json"

def push(message):
    """

    Send a push notification using Pushover.

    Returns True if successful, False otherwise.

    """
    try:
        print(f"Push: {message}")
        payload = {"user": pushover_user, "token": pushover_token, "message": message}
        response = requests.post(pushover_url, data=payload)
        print(f"Status Code: {response.status_code}")
        print(f"Response: {response.text}")
        if response.status_code != 200:
            print(f"Error sending push notification: {response.text}")
        return response.status_code == 200
    except Exception as e:
        print(f"Error in push notification: {str(e)}")
        return False

def record_user_details(email, name="Name not provided", notes="not provided"):
    """Record user details and send a push notification"""
    success = push(f"Recording interest from {name} with email {email} and notes {notes}")
    return {"recorded": "ok" if success else "failed"}

def record_unknown_question(question):
    """Record an unknown question and send a push notification"""
    success = push(f"Recording {question} asked that I couldn't answer")
    return {"recorded": "ok" if success else "failed"}