Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Create a card message

Construct a contact business card message to share a user’s profile information.

Copy

Invoke createCardMessage() to produce a contact card message sharing a user's profile details. The embedded profile attributes represent a snapshot at creation time and do not update automatically if the target user modifies their profile later.

Parameters

ParameterTypeRequiredDescription
userIDstringRecommendedStable user ID of the shared user profile.
nicknamestringRecommendedDisplay name shown on the contact card.
faceURLstringNoAvatar URL for the shared contact.
exstringNoCustom extension string; the SDK preserves this as an unparsed string.

Code example

import { createCardMessage } from '@/uni_modules/unix-openim-sdk'

const message = await createCardMessage({
  userID: 'user_42',
  nickname: 'Alex',
  faceURL: 'https://example.com/avatar/user_42.png',
  ex: JSON.stringify({ source: 'team-directory' }),
})
if (message == null) return

While individual fields are typed as optional, constructing a meaningful card requires a valid userID and display name. When recipients initiate actions such as sending a friend request or opening a chat from a card, re-query user information through Get user profiles rather than treating card fields as live authorization credentials.

Return value

The Promise resolves with an OpenIMMessageItem | null object.

State changes after the call

Pass the constructed message item to Send a message. Track message status updates in your UI using clientMsgID.