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.

MESSAGE_ID - Unique Id for each and every messages. When you given your MESSAGE_ID, SDK will take your message id otherwise SDK will generate it's own MESSAGE_ID

Text Message#

await SDK.sendTextMessage(`TO_USER_JID`, `MESSAGE_BODY`, `MESSAGE_ID`);

Request Param#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
MESSAGE_BODYText Message BodyStringtrue
MESSAGE_IDMessage IdStringfalse

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: {
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: "", // Number - TimeStamp - 16 Character length
},

Image Message#

caution

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

await SDK.sendImageMessage(`TO_USER_JID`, `IMAGE_FILE`, `FILE_OPTIONS`);

Request Params#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
IMAGE_FILEImage File - Should be of type png, jpg, jpeg, svg & gifFiletrue
FILE_OPTIONSFile Option ParamsObjecttrue
FILE_OPTIONS.msgIdMessage IdStringfalse
FILE_OPTIONS.captionImage CaptionStringfalse
FILE_OPTIONS.thumbImageThumbnail Image - Base64Stringfalse
FILE_OPTIONS.webWidthWidth for WebStringfalse
FILE_OPTIONS.webHeightHeight for WebStringfalse
FILE_OPTIONS.androidWidthWidth for AndroidStringfalse
FILE_OPTIONS.androidHeightHeight for AndroidStringfalse
FILE_OPTIONS.thumbRatioAspect ratio for Thumb ImageStringfalse

Note: Here Message Id is sent in the request to use upload cancellation request as described here

Note: Width and Height Params are Used to Display the Image with Original Dimenstions

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: "", // Number - TimeStamp - 16 Character length
},

Audio Message#

caution

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

await SDK.sendAudioMessage(`TO_USER_JID`, `AUDIO_FILE`, `FILE_OPTIONS`);

Request Params#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
AUDIO_FILEImage File - Should be of type mp3, mpeg & wavFiletrue
FILE_OPTIONSFile Option ParamsObjecttrue
FILE_OPTIONS.msgIdMessage IdStringfalse
FILE_OPTIONS.captionAudio CaptionStringfalse
FILE_OPTIONS.durationAudio DurationNumberfalse

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: "", // Number - TimeStamp - 16 Character length
},

Video Message#

caution

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

await SDK.sendVideoMessage(`TO_USER_JID`, `VIDEO_FILE`, `FILE_OPTIONS`);

Request Params#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
VIDEO_FILEImage File - Should be of type mp4Filetrue
FILE_OPTIONSFile Option ParamsObjecttrue
FILE_OPTIONS.msgIdMessage IdStringfalse
FILE_OPTIONS.captionVideo CaptionStringfalse
FILE_OPTIONS.durationVideo DurationNumberfalse
FILE_OPTIONS.thumbImageThumbnail Image - Base64Stringfalse
FILE_OPTIONS.webWidthWidthStringfalse
FILE_OPTIONS.webHeightHeight for WebStringfalse
FILE_OPTIONS.androidWidthWidth for AndroidStringfalse
FILE_OPTIONS.androidHeightHeight for AndroidStringfalse
FILE_OPTIONS.thumbRatioAspect ratio for Thumb ImageStringfalse

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: "", // Number - TimeStamp - 16 Character length
},

Document Message#

caution

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

await SDK.sendDocumentMessage(`TO_USER_JID`, `DOCUMENT_FILE`, `FILE_OPTIONS`);

Request Params#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
DOCUMENT_FILEDocument File - Accepted files are pdf, doc, xls, csv, ppt & txtFiletrue
FILE_OPTIONSFile Option ParamsObjecttrue
FILE_OPTIONS.msgIdMessage IdStringfalse
FILE_OPTIONS.captionDocument CaptionStringfalse

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: "", // Number - TimeStamp - 16 Character length
},

Media Message Data#

Send Media message as a meta data, here media will be uploaded externally (client side) and media information will be sent.

await SDK.sendMediaMessageData(`TO_USER_JID`, `MSG_TYPE`, `FILE_OPTIONS`);

Request Params#

StatusDescriptionTypeRequired
TO_USER_JIDJID of the To UserJID Stringtrue
MSG_TYPEMessage Type - Accepted types are image, video, audio & fileFiletrue
FILE_OPTIONSFile Option ParamsObjecttrue
FILE_OPTIONS.fileNameFile NameStringtrue
FILE_OPTIONS.fileURLFile UrlStringtrue
FILE_OPTIONS.fileSizeFile SizeStringtrue
FILE_OPTIONS.durationMedia Duration - "mm:ss"Stringtrue if MSG_TYPE is "audio"/"video"
FILE_OPTIONS.thumbImgThumbnail Image - Base64Stringtrue if MSG_TYPE is "video"
FILE_OPTIONS.captionMedia CaptionStringfalse

Example Requests#

const fileOptions = {
fileName: "fileName.png",
fileSize: 1000,
fileURL: "https://imagepath.com",
};
await SDK.sendMediaMessageData("toUser@domain.com", "image", fileOptions);
const fileOptions = {
fileName: "fileName.png",
fileSize: 1000,
fileURL: "https://imagepath.com",
duration: "02:22",
thumbImg: "base64",
};
await SDK.sendMediaMessageData("toUser@domain.com", "video", fileOptions);

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: "", // Number - TimeStamp - 16 Character length
},

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(`TO_JID`, `MESSAGE_BODY`, `MESSAGE_ID`, `REPLY_TO`);

Request Param#

StatusDescriptionTypeRequired
TO_JIDJID of the To User/GroupJID Stringtrue
MESSAGE_BODYText Message BodyStringtrue
MESSAGE_IDUnique Message IDStringtrue
REPLY_TOMessage ID of Original MessageStringtrue

Note: MESSAGE_ID can be passed as empty/null

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/Group JIDsArraytrue
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(`MESSAGE_ID`, `IS_FAVOURITE`);

Request Param#

StatusDescriptionTypeRequired
MESSAGE_IDUnique Message IDStringtrue
IS_FAVOURITEtrue for adding to favourites, false for removingBooleantrue

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`);

Method Params#

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

Delete Chat#

If a user selects the option to delete a chat, all messages, files, and other content within that chat are permanently removed from the user's account and cannot be retrieved.

The purpose of a delete chat function is to allow users to manage their conversations and maintain privacy by removing sensitive or unwanted content from their messaging history.

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