#!/usr/bin/env python3 """ Check Signal bridge authentication status and complete login process """ import asyncio import httpx import json MATRIX_HOMESERVER = "https://matrix.klas.chat" CLAUDE_ACCESS_TOKEN = "syt_Y2xhdWRl_CoBgPoHbtMOxhvOUcMnz_2WRPZJ" SIGNAL_BRIDGE_BOT_ID = "@signalbot:matrix.klas.chat" BRIDGE_DM_ROOM_ID = "!oBnnfKDprgMEHNhNjL:matrix.klas.chat" # From previous setup async def get_bridge_room_messages(): """Get recent messages from the Signal bridge DM room""" try: async with httpx.AsyncClient() as client: headers = {"Authorization": f"Bearer {CLAUDE_ACCESS_TOKEN}"} # Get recent messages from the bridge room response = await client.get( f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{BRIDGE_DM_ROOM_ID}/messages", headers=headers, params={"limit": 20, "dir": "b"} ) if response.status_code == 200: data = response.json() print("šŸ“± Recent Signal Bridge Messages:") print("=" * 50) for event in data.get("chunk", []): if event.get("type") == "m.room.message": sender = event.get("sender", "") content = event.get("content", {}) body = content.get("body", "") timestamp = event.get("origin_server_ts", 0) sender_name = "Claude" if "claude" in sender else "Signal Bot" print(f"[{sender_name}]: {body}") return data.get("chunk", []) else: print(f"āŒ Failed to get messages: {response.status_code}") print(f"Response: {response.text}") return [] except Exception as e: print(f"āŒ Error getting bridge messages: {e}") return [] async def send_bridge_command(command, explanation=""): """Send a command to the Signal bridge bot""" try: async with httpx.AsyncClient() as client: headers = { "Authorization": f"Bearer {CLAUDE_ACCESS_TOKEN}", "Content-Type": "application/json" } print(f"šŸ¤– Sending: {command}") if explanation: print(f" {explanation}") response = await client.post( f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{BRIDGE_DM_ROOM_ID}/send/m.room.message", headers=headers, json={ "msgtype": "m.text", "body": command } ) if response.status_code == 200: print(f"āœ… Command sent: {command}") await asyncio.sleep(2) # Wait for response return True else: print(f"āŒ Failed to send command: {response.status_code}") return False except Exception as e: print(f"āŒ Error sending command: {e}") return False async def try_signal_authentication(): """Try various Signal bridge authentication methods""" # Common Signal bridge commands to try auth_commands = [ ("help", "Get help and available commands"), ("register", "Register with Signal bridge"), ("login", "Login to Signal bridge"), ("!signal help", "Signal-specific help"), ("!signal register", "Signal registration"), ("!signal login", "Signal login"), ("status", "Check current status"), ("whoami", "Check current user"), ("bridge", "Bridge-specific commands") ] print("šŸ” Trying Signal Bridge Authentication...") print("=" * 50) for command, explanation in auth_commands: await send_bridge_command(command, explanation) # Check for responses after each command print("šŸ“¬ Checking for responses...") messages = await get_bridge_room_messages() # Look for any authentication responses recent_bot_messages = [ msg for msg in messages[-3:] if msg.get("sender") == SIGNAL_BRIDGE_BOT_ID and msg.get("type") == "m.room.message" ] if recent_bot_messages: print("šŸ”” Recent bot responses:") for msg in recent_bot_messages: body = msg.get("content", {}).get("body", "") print(f" → {body}") print("-" * 30) async def check_bridge_configuration(): """Check if we need to configure the bridge differently""" try: async with httpx.AsyncClient() as client: headers = {"Authorization": f"Bearer {CLAUDE_ACCESS_TOKEN}"} # Check if we're actually in the room response = await client.get( f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{BRIDGE_DM_ROOM_ID}/state/m.room.member/@claude:matrix.klas.chat", headers=headers ) if response.status_code == 200: data = response.json() membership = data.get("membership", "unknown") print(f"āœ… Claude membership in bridge room: {membership}") if membership != "join": print("āŒ Claude is not properly joined to the bridge room") return False else: print(f"āŒ Failed to check room membership: {response.status_code}") return False # Check room power levels to see if Claude can send messages response = await client.get( f"{MATRIX_HOMESERVER}/_matrix/client/v3/rooms/{BRIDGE_DM_ROOM_ID}/state/m.room.power_levels", headers=headers ) if response.status_code == 200: power_data = response.json() users = power_data.get("users", {}) claude_power = users.get("@claude:matrix.klas.chat", 0) print(f"āœ… Claude power level: {claude_power}") return True except Exception as e: print(f"āŒ Error checking bridge configuration: {e}") return False async def main(): """Main function""" print("šŸŒ‰ Signal Bridge Authentication Troubleshooting") print("=" * 60) # Step 1: Check bridge configuration print("\n1. Checking bridge room configuration...") config_ok = await check_bridge_configuration() if not config_ok: print("āŒ Bridge configuration issues detected") return # Step 2: Get current message history print("\n2. Getting recent bridge messages...") await get_bridge_room_messages() # Step 3: Try authentication commands print("\n3. Attempting authentication...") await try_signal_authentication() # Step 4: Final status check print("\n4. Final status check...") await get_bridge_room_messages() print("\n" + "=" * 60) print("šŸ” Bridge Authentication Troubleshooting Complete") print("\nšŸ’” If authentication still fails:") print("1. Signal bridge may require phone number verification") print("2. Bridge may need admin approval for new users") print("3. Check if Signal bridge supports automated registration") print("4. May need manual intervention from bridge administrator") if __name__ == "__main__": asyncio.run(main())