Single chat

note

To generate your own or others JID using the unique username got in registration response, use the const userJid = SDK.getJid(USER_ID) method.

Get Recent Chats#

To get all the list of recent chats, send a request to the server as described below.

Check here for response format

await SDK.getRecentChats();

Response Params#

ArgumentsDescriptionType
statusCodeStatus CodeNumber
messageSuccess/Error MessageString
dataArray of Object datasArray

Get Chat Messages#

To get the chat history of the selected user, send a request to the server as described below.

Check here for response format

Without Pagination

await SDK.getChatMessages(`TO_JID`);

With Pagination

await SDK.getChatMessages(`TO_JID`, `POSITION`, `LAST_ROW_ID`, `LIMIT`);

Example

await SDK.getChatMessages(
"91XXXXXXXXXX@domain.com",
"down",
"12345",
10,
);

Request Params#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
POSITIONPosition for PaginationStringfalse
LAST_ROW_IDLast Row ID of PaginationStringfalse
LIMITPagination LimitNumberfalse

Note: POSITION - Accepts "down"/"up"

Response Params#

ArgumentsDescriptionType
statusCodeStatus CodeNumber
messageSuccess/Error MessageString
dataArray of Object datasArray

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: []
});

Sample Request:#

await SDK.sendTextMessage({
toJid: "123456789@xmppdomain",
messageText: "hello",
mentionedUsersIds: ['910987654321']
})
ParamDescriptionTypeRequired
toJidJID of the To UserJID Stringtrue
messageTextText Message BodyStringtrue
mentionedUsersIdsArray of Group Mentioned UsersIdsArrayfalse

Response Format:#

statusCode: "", // 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
msgBody: {
message: "", // String - Message Body
message_type: "", // String - Message Type
nickname: "", // String - nick name
mentionedUsersIds: [] // Array of mentioned users
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Group Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
},

Image Message#

caution

If Image attachment feature is unavailable for your plan, then it will throw 403 exception

await SDK.sendFileMessage({
toJid: "",
messageType: "image",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: "",
},
replyMessageId: "",
mentionedUsersIds: []
});
ParamDescriptionTypeRequired
toJidJID of the To UserJID Stringtrue
fileMessageParamsFile Message ParamsObjecttrue
fileMessageParams.fileImage File - Should be of type png, jpg, jpeg, svg & gifFiletrue
fileMessageParams.thumbImageImage File Thumb Image. When the value not given, SDK will generate thumb image for the given FILE. When using the fileUrl SDK won't generate the thumb image.Stringfalse
fileMessageParams.fileSizeImage File Size. When the value not given, SDK will detect the size of the given FILE. When using the fileUrl SDK won't detect the size.Stringfalse
fileMessageParams.fileNameImage File Name. When the value not given, SDK will detect the name of the given FILE. When using the fileUrl SDK won't detect the name.Stringfalse
fileMessageParams.captionImage CaptionStringfalse
replyMessageIdMessage ID of Original MessageStringfalse
mentionedUsersIdsArray of Group Mentioned UsersIdsArray of Stringsfalse

Response Format:#

statusCode: "", // 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
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
fileToken: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
message_type: "", // String - Message Type
nickname: "", // String - nick name
mentionedUsersIds: [] // Array of mentioned users
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Group Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
},

Audio Message#

caution

If Audio attachment feature is unavailable for your plan, then it will throw 403 exception

await SDK.sendFileMessage({
toJid: "",
messageType: "audio",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: "",
},
replyMessageId: "",
mentionedUsersIds: []
});
ParamDescriptionTypeRequired
toJidJID of the To UserJID Stringtrue
fileMessageParamsFile Message ParamsObjecttrue
fileMessageParams.fileAudio File - Should be of type mp3, mpeg & wavFiletrue
fileMessageParams.fileSizeAudio File Size. When the value not given, SDK will detect the size of the given FILE. When using the fileUrl SDK won't detect the size.Stringfalse
fileMessageParams.fileNameAudio File Name. When the value not given, SDK will detect the name of the given FILE. When using the fileUrl SDK won't detect the name.Stringfalse
fileMessageParams.durationAudio File Duration. When the value not given, SDK will detect the duration of the given FILE. When using the fileUrl SDK won't detect the duration.Stringfalse
fileMessageParams.captionAudio CaptionStringfalse
replyMessageIdMessage ID of Original MessageStringfalse
mentionedUsersIdsArray of Group Mentioned UsersIdsArray of Stringsfalse

