Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create business card message

Create a contact card message to share user identity and profile information.

Copy

Contact card data is captured at the time the message is created and does not automatically update when user profile attributes change later.

Code example

import sdk, { CreateCardMessageReq, CreateCardMessageResp } from '@openimsdk/imsdk';

const request: CreateCardMessageReq = {
  userID: 'user_42',
  nickname: 'Alex',
  faceURL: 'https://example.com/avatar/user_42.png',
  ex: JSON.stringify({ source: 'team-directory' }),
};
const response: CreateCardMessageResp = await sdk.createCardMessage(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
userIDstringYesTarget user ID represented by the contact card.
nicknamestringYesDisplay nickname captured at creation time.
faceURLstringYesAvatar URL captured at creation time.
exstringYesCustom extension string.

Return value

Returns a Promise resolving to CreateCardMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated business card message object.

State changes after the call

All four fields are required. Before initiating friend requests or starting conversations from a card, receiving clients should query the latest user profile and verify permissions rather than treating card fields as live identity credentials. This operation instantiates the message object locally; call Send message to dispatch it.