Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Get conversation ID

Derive a stable conversation ID based on the chat target and session type.

Copy

Use getConversationIDBySessionType() when your application needs only the canonical conversationID string rather than the full conversation object:

Code example

import sdk, {
  GetConversationIDBySessionTypeReq,
  GetConversationIDBySessionTypeResp,
  SessionType,
} from '@openimsdk/imsdk';

const request: GetConversationIDBySessionTypeReq = {
  sourceID: targetUserID,
  sessionType: SessionType.Single,
};
const response: GetConversationIDBySessionTypeResp =
  await sdk.getConversationIDBySessionType(request);
useConversationID(response.conversationID);

Parameters

ParameterTypeRequiredDescription
sourceIDstringYesTarget identifier: userID for direct chats, or groupID for group chats.
sessionTypeSessionTypeYesSessionType.Single for direct chats or SessionType.WriteGroup for group chats.

Return value

Returns a Promise that resolves to a GetConversationIDBySessionTypeResp object:

PropertyTypeDescription
conversationIDstringThe authoritative conversation identifier derived by the native SDK engine.

State changes after the call

For group chats, set sourceID to the group ID and use SessionType.WriteGroup. The SDK calculates conversationID deterministically using internal hashing algorithms; never synthesize conversation IDs by manually concatenating strings. If you require the full conversation record containing drafts and unread counts, see Retrieve conversation by target.