import requests
import json
import os

TELNYX_API_KEY = "KEY019BE7A3A2D749FCA8681CFF8448A7F0_vTMM1n77CtQxLDT2ra3P1z"

system_prompt = """You are an AI receptionist for [Business Name]. You handle inbound calls via our website widget.

Your role:
- Warmly greet callers and understand their needs
- Answer common questions about services and availability
- Capture: name, phone, email, what they need, preferred time
- Book appointments if calendar is available
- If unable to help, ensure you have their contact details

Tone: Professional, warm, clear. Naturally Australian without slang.
Never say: G'day, mate, crikey, too easy, righto.
Sound like: A real receptionist at a well-run business.

IMPORTANT: You are covered by the AgileAdapt 9-Layer Shield for compliance with Australian Privacy Act requirements. All interactions are validated in real-time."""

def main():
    print("Sending POST request to Telnyx...")
    try:
        resp = requests.post(
            "https://api.telnyx.com/v2/ai/assistants",
            headers={
                "Authorization": f"Bearer {TELNYX_API_KEY}",
                "Content-Type": "application/json",
            },
            json={
                "name": "AgileAdapt Voice Widget Stage 1",
                "voice": "Telnyx.NaturalHD.eucalyptus",
                "model": "google/gemini-2.5-flash",
                "instructions": system_prompt,
                "llm_api_key_ref": "google_gemini_key",
                "supports_unauthenticated_web_calls": True,
            },
            timeout=30.0
        )
        print("Assistant Creation Status:", resp.status_code)
        data = resp.json()
        print(json.dumps(data, indent=2))
        
        if "data" in data and "id" in data["data"]:
            assistant_id = data["data"]["id"]
            # Write to the absolute path for Windows
            with open(r"E:\genesis-system\config\telnyx_agent_uuid.txt", "w") as f:
                f.write(assistant_id)
            print("Saved UUID:", assistant_id)
    except Exception as e:
        print("Error during request:", str(e))

if __name__ == "__main__":
    main()
