ChatThread

public struct ChatThread : Identifiable, Sendable

All information about a chat thread as well as the messages for the thread.

  • id

    The unique id of the thread. Refers to the idOnExternalPlatform.

    The canonical, case-preserving identifier of the thread as provided by the backend. Stores the exact value from the backend, without altering case.

    Declaration

    Swift

    public let id: String
  • The name given to the thread (for multi-thread channels only).

    Declaration

    Swift

    public let name: String?
  • The list of messages on the thread.

    Declaration

    Swift

    public let messages: [Message]
  • The agent assigned in the thread.

    Declaration

    Swift

    public let assignedAgent: Agent?
  • The last agent that has been assigned to the thread

    This attribute can be used to get the previously assigned agent back to the thread after unassignment.

    Declaration

    Swift

    public let lastAssignedAgent: Agent?
  • The agent that owns the case — the last agent it was actually assigned to.

    Unlike assignedAgent (the inbox assignee, i.e. who currently has the case open), the owner persists across unassignment. It is populated from the backend on thread recovery and is used to determine that the customer has already been engaged by an agent (and is therefore no longer in the queue).

    Declaration

    Swift

    public let ownerAssignee: Agent?
  • The identifier of the contact associated with this thread, as provided by the backend.

    May be nil when the thread has no associated contact yet — for example, a thread constructed locally before the SDK has populated it. This value is read-only: it is supplied by the SDK and cannot be set when constructing a ChatThread directly.

    Declaration

    Swift

    public let contactId: String?
  • The token for the scroll position used to load more messages.

    Declaration

    Swift

    public let scrollToken: String
  • The thread state

    Declaration

    Swift

    public let state: ChatThreadState
  • Whether there are more messages to load in the thread.

    Declaration

    Swift

    public var hasMoreMessagesToLoad: Bool { get }
  • The position in the queue

    Declaration

    Swift

    public let positionInQueue: Int?
  • The party currently responsible for handling the contact behind this thread.

    While an automated bot holds the contact, the customer is not queued for a human agent, so there is no position in queue to report. Once the bot hands the conversation over, this becomes cxone and the regular routing rules apply again.

    nil when the platform reports no handler for the channel, in which case the thread behaves exactly as it did before handlers existed.

    Declaration

    Swift

    public let contactHandler: ContactHandler?

Init

  • Creates a ChatThread value, typically when synthesising threads for tests, previews, or seeding state.

    Production code receives ChatThread instances from the SDK via the threads provider and the threadUpdated(_:) / threadsUpdated(_:) events — direct construction is rarely needed.

    Declaration

    Swift

    public init(
        id: String,
        state: ChatThreadState,
        name: String? = nil,
        messages: [Message] = [],
        assignedAgent: Agent? = nil,
        lastAssignedAgent: Agent? = nil,
        ownerAssignee: Agent? = nil,
        scrollToken: String = "",
        positionInQueue: Int? = nil,
        contactHandler: ContactHandler? = nil
    )

    Parameters

    id

    The backend-canonical thread identifier (idOnExternalPlatform).

    state

    The current state of the thread.

    name

    Display name (multi-thread channels only).

    messages

    The known messages on the thread.

    assignedAgent

    Currently assigned agent, if any.

    lastAssignedAgent

    Previously assigned agent, useful for re-assignment flows.

    ownerAssignee

    The agent that owns the case, persisted across unassignment.

    scrollToken

    Cursor for paging older messages; empty means no more history.

    positionInQueue

    Position in queue for live-chat scenarios.

    contactHandler

    The party currently handling the contact, when the platform reports one.