Response Format:#

statusCode: "", // 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
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
fileToken: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
message_type: "", // String - Message Type
nickname: "", // String - nick name
mentionedUsersIds: [] // Array of mentioned users
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Group Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
},

Video Message#

caution

If Video attachment feature is unavailable for your plan, then it will throw 403 exception

await SDK.sendFileMessage({
toJid: "",
messageType: "video",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: ""
},
replyMessageId: "",
mentionedUsersIds: []
});
ParamDescriptionTypeRequired
toJidJID of the To UserJID Stringtrue
fileMessageParamsFile Message ParamsObjecttrue
fileMessageParams.fileVideo File - Should be of type mp4Filetrue
fileMessageParams.fileSizeVideo File Size. When the value not given, SDK will detect the size of the given FILE. When using the fileUrl SDK won't detect the size.Stringfalse
fileMessageParams.fileNameVideo File Name. When the value not given, SDK will detect the name of the given FILE. When using the fileUrl SDK won't detect the name.Stringfalse
fileMessageParams.durationVideo File Duration. When the value not given, SDK will detect the duration of the given FILE. When using the fileUrl SDK won't detect the duration.Stringfalse
fileMessageParams.thumbImageVideo File Thumb Image. When the value not given, SDK will generate thumb image for the given FILE. When using the fileUrl SDK won't generate the thumb image.Stringfalse
fileMessageParams.captionVideo CaptionStringfalse
replyMessageIdMessage ID of Original MessageStringfalse
mentionedUsersIdsArray of Group Mentioned UsersIdsArray of Stringsfalse

Response Format:#

statusCode: "", // 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
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
fileToken: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
message_type: "", // String - Message Type
nickname: "", // String - nick name
mentionedUsersIds: [] // Array of mentioned users
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Group Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
},

Document Message#

caution

If Document attachment feature is unavailable for your plan, then it will throw 403 exception

await SDK.sendFileMessage({
toJid: GroupJID,
messageType: "file",
fileMessageParams: {
file: FILE, // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
caption: ""
},
replyMessageId: "",
mentionedUsersIds: []
});
ParamDescriptionTypeRequired
toJidJID of the To UserJID Stringtrue
fileMessageParamsFile Message ParamsObjecttrue
fileMessageParams.fileDocument File - Accepted files are pdf, doc, xls, csv, ppt & txtFiletrue
fileMessageParams.fileSizeDocument File Size. When the value not given, SDK will detect the size of the given FILE. When using the fileUrl SDK won't detect the size.Stringfalse
fileMessageParams.fileNameDocument File Name. When the value not given, SDK will detect the name of the given FILE. When using the fileUrl SDK won't detect the name.Stringfalse
fileMessageParams.captionDocument CaptionStringfalse
replyMessageIdMessage ID of Original MessageStringfalse
mentionedUsersIdsArray of Group Mentioned UsersIdsArray of Stringsfalse

Response Format:#

status code: "", // 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
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
fileToken: "", // String - File Url
is_downloaded: "", // Number - Downloaded Status
is_uploading: "", // Number - Uploading Status
local_path: "", // String - Local Path
thumb_image: "", // Base64 - Thumb Image
}
message_type: "", // String - Message Type
nickname: "", // String - nick name
mentionedUsersIds: [] // Array of mentioned users
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Group Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
},

Download Media#

This method is used to get the media file url when we download the media.

await SDK.getMediaURL(`fileToken`, `filekey`);

Request Param#

StatusDescriptionTypeRequired
fileTokenFile UrlStringtrue
filekeyFile key is optional param, which we get from the selected Media message BodyStringfalse

