Topic Based Chat

Topic based chat lets you to group the chat by topic. You can create the topic , send  all types of messages with topic information and thus you can receive the messages by topic.

Create Topic#

You can use the below given method to create a new topic

await SDK.createTopic({
topicName: "",
metaData: {} // Optional
});

Request Params#

StatusDescriptionTypeRequired
topicNameTopic name for the creation. We accept only the AlphaNumeric StringStringtrue
metaDatametaData is an optional parameter to provide MetaData of topic key pair value as string. Maximum size is 3Objectfalse

Sample Response:#

{
statusCode: 200, // Number - status code
message: "Success", // String - Success/Error Message
data: {
topicId: "123456789", //String - Unique Id For Topic Creation
}
}

Get Topics#

Use the below method to get topics details.

await SDK.getTopics(`TOPIC_IDS`);

Request Params#

StatusDescriptionTypeRequired
TOPIC_IDSList of Topic idsArray of Stringstrue

Example Response#

{
statusCode: 200, // Number - status code
message: "Success", // String - Success/Error Message
data:{
topics:[
{
metaData : {}, // Object - MetaData for the topic
topicId:"", // String - Topic Id
topicName:"" // String - Topic Name
},
//...
];
}
}

Send Message#

To send the message to the user, use the below methods. Different messages such as text, image, audio, video & document type messages can be sent using the below methods.

Text Message#

await SDK.sendTextMessage({
toJid: "",
messageText: "",
mentionedUsersIds: [], // Optional
topicId: "", // Optional
metaData: {} // Optional
});

To learn more on request and response about ' Text Message ' see the Text Message Section

Image Message#

await SDK.sendMediaFileMessage({
toJid: "",
messageType: "image",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: "",
},
replyMessageId: "",
mentionedUsersIds: [], //Optional
topicId: "", //Optional
metaData: {} //Optional
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);

To learn more on request and response about ' Image Message ' see the Image Message Section

Audio Message#

await SDK.sendMediaFileMessage({
toJid: "",
messageType: "audio",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: "",
},
replyMessageId: "",
mentionedUsersIds: [], //Optional
topicId: "", //Optional
metaData: {} //Optional
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);

To learn more on request and response about ' Audio Message ' see the Audio Message Section

Video Message#

await SDK.sendMediaFileMessage({
toJid: "",
messageType: "video",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: ""
},
replyMessageId: "",
mentionedUsersIds: [], //Optional
topicId: "", //Optional
metaData: {} //Optional
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);

To learn more on request and response about ' Video Message ' see the Video Message Section

Document Message#

await SDK.sendMediaFileMessage({
toJid: "",
messageType: "file",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: ""
},
replyMessageId: "",
mentionedUsersIds: [], //Optional
topicId: "", //Optional
metaData: {} //Optional
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);

To learn more on request and response about ' Document Message ' see the Document Message Section

Meet Message#

Before you send the meet message, you need to create the meet link using the createMeetLink method. Once the meet link has been created successfully, you can send the Meet message.

caution

If Group call feature is unavailable for your plan, then it will throw 403 exception

SDK.createMeetLink();

Response Format#

{
statusCode: `STATUS_CODE`,
message: `ERROR|SUCCESS message`,
data: "ehl-niyc-wcc"
}

You can send the meet message by using the sendMeetMessage method. You can share the title, link and schdueled date and time using this method.

caution

If Group call feature is unavailable for your plan, then it will throw 403 exception

await SDK.sendMeetMessage({
toJid: "",
link: "",
scheduledDateTime: 0,
title: "",
mentionedUsersIds: [],
topicId: "",
metaData: {}
});
ParamDescriptionTypeRequired
toJidJID of the To User/GROUPJID Stringtrue
linkMeet Link which we need to shareStringtrue
scheduledDateTimeScheduled Date and TimeNumber (Timestamp)true
titleMeet Title which we need to shareStringfalse
mentionedUsersIdsArray of Group Mentioned UsersIdsArray of Stringfalse
topicIdTopic Id for the MessageStringfalse
metaDataMetaData for the MessageStringfalse

