createTalkitChat
Create and control a TalkIt Website text-chat client in the browser.
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.
declare function createTalkitChat(config: TalkitChatConfig): TalkitChat;
TalkitChatConfig
Configures the TalkIt server, session-grant callback, and startup timeout.
interface TalkitChatConfig {
baseUrl: string;
getSessionToken: () => Promise<string | TalkitChatSessionTokenResult>;
startupTimeoutMs?: number;
}
TalkitChatSessionTokenResult
Describes the grant returned by the session-token callback.
interface TalkitChatSessionTokenResult {
sessionToken: string;
websocketUrl?: string;
expiresAt?: string;
}
TalkitChat
Exposes connection, messaging, history, cancellation, cleanup, and typed event APIs.
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.
type TalkitChatEventName = keyof TalkitChatEventMap;
TalkitChatEventHandler
Typed callback for one chat event.
type TalkitChatEventHandler<TEventName extends TalkitChatEventName> = (event: TalkitChatEventMap[TEventName]) => void;
TalkitChatEventMap
Maps every supported chat event name to its payload type.
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.
interface TalkitChatLifecycleEvent {
threadId?: string;
}
TalkitChatStateEvent
Reports the current chat connection state.
interface TalkitChatStateEvent {
threadId?: string;
state: 'idle' | 'connecting' | 'connected' | 'ready' | 'ended';
}
TalkitChatReadyEvent
Reports the resolved thread and conversation identifiers after connection.
interface TalkitChatReadyEvent {
threadId: string;
scopedThreadId?: string;
conversationGroupKey?: string;
}
TalkitChatAckEvent
Correlates an accepted message with its client-generated identifier.
interface TalkitChatAckEvent {
threadId: string;
messageId: string;
clientMessageId: string;
status: 'received';
timestamp: number;
}
TalkitChatBatchEvent
Carries transport events and any rendered assistant-message updates.
interface TalkitChatBatchEvent {
threadId: string;
events: unknown[];
renderedMessages?: TalkitChatRenderedMessage[];
}
TalkitChatRenderedMessage
Describes one rendered assistant message update emitted by a batch event.
interface TalkitChatRenderedMessage {
renderedMessageId: string;
turnId?: string;
text: string;
status: 'streaming' | 'final';
deliveryDelayMs?: number;
}
TalkitChatHistoryMessage
Represents one message returned by history pagination.
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.
interface TalkitChatHistoryEvent {
messages: TalkitChatHistoryMessage[];
pagination: {
hasMore: boolean;
nextBefore?: string;
};
}
TalkitChatEndedEvent
Reports the thread and optional termination reason.
interface TalkitChatEndedEvent {
threadId?: string;
reason?: string;
}
TalkitChatErrorEvent
Reports a chat error and optional client message correlation identifier.
interface TalkitChatErrorEvent {
code?: string;
message: string;
clientMessageId?: string;
}