Send a 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: [],
topicId: "",
metaData: {}
});
ParamDescriptionTypeRequired
toJidJID of the To UserJID Stringtrue
messageTextText Message BodyStringtrue
mentionedUsersIdsArray of Group Mentioned UsersIdsArray of Stringsfalse
topicIdTopic Id for the MessageStringfalse
metaDataMetaData for the MessageObjectfalse

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
fromUserId: "", // String - From User Id
fromUserJid: "", // String - From User Jid
metaData: {}, //Object - Meta data for the message
msgBody: {
mentionedUsersIds: [] // Array of mentioned users
message: "", // String - Message Body
message_type: "", // String - Message Type
nickname: "", // String - nick name
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
toUserId: "", // String - toUser Id
toUserJid: "", // String - toUser Jid
topicId: "", //String - Topic id for the message
},

Image Message#

caution

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

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: [],
topicId: "",
metaData: {}
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);
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
topicIdTopic Id for the MessageStringfalse
metaDataMetaData for the MessageObjectfalse
onPendingPending call backfunctiontrue
onSuccessSend Message success call backfunctiontrue
onErrorSend Message error call backfunctiontrue

onSuccess:#

{
chatType: "", // String - Chat Type - "chat"
createdAt: "", // String - Message Created Time
deleteStatus: "", // Number - Delete Status
favouriteBy: "", // String - Favourited By - User
favouriteStatus: "", //Number - Favourite status
fromUserId: "", // String - From User Id
fromUserJid: "", // String - From User Jid
metaData: {}, //Object - Meta data for the message
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
}
mentionedUsersIds: [] // Array of mentioned users
message_type: "", // String - Message Type
nickname: "", // String - nick name
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
toUserId: "", // String - toUser Id
toUserJid: "", // String - toUser Jid
topicId: "", //String - Topic id for the message
},
caution

SDK.sendFileMessage() method was deprecated and will be removed in the future release. migrate to SDK.sendMediaFileMessage() method to send Image files.

Audio Message#

caution

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

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: [],
topicId: "",
metaData: {}
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);
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
topicIdTopic Id for the MessageStringfalse
metaDataMetaData for the MessageObjectfalse
onPendingPending call backfunctiontrue
onSuccessSend Message success call backfunctiontrue
onErrorSend Message error call backfunctiontrue

onSuccess:#

{
chatType: "", // String - Chat Type - "chat"
createdAt: "", // String - Message Created Time
deleteStatus: "", // Number - Delete Status
favouriteBy: "", // String - Favourited By - User
favouriteStatus: "", //Number - Favourite status
fromUserId: "", // String - From User Id
fromUserJid: "", // String - From User Jid
metaData: {}, //Object - Meta data for the message
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
}
mentionedUsersIds: [] // Array of mentioned users
message_type: "", // String - Message Type
nickname: "", // String - nick name
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
toUserId: "", // String - toUser Id
toUserJid: "", // String - toUser Jid
topicId: "", //String - Topic id for the message
},
caution

SDK.sendFileMessage() method was deprecated and will be removed in the future release. migrate to SDK.sendMediaFileMessage() method to send Audio files.

Video Message#

caution

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

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: [],
topicId: "",
metaData: {}
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);
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
topicIdTopic Id for the MessageStringfalse
metaDataMetaData for the MessageObjectfalse
onPendingPending call backfunctiontrue
onSuccessSend Message success call backfunctiontrue
onErrorSend Message error call backfunctiontrue

onSuccess:#

{
chatType: "", // String - Chat Type - "chat"
createdAt: "", // String - Message Created Time
deleteStatus: "", // Number - Delete Status
favouriteBy: "", // String - Favourited By - User
favouriteStatus: "", //Number - Favourite status
fromUserId: "", // String - From User Id
fromUserJid: "", // String - From User Jid
metaData: {}, //Object - Meta data for the message
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
}
mentionedUsersIds: [] // Array of mentioned users
message_type: "", // String - Message Type
nickname: "", // String - nick name
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
toUserId: "", // String - toUser Id
toUserJid: "", // String - toUser Jid
topicId: "", //String - Topic id for the message
},
caution

SDK.sendFileMessage() method was deprecated and will be removed in the future release. migrate to SDK.sendMediaFileMessage() method to send Video files.

Document Message#

caution

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

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: [],
topicId: "",
metaData: {}
},
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);
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
topicIdTopic Id for the MessageStringfalse
metaDataMetaData for the MessageObjectfalse
onPendingPending call backfunctiontrue
onSuccessSend Message success call backfunctiontrue
onErrorSend Message error call backfunctiontrue

onSuccess:#

{
chatType: "", // String - Chat Type - "chat"
createdAt: "", // String - Message Created Time
deleteStatus: "", // Number - Delete Status
favouriteBy: "", // String - Favourited By - User
favouriteStatus: "", //Number - Favourite status
fromUserId: "", // String - From User Id
fromUserJid: "", // String - From User Jid
metaData: {}, //Object - Meta data for the message
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
}
mentionedUsersIds: [] // Array of mentioned users
message_type: "", // String - Message Type
nickname: "", // String - nick name
},
msgId: "", // String - Unique Message Id
msgType: "", // String - Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
toUserId: "", // String - toUser Id
toUserJid: "", // String - toUser Jid
topicId: "", //String - Topic id for the message
},
caution

SDK.sendFileMessage() method was deprecated and will be removed in the future release. migrate to SDK.sendMediaFileMessage() method to send Document files.

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
fromUserId: "", // String - From User Id
fromUserJid: "", // String - From User Jid
metaData: {}, //Object - Meta data for the message
msgBody: {
meet: {
        link: "ehl-niyc-wcc" // String - Link
        scheduledDateTime: 1695202750020, // Number - Timestamp - Milliseconds
      title: "", // String - Title
      }
      mentionedUsersIds: [], // Array of mentioned users
    message_type: "meet", // String - Message Type
      nickName: "", // String - nick name
    }
msgId: "", // String - Unique Message Id
msgType: "", // String - Message Type
publisherId: "", // String - user Id
timestamp: 1681185232000, // Number - TimeStamp - Milliseconds
toUserId: "", // String - toUser Jid
toUserJid: "", // String - toUser Jid
topicId: "", //String - Topic id for the message
},

Download Media#

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

await SDK.downloadMedia(msgId,
onPending((msgId) => {
// ...
}),
.onSuccess((response) => {
// ...
}),
.onError((error) => {
// ...
})
);

Request Param#

StatusDescriptionTypeRequired
msgIdmsgId for the download messageStringtrue
onPendingPending call backfunctiontrue
onSuccessDownload Message success call backfunctiontrue
onErrorDownload Message error call backfunctiontrue

onSuccess:#

{
msgId: "" , // String
blobUrl: "", // String - blobUrl
blob: {
"size" : "", // Number - size
"type" : "" // String
}
}

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: [],
topicId: "",
metaData: {}
});

Request Param#

ParamDescriptionTypeRequired
toJidJID of the To User/GroupJID Stringtrue
messageTextText Message BodyStringtrue
replyMessageIdMessage ID of Original MessageStringtrue
mentionedUsersIdsArray of Group Mentioned UsersIdsArrayfalse
topicIdTopic Id for the MessageStringfalse
metaDataMetaData for the MessageObjectfalse