Skip to main content

Create Direct Message Chatroom

LikeMinds React Chat SDK offers a convenient feature to create Direct Message Chatrooms, allowing you to communicate privately with specific individuals.

Steps to check Direct Messages limit

  1. Check Direct Message Chatroom already exist or not and member have not crossed its limit to send Direct Message request, use the method checkDMLimit()
  2. Pass in the required parameter memberId.
  3. Process the response as per your requirement.
const payload: any = {
memberId: 23233, // Enter the member's ID to initiate a private message.
};
const response = await lmChatClient.checkDMLimit(payload);

if (response.success) {
// your function to process the response data
processResponse(response);
} else {
// your function to process error message
processError(response);
}

Check DM Limit Payload

List of parameters for the checkDMLimit() function.

VariableTypeDescriptionOptional
memberIdnumberMember Id

Check DM Limit Response

List of parameters in the response.

VariableTypeDescription
successbooleanAPI success status
error_messagestringError message in case of failure
is_request_dm_limit_exceededbooleanchecks whether the limit for sending request has already been hit or not.
chatroom_idnumberChatroom ID if the chatroom already exists

Steps to create direct message chatroom

  1. If Direct Message Chatroom does not exist and limit is not exceeded, use the method createDMChatroom()
  2. Pass in the required parameter memberId.
  3. Process the response as per your requirement.
const payload: any = {
memberId: 23233, // Enter the member's Id to initiate a private message.
};
const response = await lmChatClient.checkDMLimit(payload);

if (response.success) {
// your function to process the response data
let res = response?.data;
if (!!res?.chatroom_id) {
//DM already created
processResponse(response); // Open the respective chatroom
} else {
if (res?.is_request_dm_limit_exceeded === false) {
const payloadCreateDM: any = {
memberId: 23233, // Enter the member's ID to initiate a private message.
};
const responseCreateDM = await lmChatClient.createDMChatroom(
payloadCreateDM
);

if (responseCreateDM.success) {
// your function to process the response data
processResponse(responseCreateDM);
} else {
// your function to process error message
processError(responseCreateDM);
}
} else {
alert("Request limit exceeded"); ////Show disclaimer popup on limit exceed.
}
}
} else {
// your function to process error message
processError(response);
}

Create DM Chatroom Payload

List of parameters for the createDMChatroom() function.

VariableTypeDescriptionOptional
memberIdnumberMember Id

Create DM Chatroom Response

List of parameters in the response.

VariableTypeDescription
successbooleanAPI success status
error_messagestringError message in case of failure
chatroomobjectChatroom Details