Browse SDKs · WASM
SDKsWASM

Open a conversation

Get a conversation for a user or group with the WASM SDK.

Copy

Use getOneConversation() when opening a chat from a contact list, user profile, or group profile. For a one-to-one chat, pass the other user's userID as sourceID. For a group chat, pass groupID as sourceID. Even if no messages have been exchanged, let the SDK return the conversation instead of constructing a conversationID or ConversationItem in the application.

Parameters

ParameterTypeRequiredDescription
sourceIDstringYesThe other user's ID for a one-to-one chat, or the group ID for a group chat.
sessionTypeSessionTypeYesUse SessionType.Single for a one-to-one chat and SessionType.WorkingGroup for a group chat.
import { SessionType } from '@openim/wasm-client-sdk';

const { data: conversation } = await openimsdk.getOneConversation({
  sourceID: targetUserID,
  sessionType: SessionType.Single,
});

openChatPage(conversation);

The successful Promise returns a ConversationItem that can be passed directly to the chat page. See Get the conversation list for field descriptions.

This query returns the conversation data available at the time of the call and does not trigger a conversation event. When a later event arrives, use conversationID to find and update the matching conversation. See Get the conversation list for the complete handling flow.