diff --git a/check_room_messages.py b/check_room_messages.py deleted file mode 100644 index cf00c70..0000000 --- a/check_room_messages.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python3 -""" -Check recent messages in Home Assistant room -""" - -import asyncio -import json -import httpx -from datetime import datetime - -# Matrix configuration -MATRIX_HOMESERVER = "https://matrix.klas.chat" -MATRIX_ACCESS_TOKEN = "syt_a2xhcw_ZcjbRgfRFEdMHnutAVOa_1M7eD4" -HOME_ASSISTANT_ROOM_ID = "!xZkScMybPseErYMJDz:matrix.klas.chat" - -async def check_recent_messages(): - """Check recent messages in Home Assistant room""" - print("šŸ“Ø Checking recent messages in Home Assistant room...") - - headers = { - "Authorization": f"Bearer {MATRIX_ACCESS_TOKEN}", - "Content-Type": "application/json" - } - - try: - async with httpx.AsyncClient() as client: - # Get recent messages from the room - response = await client.get( - f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{HOME_ASSISTANT_ROOM_ID}/messages?dir=b&limit=10", - headers=headers, - timeout=30.0 - ) - - if response.status_code == 200: - data = response.json() - events = data.get('chunk', []) - - print(f"āœ… Found {len(events)} recent events") - print("\nšŸ“‹ Recent messages:") - - for i, event in enumerate(events): - if event.get('type') == 'm.room.message': - content = event.get('content', {}) - body = content.get('body', '') - sender = event.get('sender', '') - timestamp = event.get('origin_server_ts', 0) - - # Convert timestamp to readable format - dt = datetime.fromtimestamp(timestamp / 1000) - time_str = dt.strftime('%Y-%m-%d %H:%M:%S') - - print(f" {i+1}. [{time_str}] {sender}: {body}") - - # Check if this is our test message - if "Matrix API test message from LangMem debug script" in body: - print(" āœ… This is our test message!") - - return True - else: - print(f"āŒ Failed to get messages: {response.status_code}") - print(f"Response: {response.text}") - return False - - except Exception as e: - print(f"āŒ Error checking messages: {e}") - return False - -async def main(): - """Main function""" - await check_recent_messages() - -if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file diff --git a/debug_matrix.py b/debug_matrix.py deleted file mode 100644 index 46de1c0..0000000 --- a/debug_matrix.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python3 -""" -Debug Matrix API connection step by step -""" - -import asyncio -import json -import httpx - -# Matrix configuration -MATRIX_HOMESERVER = "https://matrix.klas.chat" -MATRIX_ACCESS_TOKEN = "syt_a2xhcw_ZcjbRgfRFEdMHnutAVOa_1M7eD4" -HOME_ASSISTANT_ROOM_ID = "!xZkScMybPseErYMJDz:matrix.klas.chat" - -async def test_matrix_connection(): - """Test Matrix connection step by step""" - print("šŸ” Testing Matrix API connection...") - - headers = { - "Authorization": f"Bearer {MATRIX_ACCESS_TOKEN}", - "Content-Type": "application/json" - } - - try: - async with httpx.AsyncClient() as client: - # Test 1: Check if we can access the Matrix server - print("\n1. Testing Matrix server access...") - response = await client.get(f"{MATRIX_HOMESERVER}/_matrix/client/versions", timeout=30.0) - print(f" Status: {response.status_code}") - if response.status_code == 200: - print(" āœ… Matrix server is accessible") - else: - print(" āŒ Matrix server access failed") - return False - - # Test 2: Check if our access token is valid - print("\n2. Testing access token...") - response = await client.get(f"{MATRIX_HOMESERVER}/_matrix/client/v3/account/whoami", headers=headers, timeout=30.0) - print(f" Status: {response.status_code}") - if response.status_code == 200: - data = response.json() - print(f" āœ… Access token valid, user: {data.get('user_id')}") - else: - print(" āŒ Access token invalid") - print(f" Response: {response.text}") - return False - - # Test 3: Check if we can access the Home Assistant room - print("\n3. Testing Home Assistant room access...") - response = await client.get(f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{HOME_ASSISTANT_ROOM_ID}/state/m.room.name", headers=headers, timeout=30.0) - print(f" Status: {response.status_code}") - if response.status_code == 200: - data = response.json() - print(f" āœ… Room accessible, name: {data.get('name')}") - else: - print(" āŒ Room access failed") - print(f" Response: {response.text}") - return False - - # Test 4: Send a simple test message - print("\n4. Sending test message...") - message_data = { - "msgtype": "m.text", - "body": "šŸ”§ Matrix API test message from LangMem debug script" - } - - response = await client.post( - f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{HOME_ASSISTANT_ROOM_ID}/send/m.room.message", - headers=headers, - json=message_data, - timeout=30.0 - ) - print(f" Status: {response.status_code}") - if response.status_code == 200: - data = response.json() - print(f" āœ… Message sent successfully!") - print(f" Event ID: {data.get('event_id')}") - return True - else: - print(" āŒ Message sending failed") - print(f" Response: {response.text}") - return False - - except Exception as e: - print(f"āŒ Error during testing: {e}") - return False - -async def main(): - """Main function""" - success = await test_matrix_connection() - - if success: - print("\nšŸŽ‰ All Matrix API tests passed!") - else: - print("\nāŒ Matrix API tests failed!") - -if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file diff --git a/matrix_notifier.py b/matrix_notifier.py deleted file mode 100644 index 7f7749b..0000000 --- a/matrix_notifier.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python3 -""" -Simple Matrix message sender for LangMem notifications -""" - -import asyncio -import json -import sys -import httpx - -# Matrix configuration -MATRIX_HOMESERVER = "https://matrix.klas.chat" -MATRIX_ACCESS_TOKEN = "syt_a2xhcw_ZcjbRgfRFEdMHnutAVOa_1M7eD4" -HOME_ASSISTANT_ROOM_ID = "!xZkScMybPseErYMJDz:matrix.klas.chat" - -async def send_matrix_notification(message: str) -> bool: - """Send notification to Matrix Home Assistant room""" - headers = { - "Authorization": f"Bearer {MATRIX_ACCESS_TOKEN}", - "Content-Type": "application/json" - } - - message_data = { - "msgtype": "m.text", - "body": message - } - - try: - async with httpx.AsyncClient() as client: - response = await client.post( - f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{HOME_ASSISTANT_ROOM_ID}/send/m.room.message", - headers=headers, - json=message_data, - timeout=30.0 - ) - - if response.status_code == 200: - data = response.json() - print(f"āœ… Matrix notification sent: {data.get('event_id')}") - return True - else: - print(f"āŒ Failed to send Matrix notification: {response.status_code}") - print(f"Response: {response.text}") - return False - - except Exception as e: - print(f"āŒ Error sending Matrix notification: {e}") - return False - -async def main(): - """Main function""" - if len(sys.argv) > 1: - message = " ".join(sys.argv[1:]) - else: - message = "šŸ“‹ Matrix notification test - please confirm you received this message" - - print(f"šŸ“¤ Sending: {message}") - success = await send_matrix_notification(message) - - if success: - print("šŸŽ‰ Matrix notification sent successfully!") - print("šŸ’¬ Please check your Home Assistant room in Matrix") - else: - print("āŒ Failed to send Matrix notification") - -if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file diff --git a/send_matrix_message.py b/send_matrix_message.py deleted file mode 100755 index fa79034..0000000 --- a/send_matrix_message.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python3 -""" -Send message to Matrix room via direct API call -""" - -import asyncio -import json -import sys -from typing import Optional - -import httpx - -# Matrix configuration -MATRIX_HOMESERVER = "https://matrix.klas.chat" -MATRIX_ACCESS_TOKEN = "syt_a2xhcw_ZcjbRgfRFEdMHnutAVOa_1M7eD4" -HOME_ASSISTANT_ROOM_ID = "!OQkQcCnlrGwGKJjXnt:matrix.klas.chat" # Need to find this - -async def send_matrix_message(room_id: str, message: str, access_token: str = MATRIX_ACCESS_TOKEN) -> bool: - """Send a message to a Matrix room""" - try: - url = f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{room_id}/send/m.room.message" - - headers = { - "Authorization": f"Bearer {access_token}", - "Content-Type": "application/json" - } - - data = { - "msgtype": "m.text", - "body": message - } - - async with httpx.AsyncClient() as client: - response = await client.post(url, headers=headers, json=data, timeout=30.0) - - if response.status_code == 200: - print(f"āœ… Message sent successfully to room {room_id}") - return True - else: - print(f"āŒ Failed to send message: {response.status_code}") - print(f"Response: {response.text}") - return False - - except Exception as e: - print(f"āŒ Error sending message: {e}") - return False - -async def find_home_assistant_room(): - """Find the Home Assistant room ID""" - try: - url = f"{MATRIX_HOMESERVER}/_matrix/client/v3/joined_rooms" - - headers = { - "Authorization": f"Bearer {MATRIX_ACCESS_TOKEN}" - } - - async with httpx.AsyncClient() as client: - response = await client.get(url, headers=headers, timeout=30.0) - - if response.status_code == 200: - data = response.json() - print("šŸ” Searching for Home Assistant room...") - - for room_id in data.get("joined_rooms", []): - # Get room name - room_url = f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{room_id}/state/m.room.name" - room_response = await client.get(room_url, headers=headers, timeout=30.0) - - if room_response.status_code == 200: - room_data = room_response.json() - room_name = room_data.get("name", "") - print(f" Found room: {room_name} ({room_id})") - - if "Home Assistant" in room_name: - print(f"āœ… Found Home Assistant room: {room_id}") - return room_id - - print("āŒ Home Assistant room not found") - return None - else: - print(f"āŒ Failed to get rooms: {response.status_code}") - return None - - except Exception as e: - print(f"āŒ Error finding room: {e}") - return None - -async def main(): - """Main function""" - message = "šŸ¤– Test message from LangMem MCP Server implementation!" - - if len(sys.argv) > 1: - message = " ".join(sys.argv[1:]) - - print(f"šŸ“¤ Sending message: {message}") - - # Find Home Assistant room - room_id = await find_home_assistant_room() - - if room_id: - success = await send_matrix_message(room_id, message) - if success: - print("šŸŽ‰ Message sent successfully!") - else: - print("āŒ Failed to send message") - else: - print("āŒ Could not find Home Assistant room") - -if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file