OpenAIChatKit
A Web Component that serves as the entry point for a ChatKit integration.
Extends
Section titled “Extends”HTMLElement
Methods
Section titled “Methods”addEventListener()
Section titled “addEventListener()”Call Signature
Section titled “Call Signature”addEventListener<K>( type: K, listener: EventHandler<K>, options?: boolean | AddEventListenerOptions): void;Adds an event listener for the specified ChatKitEvents event.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
See ChatKitEvents for available events. |
|
|
|
The event listener callback. |
|
|
|
An object that specifies characteristics about the event listener. See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#options |
Returns
Section titled “Returns”void
Example
Section titled “Example”chatKit.addEventListener('chatkit.error', (event) => { logToMyErrorLogger(event.detail.error);});https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
Overrides
Section titled “Overrides”HTMLElement.addEventListener;Call Signature
Section titled “Call Signature”addEventListener( type: string, listener: null | EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;Internal
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”HTMLElement.addEventListener;fetchUpdates()
Section titled “fetchUpdates()”fetchUpdates(): Promise<void>;Manually fetches updates from the server.
Use this when you’ve manually updated the thread or thread items and need to sync them with the client.
Returns
Section titled “Returns”Promise<void>
focusComposer()
Section titled “focusComposer()”focusComposer(): Promise<void>;Focuses the composer input field.
Returns
Section titled “Returns”Promise<void>
removeEventListener()
Section titled “removeEventListener()”Call Signature
Section titled “Call Signature”removeEventListener<K>( type: K, listener: EventHandler<K>, options?: boolean | EventListenerOptions): void;Removes an event listener for the specified event.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
See ChatKitEvents for available events. |
|
|
|
The event listener callback to remove. |
|
|
|
An object that specifies characteristics about the event listener. See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#options |
Returns
Section titled “Returns”void
Example
Section titled “Example”chatKit.removeEventListener('chatkit.error', myErrorListener);https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
Overrides
Section titled “Overrides”HTMLElement.removeEventListener;Call Signature
Section titled “Call Signature”removeEventListener( type: string, listener: null | EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;Internal
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”HTMLElement.removeEventListener;sendCustomAction()
Section titled “sendCustomAction()”sendCustomAction(action: { payload?: Record<string, unknown>; type: string;}, itemId?: string): Promise<void>;Sends a custom application-defined action to your backend. See https://openai.github.io/chatkit-js/guides/widget-actions/ for more details.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
{ |
‐ |
|
|
|
‐ |
|
|
|
‐ |
|
|
|
The ID of the WidgetItem that the action is associated with. You may need this if the action was triggered by a widget, gets handled client-side, and then you want to send the action back to the server to do additional handling. Example |
Returns
Section titled “Returns”Promise<void>
sendUserMessage()
Section titled “sendUserMessage()”sendUserMessage(params: { attachments?: Attachment[]; newThread?: boolean; reply?: string; text: string;}): Promise<void>;Sends a user message.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”Promise<void>
setComposerValue()
Section titled “setComposerValue()”setComposerValue(params: { attachments?: Attachment[]; reply?: string; text: string;}): Promise<void>;Sets the composer’s content without sending a message.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
{ |
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”Promise<void>
setOptions()
Section titled “setOptions()”setOptions(options: ChatKitOptions): void;Applies configuration options to the ChatKit instance.
IMPORTANT: New options are not merged with the existing options. You must provide a full set of options every time you call this method.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”void
setThreadId()
Section titled “setThreadId()”setThreadId(threadId: null | string): Promise<void>;Changes the active thread. Pass null to switch to a new thread.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Promise<void>