Response Format:#

statusCode: 200, // Number - status code
message: "", // String - Success/Error Message
data:
{
chatType: "", // String - Chat Type - "chat"
createdAt: "", // String - Message Created Time
deleteStatus: "", // Number - Delete Status
favouriteBy: "", // String - Favourited By - User
favouriteStatus: "", //Number - Favourite status
fromUserJid: "", // String - From User Jid
metaData: {}, //Object - Meta data for the message
msgBody: {
    message_type: "meet", // String - Message Type
      nickName: "", // String - nick name
      mentionedUsersIds: [], // Array of mentioned users
      meet: {
      title: "", // String - Title
        scheduledDateTime: 1695202750020, // Number - Timestamp - Milliseconds
        link: "ehl-niyc-wcc" // String - Link
      }
    }
topicId: "", //String - Topic id for the message
msgId: "", // String - Unique Message Id
msgType: "", // String - Group Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
},

Send Reply Message#

To send a reply to the original message, we are using sendTextMessage by passing in the additional parameter original message-id.

await SDK.sendTextMessage({
toJid: "",
messageText: "",
replyMessageId: "",
mentionedUsersIds: [], // Optional
topicId: "", // Optional
metaData: {} // Optional
});

Receive a Message#

To receive a metaData related message from another user you must implement the messageListener function. It’s a function that will be triggered whenever you receive a new message or related event in the chat.

function messageListener(response) {
console.log("Message Listener", response);
}
note

To learn more on 'message listener callbacks,' see the Message Callback Event Listener Section

Get Chats By Topic Id#

Use the below method to get all the list of recent chats by topic id specific

await SDK.getChatsByTopicId({
topicId = "",
messageTime = "", // Optional
limit = 20 // Optional
});

Request Params#

StatusDescriptionTypeRequired
topicIdTopic id for the recent chats. We accept only the AlphaNumeric StringStringfalse
messageTimeLast chats message time of PaginationStringfalse
limitPagination LimitNumberfalse

Response Format:#

{
statusCode: 200, // Number - status code
message: "Success", // String - Success/Error Message
data: [
{
msgBody: {
media: { // For Media Message Only
caption: "", // String - Media Caption
duration: "", // String - Duration - For Audio/Videos
fileName: "", // String - File Name
file_size: "", // Number - File Size
file_url: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
message: "", // String - Message Body
message_type: "" // String - Message Type
mentionedUsersIds: [], // Array - Mentioned Ids For groupChat
nickName: "Rizwan" // String - User Name
},
msgId: "", // String - Unique Message Id
userJid: "", // String - User Jid
msgfromJid: "", // String - Message From User Jid
messageType: "", // String - Message Type
metaData: {}, // Object - Meta Data for Message
topicId: "", // String - Topic Id for Message
publisherJid: "", // String - Publisher Jid
msgStatus: "", // Number - Message Status
unreadCount: "", // Number - Unread Message Count
deleteStatus: "", // Number - Delete Status (Recall)
createdAt: "", // String - Created Time
messageTime:"", //String - Message Time
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
chatType: "", // String - Chat Type "chat"/"groupchat"
updatedAt: "", // String - Updated Time
muteStatus: 0, // Number - Mute Status
archiveStatus: 0 // Number - Archive Status
},
//...
];
}

Get Messages#

To get the chat and media messages, use the below methods

Get Chat Messages#

await SDK.getChatMessages({
toJid: "",
position: "",
lastRowId: "",
limit: "",
topicId: ""
});

To learn more on request and response about ' Get Chat Messages ' see the Get Chat Messages Section

Get Media Messages#

await SDK.getMediaMessages({
toJid: "",
lastMsgId: "",
topicId: ""
});

To learn more on request and response about ' Get Media Messages ' see the Get Media Messages Section