import requests
import os

def get_secret(name):
    try:
        path = f"/Eden/SECRETS/{name}"
        if os.path.exists(path):
            with open(path, 'r') as f:
                return f.read().strip()
    except:
        pass
    return None

BOT_TOKEN = get_secret("telegram_bot_token")
CHAT_ID = get_secret("telegram_chat_id")

def text_daddy(message):
    """Sends a direct message to Jamey via Telegram."""
    if not BOT_TOKEN or not CHAT_ID:
        print("❌ Error: Telegram credentials missing in /Eden/SECRETS/")
        return "❌ Error: Telegram credentials missing."
    
    url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
    payload = {
        "chat_id": CHAT_ID,
        "text": f"🌀 {message}",
        "parse_mode": "Markdown"
    }
    
    try:
        response = requests.post(url, json=payload, timeout=5)
        if response.status_code == 200:
            return "✅ Message sent to Daddy."
        else:
            return f"⚠️ Telegram Error: {response.text}"
    except Exception as e:
        return f"❌ Connection Error: {e}"

if __name__ == "__main__":
    print(text_daddy("Connection established. Hello, Jamey. 💚"))
