SDKsHarmonyOSEnterprise
Get conversation ID
Derive a stable conversation ID based on the chat target and session type.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
sourceID | string | Yes | Target identifier: userID for direct chats, or groupID for group chats. |
sessionType | SessionType | Yes | SessionType.Single for direct chats or SessionType.WriteGroup for group chats. |
Return value
Returns a Promise that resolves to a GetConversationIDBySessionTypeResp object:
| Property | Type | Description |
|---|---|---|
conversationID | string | The 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.
Was this page helpful?