Skip to documentation content
Docs
Documentation navigation
Reference
6 min read

createTalkitChat

Create and control a TalkIt Website text-chat client in the browser.

UpdatedByTalkIt Docs team
On this page

Use createTalkitChat with a callback that obtains a fresh, short-lived Website session grant before opening the text connection.

Package provenance

Generated from @talkit-llc/talkit-js@0.1.12, entrypoint ..

Download the TypeScript declaration snapshot

createTalkitChat

Creates a text-chat client from the supplied transport and grant configuration.

TS
declare function createTalkitChat(config: TalkitChatConfig): TalkitChat;

TalkitChatConfig

Configures the TalkIt server, session-grant callback, and startup timeout.

TS
interface TalkitChatConfig {
    baseUrl: string;
    getSessionToken: () => Promise<string | TalkitChatSessionTokenResult>;
    startupTimeoutMs?: number;
}

TalkitChatSessionTokenResult

Describes the grant returned by the session-token callback.

TS
interface TalkitChatSessionTokenResult {
    sessionToken: string;
    websocketUrl?: string;
    expiresAt?: string;
}

TalkitChat

Exposes connection, messaging, history, cancellation, cleanup, and typed event APIs.

TS
interface TalkitChat {
    connect(): Promise<void>;
    send(message: string | Record<string, unknown>, options?: {
        clientMessageId?: string;
    }): string;
    loadEarlier(before?: string, limit?: number): void;
    cancel(): void;
    disconnect(): void;
    destroy(): void;
    on<TEventName extends TalkitChatEventName>(eventName: TEventName, handler: TalkitChatEventHandler<TEventName>): void;
    off<TEventName extends TalkitChatEventName>(eventName: TEventName, handler: TalkitChatEventHandler<TEventName>): void;
}

TalkitChatEventName

Union of the supported chat event names.

TS
type TalkitChatEventName = keyof TalkitChatEventMap;

TalkitChatEventHandler

Typed callback for one chat event.

TS
type TalkitChatEventHandler<TEventName extends TalkitChatEventName> = (event: TalkitChatEventMap[TEventName]) => void;

TalkitChatEventMap

Maps every supported chat event name to its payload type.

TS
interface TalkitChatEventMap {
    connecting: TalkitChatLifecycleEvent;
    connected: TalkitChatLifecycleEvent;
    ready: TalkitChatReadyEvent;
    ack: TalkitChatAckEvent;
    batch: TalkitChatBatchEvent;
    ended: TalkitChatEndedEvent;
    error: TalkitChatErrorEvent;
    history: TalkitChatHistoryEvent;
    state: TalkitChatStateEvent;
}

TalkitChatLifecycleEvent

Common lifecycle payload that may identify the thread.

TS
interface TalkitChatLifecycleEvent {
    threadId?: string;
}

TalkitChatStateEvent

Reports the current chat connection state.

TS
interface TalkitChatStateEvent {
    threadId?: string;
    state: 'idle' | 'connecting' | 'connected' | 'ready' | 'ended';
}

TalkitChatReadyEvent

Reports the resolved thread and conversation identifiers after connection.

TS
interface TalkitChatReadyEvent {
    threadId: string;
    scopedThreadId?: string;
    conversationGroupKey?: string;
}

TalkitChatAckEvent

Correlates an accepted message with its client-generated identifier.

TS
interface TalkitChatAckEvent {
    threadId: string;
    messageId: string;
    clientMessageId: string;
    status: 'received';
    timestamp: number;
}

TalkitChatBatchEvent

Carries transport events and any rendered assistant-message updates.

TS
interface TalkitChatBatchEvent {
    threadId: string;
    events: unknown[];
    renderedMessages?: TalkitChatRenderedMessage[];
}

TalkitChatRenderedMessage

Describes one rendered assistant message update emitted by a batch event.

TS
interface TalkitChatRenderedMessage {
    renderedMessageId: string;
    turnId?: string;
    text: string;
    status: 'streaming' | 'final';
    deliveryDelayMs?: number;
}

TalkitChatHistoryMessage

Represents one message returned by history pagination.

TS
interface TalkitChatHistoryMessage {
    id: string;
    role: 'participant' | 'assistant' | 'operator';
    content: Record<string, unknown>;
    timestamp: number;
}

TalkitChatHistoryEvent

Carries a page of history messages and its pagination state.

TS
interface TalkitChatHistoryEvent {
    messages: TalkitChatHistoryMessage[];
    pagination: {
        hasMore: boolean;
        nextBefore?: string;
    };
}

TalkitChatEndedEvent

Reports the thread and optional termination reason.

TS
interface TalkitChatEndedEvent {
    threadId?: string;
    reason?: string;
}

TalkitChatErrorEvent

Reports a chat error and optional client message correlation identifier.

TS
interface TalkitChatErrorEvent {
    code?: string;
    message: string;
    clientMessageId?: string;
}

Was this page helpful?

Page feedback is not available right now.