#!/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())