Example Requests#

await SDK.getMediaURL("9178680804311682318992048B1cCBm6F6WIVI38s9r1a.mp4", "AllRgIXOXZAHxAzxxggTTQvapoxpzEfx");

Response Format#

{
"statusCode": "" // Number - status code,
"message": "", // String - Success/Error Message
"data": {
"blobUrl": "", // String - blobUrl
"blob": {
"size" : "", // Number - size
"type" : "" // String
}
}
}

Receive Message#

To receive the incoming message from other users, you need to implement the event messageListener, which will be triggered whenever a new message is received. Once the message is received it automatically send the delivery status to the user if the logged-in user is online.

Send Seen Status#

To send message read status, use the below method.

await SDK.sendSeenStatus(`TO_USER_JID`, `MESSAGE_ID`);

Request Param#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
MESSAGE_IDUnique Message IDStringtrue

Send Typing Status#

You can able to send the typing/gone status to the user so that receipent user can aware of that the user is typing the message.

await SDK.sendTypingStatus(`TO_JID`);

When the user starts typing the message in the input box of the chat window, call the below method to send the composing status, so that they can show a typing message in the header/recent chat.

Once the user stopped/finished typing the message send the gone status as described below, so that they can hide a typing message in the header/recent chat.

await SDK.sendTypingGoneStatus(`TO_JID`);

Method parameter#

StatusDescriptionTypeRequired
TO_JIDJID of the UserJID Stringtrue

Get Media Messages#

To get the media messages for the particular chat, on initial request it fetches three media. Then on the pagination request by passing the last message-id, it fetches 10 next media messages.

Check here for response format

caution

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

Without Pagination

await SDK.getMediaMessages(`TO_USER_JID`);

With Pagination

await SDK.getMediaMessages(`TO_USER_JID`, `LAST_MESSAGE_ID`);

Request Param#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
LAST_MESSAGE_IDLast Message ID of PaginationStringfalse

Response Params#

ArgumentsDescriptionType
statusCodeStatus CodeNumber
messageSuccess/Error MessageString
dataArray of Object datasArray

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: []
});

Request Param#

ParamDescriptionTypeRequired
toJidJID of the To User/GroupJID Stringtrue
messageTextText Message BodyStringtrue
replyMessageIdMessage ID of Original MessageStringtrue
mentionedUsersIdsArray of Group Mentioned UsersIdsArrayfalse

Get Reply Message#

To get the reply message by message id, send a request to the server as described below.

Check here for response format

await SDK.getReplyMessage(`REPLY_MESSAGE_ID`, `CHAT_TYPE`);

Request Params#

StatusDescriptionTypeRequired
REPLY_MESSAGE_IDReply Message IDStringtrue
CHAT_TYPEChat TypeStringfalse

Note: CHAT_TYPE values are "chat"/"groupchat"

Forward Messages#

To forward an message to the single/group chat, we use following methods.

Forward Single/Multiple Messages to Single/Group Chat#

await SDK.forwardMessages(`TO_JID`, `MESSAGE_IDS`, `IS_ASYNC`);

Request Param#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
MESSAGE_IDSArray of To Original Message IdsArraytrue
IS_ASYNCIF Forward has to be in Asynchronous (One by One) - Default trueBooleanfalse

Forward Single/Multiple Messages to Multiple User#

await SDK.forwardMessagesToMultipleUsers(`TO_JIDS`, `MESSAGE_IDS`);

Request Param#

StatusDescriptionTypeRequired
TO_JIDSArray of To User/JID of the To UsersArraytrue
MESSAGE_IDSArray of To Original Message IdsArraytrue
IS_ASYNCIF Forward has to be in Asynchronous (One by One) - Default trueBooleanfalse

Favourite Messages#

The favourite message is a feature that allows users to mark some messages as favourites. So that they can see those important messages in the future without searching for them in chat.

Once you marked messages as favourite, you can get those from SDK to show them on your app's screen.

Add/Remove Favourites#

