Open a conversation
Get a conversation for a user or group with the WASM SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
sourceID | string | Yes | The other user's ID for a one-to-one chat, or the group ID for a group chat. |
sessionType | SessionType | Yes | Use 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 establishes the current snapshot and does not trigger a conversation event. Merge subsequent changes by conversationID through the event handlers on the conversation-list page.
Was this page helpful?