I’m building a custom chat UI in C# instead of using the widget. I can connect to the WebSocket endpoint just fine. The docs say I need to send a connect event with routing attributes.
I’m sending this JSON:
{
"event": "connect",
"routing": {
"attributes": {
"email": "test@example.com"
}
}
}
But the server just responds with error: invalid message. What’s the exact payload structure? The docs are vague on the schema.
The issue isn’t the JSON structure itself, it’s the missing routing object wrapper for the connect event in the Guest API. You’re sending routing.attributes, but the spec expects the attributes to be nested deeper under routing.data or passed as part of the initial connection handshake payload depending on the exact endpoint version. Actually, for the standard Guest API WebSocket, the connect message needs to include the routing object with queueId and attributes inside it. The error invalid message usually means the schema validation failed because a required field like routing.queueId is missing. You can’t just send attributes; you need to specify where the guest is going. Here’s the correct payload structure. You’ll need to get the Queue ID from your Genesys Cloud instance first. Don’t forget to set the routing.language if you have multiple language queues configured. It’s easy to miss that one.
{
"event": "connect",
"routing": {
"queueId": "your-actual-queue-id-here",
"language": "en-US",
"attributes": {
"email": "test@example.com",
"custom_field": "some_value"
}
}
}
If you’re still getting errors, check the WebSocket logs in Genesys Cloud Admin > Chat > Settings. They show the exact reason for the rejection. Sometimes it’s a simple typo in the queue ID. Also, ensure your application has the necessary permissions to connect via the Guest API. The guest:write scope is required. Without it, the connection might hang or fail silently. I’ve seen this trip people up before. The docs are a bit sparse on the exact error messages. Just make sure the queueId matches an active queue in your environment. If the queue is paused, the connection will also fail. Check the queue status in the admin UI. It’s a quick fix once you spot it.