caution

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

await SDK.updateFavouriteStatus(`TO_JID`, `MESSAGE_ID`, `IS_FAVOURITE`, `MENTIONED_USERS_IDS`);

Request Param#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupStringtrue
MESSAGE_IDUnique Message IDStringtrue
IS_FAVOURITEtrue for adding to favourites, false for removingBooleantrue
MENTIONED_USERS_IDSArray of Group Mentioned UsersIdsArrayfalse

Get All Favourites#

caution

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

await SDK.getAllFavouriteMessages();

Once get all favourites method initiated, an callback method favouriteMessageListener will be triggered and response will be sent.

Remove All Favourites#

caution

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

await SDK.removeAllFavouriteMessages();

Clear Chat Messages#

The clear chat message is a feature that allows users to delete chat messages.

If you want to clear the messages for the entire chat, or multiple chats then you can utilize the below methods.

Clear Chat#

You can clear the messages for any chat by using the below method. The messages will not be deleted from the recipient.

caution

If Clear Chat feature is unavailable for your plan, then it will throw 403 exception

await SDK.clearChat(`TO_JID`, `FAVOURITES`, `LAST_MSG_ID`);

Method Params#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
FAVOURITESWhether to Delete Favourites Messages or notBooleanfalse
LAST_MSG_IDlastMsgId which the message is sendStringfalse

Delete Chat#

You can delete the chat (from recent chat) by using the below method.

caution

If Delete Chat feature is unavailable for your plan, then it will throw 403 exception

await SDK.deleteChat(`TO_JID`, `FAVOURITES`);

Method Params#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
FAVOURITESWhether to Delete Favourites Messages or notBooleanfalse

Clear All Chat#

You can clear all conversation by using the below method.

await SDK.clearAllChat();

Delete Messages#

Delete message is a feature that is found in modern messaging apps that allows the user to delete the message once it is sent. Once you sent the message, you can able to delete the messages by using built-in SDK methods.

Delete All Recent Chats#

To delete all recent chat messages use below method, which deletes all single and group conversation.

await SDK.deleteAllChat();

Delete for Me#

If you want to delete the messages for yourself only then you can use the below method.

caution

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

Note: The messages will not be deleted from the recipient.

await SDK.deleteMessagesForMe(`TO_JID`, `MESSAGE_IDS`);

Delete for Everyone#

If you want to delete the messages for yourself and the receiver then you can use the below method. The messages will also be deleted from the recipient.

caution

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

await SDK.deleteMessagesForEveryone(`TO_JID`, `MESSAGE_IDS`);

Method Params#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
MESSAGE_IDSArray of To Message IdsArraytrue

Mute Chat#

To Mute the chat use below method which disables the notification for the chat when the new messages are received or any action on group chat.

await SDK.updateMuteNotification(`TO_JID`, `IS_MUTED`);
StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
IS_MUTEDtrue for muting the chat, false for removingBooleantrue

Archive Chat#

Archive/Unarchive Chat#

To Archive the single and group chat use below method.

await SDK.updateArchiveChat(`TO_JID`, `IS_ARCHIVED`);

Method Params#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
IS_ARCHIVEDtrue for archive the chat, false for removingBooleantrue

Get All Archived Chat#

Retrieves all archived chats.

await SDK.getAllArchivedChats();

Display Browser Notification#

Display the browser notification by providing the notification object into the showChatNotification method. Notification would display when a user receive a message while user on different screen instead of on webchat application screen.

SDK.showChatNotification(`NOTIFICATION_OBJECT`);
// Exmple
SDK.showChatNotification({
title: `NOTIFICATION_TITLE`, // Title of the notification
body: `NOTIFICATION_BODY`, // Body of the notification
onClick: `CALLBACK_METHOD`, // Callback will be triggered when user click on notification
forceShow: `BOOLEAN`, // Display the notification in all cases set this value as TRUE
});

Response Params#

ArgumentsDescriptionType
statusCodeStatus CodeNumber
messageSuccess/Error MessageString