Browse SDKs · WASM
SDKsWASM

Set a conversation draft

Save or clear a conversation draft with the WASM SDK.

Copy

Use setConversationDraft() to save a draft when the user leaves the chat page, switches conversations, or changes the input content. Pass conversationID and the draft text as draftText.

Keep editor state locally while the user is typing and debounce saves. Submit the latest text once immediately before leaving the page or switching conversations so that every keystroke does not write to the SDK.

await openimsdk.setConversationDraft(
  {
    conversationID,
    draftText: editorValue,
  }
);

Pass an empty string to clear the draft:

await openimsdk.setConversationDraft({
  conversationID,
  draftText: '',
});

State changes after the call

When setConversationDraft() succeeds, the draft has been saved. The SDK synchronizes the changed conversation through CbEvents.OnConversationChanged. The event's data is ConversationItem[]; merge draftText and draftTextTime by conversationID.

See Get the conversation list for complete event registration, cleanup, and conversation merging. Also clear in-memory editor state when signing out or switching accounts so that a draft from one account is not carried into another.