Private Message in TS6 Websocket

Im currently developing an app that acts on private messages, but after some debugging it seems like private message events arent sent over the websocket. Is this the case or am I going crazy? Im using the python websockets library and I see events for everything else except private messages

async def handle_message(raw: str) -> None:
    """Process a single message from the TS6 WebSocket."""
    try:
        msg = json.loads(raw)
    except json.JSONDecodeError:
        log.warning("Non-JSON message received: %s", raw[:200])
        return

    msg_type = msg.get("type", "")

    # Log every incoming message so we can see what TS6 actually sends
    log.info("Received [%s]: %s", msg_type, json.dumps(msg, indent=2))

async def connect() -> None:
    """Connect to the TS6 Remote Apps WebSocket and listen for events."""
    uri = f"ws://{config.TS6_WS_HOST}:{config.TS6_WS_PORT}"
    api_key = load_api_key()

    if api_key:
        log.info("Using stored API key")
    else:
        log.info("No stored API key — TS6 will prompt you to approve the app")

    async for ws in websockets.connect(uri):
        try:
            log.info("Connected to TS6 at %s", uri)
            await ws.send(build_auth_payload(api_key))

            async for raw in ws:
                await handle_message(str(raw))

        except websockets.ConnectionClosed:
            log.warning("Connection closed, reconnecting...")
        except Exception:
            log.exception("Unexpected error, reconnecting...")

        # websockets.connect with `async for` handles reconnection
        # with exponential backoff automatically

If I recall this correctly, global chat messages are not sent, but you should have access to the ones that are sent via a TS server.

2 Likes