#!/usr/bin/env python3 """ Complete Signal bridge authentication by checking login status and attempting proper authentication """ 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" 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(3) # Wait longer 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 get_bridge_room_messages(limit=10): """Get recent messages from the Signal bridge DM 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/{BRIDGE_DM_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 bridge messages: {e}") return [] async def check_login_status(): """Check current login status""" print("šŸ“‹ Checking current login status...") await send_bridge_command("list-logins", "Check existing logins") messages = await get_bridge_room_messages(5) recent_bot_messages = [ msg for msg in messages if msg.get("sender") == SIGNAL_BRIDGE_BOT_ID and msg.get("type") == "m.room.message" ] print("šŸ”” Recent bot responses:") for msg in recent_bot_messages[:3]: # Show last 3 responses body = msg.get("content", {}).get("body", "") print(f" → {body}") return recent_bot_messages async def attempt_manual_authentication(): """Try to authenticate manually with Signal bridge""" print("\nšŸ” Attempting manual authentication...") # First check if we have any existing logins await check_login_status() # Try to get version info print("\nšŸ“± Getting bridge version...") await send_bridge_command("version", "Get bridge version") # Check messages messages = await get_bridge_room_messages(5) recent_bot_messages = [ msg for msg in messages if msg.get("sender") == SIGNAL_BRIDGE_BOT_ID and msg.get("type") == "m.room.message" ] print("šŸ”” Recent responses:") for msg in recent_bot_messages[:3]: body = msg.get("content", {}).get("body", "") print(f" → {body}") # Try to initiate login process print("\nšŸš€ Initiating login process...") await send_bridge_command("login", "Start login process") # Check for QR code or other authentication responses await asyncio.sleep(2) messages = await get_bridge_room_messages(5) recent_bot_messages = [ msg for msg in messages if msg.get("sender") == SIGNAL_BRIDGE_BOT_ID and msg.get("type") == "m.room.message" ] print("šŸ”” Authentication responses:") for msg in recent_bot_messages[:3]: body = msg.get("content", {}).get("body", "") print(f" → {body}") # Check if we got a QR code link if "sgnl://linkdevice" in body: print(f"šŸ”— QR Code link detected: {body}") print("šŸ“± To complete authentication:") print(" 1. Open Signal app on your phone") print(" 2. Go to Settings > Linked devices") print(" 3. Tap 'Link New Device'") print(" 4. Scan the QR code or use the link above") return True return False async def main(): """Main function""" print("šŸŒ‰ Signal Bridge Authentication Completion") print("=" * 50) # Check current status await check_login_status() # Try manual authentication has_auth_method = await attempt_manual_authentication() if has_auth_method: print("\nāœ… Authentication method available!") print("šŸ“± Complete the authentication using your Signal app") print("šŸ” After scanning QR code, run this script again to verify") else: print("\nāŒ No authentication method available") print("šŸ’” This may require manual intervention or bridge configuration") if __name__ == "__main__": asyncio.run(main())