## 🎯 Major Features Added ### Analytics System - Added comprehensive memory analytics (src/api/analytics.py) - User statistics, memory relationships, clusters, and trends - System health monitoring and metrics - New analytics endpoints in main API ### Performance Optimization - Created performance optimizer (src/api/performance_optimizer.py) - Database indexing and query optimization - Connection pooling and performance monitoring - Optimization script for production deployment ### Alternative Messaging System - Matrix messaging integration (scripts/claude-messaging-system.py) - Home Assistant room communication - Real-time message monitoring and notifications - Alternative to Signal bridge authentication ### Signal Bridge Investigation - Signal bridge authentication scripts and troubleshooting - Comprehensive authentication flow implementation - Bridge status monitoring and verification tools ## 📊 API Enhancements - Added analytics endpoints (/v1/analytics/*) - Enhanced memory storage with fact extraction - Improved error handling and logging - Performance monitoring decorators ## 🛠️ New Scripts & Tools - claude-messaging-system.py - Matrix messaging interface - optimize-performance.py - Performance optimization utility - Signal bridge authentication and verification tools - Message sending and monitoring utilities ## 📚 Documentation Updates - Updated README.md with new features and endpoints - Added IMPLEMENTATION_STATUS.md with complete system overview - Comprehensive API documentation - Alternative messaging system documentation ## 🎉 System Status - All core features implemented and operational - Production-ready with comprehensive testing - Alternative communication system working - Full documentation and implementation guide 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
143 lines
5.2 KiB
Python
143 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Send Matrix messages as Home Assistant user for testing messaging functionality
|
|
"""
|
|
|
|
import asyncio
|
|
import httpx
|
|
import json
|
|
|
|
MATRIX_HOMESERVER = "https://matrix.klas.chat"
|
|
CLAUDE_ACCESS_TOKEN = "syt_Y2xhdWRl_CoBgPoHbtMOxhvOUcMnz_2WRPZJ"
|
|
HOME_ASSISTANT_ROOM_ID = "!xZkScMybPseErYMJDz:matrix.klas.chat"
|
|
SIGNAL_BRIDGE_ROOM_ID = "!oBnnfKDprgMEHNhNjL:matrix.klas.chat"
|
|
|
|
async def send_matrix_message(room_id, message, sender_name="Claude"):
|
|
"""Send a message to a Matrix room"""
|
|
try:
|
|
async with httpx.AsyncClient() as client:
|
|
headers = {
|
|
"Authorization": f"Bearer {CLAUDE_ACCESS_TOKEN}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
# Format message with sender identification
|
|
formatted_message = f"[{sender_name}] {message}"
|
|
|
|
response = await client.post(
|
|
f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{room_id}/send/m.room.message",
|
|
headers=headers,
|
|
json={
|
|
"msgtype": "m.text",
|
|
"body": formatted_message
|
|
}
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
print(f"✅ Message sent to room {room_id}")
|
|
print(f"📨 Message: {formatted_message}")
|
|
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 get_room_messages(room_id, limit=10):
|
|
"""Get recent messages from a Matrix room"""
|
|
try:
|
|
async with httpx.AsyncClient() as client:
|
|
headers = {"Authorization": f"Bearer {CLAUDE_ACCESS_TOKEN}"}
|
|
|
|
response = await client.get(
|
|
f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{room_id}/messages",
|
|
headers=headers,
|
|
params={"limit": limit, "dir": "b"}
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
return data.get("chunk", [])
|
|
else:
|
|
print(f"❌ Failed to get messages: {response.status_code}")
|
|
return []
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error getting messages: {e}")
|
|
return []
|
|
|
|
async def test_home_assistant_messaging():
|
|
"""Test messaging capability through Home Assistant room"""
|
|
print("🏠 Testing Home Assistant messaging...")
|
|
|
|
# Send a test message to Home Assistant room
|
|
test_message = "Hello from Claude! Testing messaging system connectivity."
|
|
success = await send_matrix_message(HOME_ASSISTANT_ROOM_ID, test_message, "Claude-Test")
|
|
|
|
if success:
|
|
print("✅ Successfully sent message to Home Assistant room")
|
|
|
|
# Wait a moment and check for any responses
|
|
await asyncio.sleep(2)
|
|
|
|
messages = await get_room_messages(HOME_ASSISTANT_ROOM_ID, 5)
|
|
print(f"📬 Recent messages in Home Assistant room:")
|
|
for msg in messages[:3]:
|
|
if msg.get("type") == "m.room.message":
|
|
sender = msg.get("sender", "")
|
|
body = msg.get("content", {}).get("body", "")
|
|
print(f" [{sender}]: {body}")
|
|
|
|
return success
|
|
|
|
async def test_bridge_room_messaging():
|
|
"""Test messaging capability through Signal bridge room"""
|
|
print("\n🌉 Testing Signal bridge room messaging...")
|
|
|
|
# Send a test message to Signal bridge room
|
|
test_message = "Test message from Claude - checking Matrix messaging without Signal authentication"
|
|
success = await send_matrix_message(SIGNAL_BRIDGE_ROOM_ID, test_message, "Claude-Matrix")
|
|
|
|
if success:
|
|
print("✅ Successfully sent message to Signal bridge room")
|
|
|
|
# Wait a moment and check for any responses
|
|
await asyncio.sleep(2)
|
|
|
|
messages = await get_room_messages(SIGNAL_BRIDGE_ROOM_ID, 5)
|
|
print(f"📬 Recent messages in Signal bridge room:")
|
|
for msg in messages[:3]:
|
|
if msg.get("type") == "m.room.message":
|
|
sender = msg.get("sender", "")
|
|
body = msg.get("content", {}).get("body", "")
|
|
print(f" [{sender}]: {body}")
|
|
|
|
return success
|
|
|
|
async def main():
|
|
"""Main function"""
|
|
print("📱 Matrix Messaging Test")
|
|
print("=" * 40)
|
|
|
|
# Test Home Assistant messaging
|
|
ha_success = await test_home_assistant_messaging()
|
|
|
|
# Test Signal bridge room messaging
|
|
bridge_success = await test_bridge_room_messaging()
|
|
|
|
print("\n" + "=" * 40)
|
|
print("📊 Test Results:")
|
|
print(f"🏠 Home Assistant room: {'✅ Working' if ha_success else '❌ Failed'}")
|
|
print(f"🌉 Signal bridge room: {'✅ Working' if bridge_success else '❌ Failed'}")
|
|
|
|
if ha_success or bridge_success:
|
|
print("\n✅ Matrix messaging is functional!")
|
|
print("💡 You can receive messages through the working rooms")
|
|
else:
|
|
print("\n❌ Matrix messaging issues detected")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |