myContactCenterManual

chatHub — interface reference

Register, AddMessage, Reconnect and server events of the SignalR chat hub, also searchable as webChatHub.

Endpoint: /chatHub. The connection belongs to the browser session; the Routing Service uses its SignalR connection ID to identify the chat.

Website methods

Method for connection.invoke Arguments in this order Return value
Register customerName (string), skill (string), language (string) boolean
AddMessage message (string) no application-level acknowledgement
Reconnect conversationId (string) boolean

Register triggers processing of a new chat request. skill and language must match a configured chat flow mapping. true means that the hub method completed without its own error. Subsequent processing can still fail. The server then sends the conversation ID with the SetConversationIdAsync event.

Reconnect moves an existing chat to the current connection, see Resuming a chat after a reload.

Call AddMessage only for a registered chat. If no chat exists for the connection, the server logs the error and does not process the message. A completed invoke operation is therefore not a delivery acknowledgement.

Server events

Name for connection.on Arguments Meaning
OnStateChangedAsync newState new conversation state
OnPositionChangedAsync position reported queue position
AddMessageAsync participant, htmlMessage participant label and message
SetConversationIdAsync conversationId ID of the chat; after Register and every successful Reconnect
OnChatContinuedElsewhereAsync – The chat continues in another window; this connection is no longer responsible.

Use the event names including Async. Chat sends one argument for a state change; callback sends two.

With the normal JSON configuration, the state is a numeric ConversationState. Common values are Inactive = 0, Waiting = 1, Alerting = 2, Connected = 3, Disconnected = 13 and OnHold = 14; Finalized = -1. Handle other values too, including closure and error states, rather than displaying an unknown value as connected. The flow determines the actual sequence.

htmlMessage may contain HTML. Do not insert it using unchecked innerHTML. The chat guide displays plain text; if formatting is required, the website must explicitly filter permitted HTML.

Close the connection

connection.stop() closes the connection. This does not end the chat immediately: the Routing Service keeps it available for another 30 seconds after the disconnect and only then unregisters it. During this time, it does not deliver a waiting chat to any agent, but the chat keeps its place in the queue. A chat that is already ringing at an agent or connected to one stays there. Do not silently register a second request after reconnecting.

Resuming a chat after a reload

If the visitor reloads the page, the website can resume the running chat within the 30 seconds:

  1. Remember the ID from SetConversationIdAsync, for example in a cookie. Browsers do not store cookies for pages opened directly as a file; the page must come from a web server.
  2. After setting up a new connection, call Reconnect(conversationId) first.
  3. If Reconnect returns true, the chat continues: the server sends the current state with OnStateChangedAsync and the history so far again with AddMessageAsync; so clear the displayed messages first.
  4. If it returns false — the ID is unknown, the 30 seconds have expired or the chat has ended —, call Register for a new chat.

If the visitor opens the same chat in a second window, that window takes it over. The first window receives OnChatContinuedElsewhereAsync; lock the input there and close the connection.

    ↑ ↓ select · Enter open · Esc close