Retrieve Messages

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 Chat Messages#

To fetch all the conversation between you and a single chat user or group, call the below method.

await SDK.getChatMessages(TO_JID);

Example

await SDK.getChatMessages("91XXXXXXXXXX@domain.com");

Request Params#

StatusDescriptionTypeRequired
toJidJID of the To User/GroupStringtrue

Response Format#

{
"statusCode": 200,
"message": "Success",
"userJid": "", // String - Requested User Jid
"data": [
{
"createdAt": "2024-04-02 10:38:02.350",
"chatType": "chat", // String - Chat Type "chat"/"groupchat"
"favouriteBy": "",
"favouriteStatus": 0,
"deleteStatus": 0,
"recallStatus": 0,
"fromUserId": "",
"fromUserJid": "",
"toUserJid": "",
"publisherJid": "sender@domain", // String - Publisher Jid
"publisherId": "sender", // String - Publisher Id
"timestamp": 1712054282350,
"msgId": "878aef37-8e14-4e97-aa19-e5f391179d89",
"msgStatus": 0,
"msgBody": {
"mid": "878aef37-8e14-4e97-aa19-e5f391179d89",
"message": "Hi",
"message_type": "text",
"replyTo": "",
"mentionedUsersIds": "",
"nickName": "",
"notificationContent": "You added wjksd3kwwsz8fbmggtujq9ahu4u2" // For only groupchat and message_type ['notification']
"media": { // For Media Message Only for message message_type ['image', 'video', 'file', 'audio']
"androidHeight": 188, // Number - Android Height -Only For Image/Video
"androidWidth": 250, // Number - Android Width -Only For Image/Video
"caption": "", // String - Media Caption
"duration": 0, // Number - Duration - For Audio/Videos
"fileName": "", // String - File Name
"file_key": "", // String - File Key
"file_size": 543879, // Number - File Size
"file_url": "", // String - File Url
"is_downloaded": 0, // Number - Downloaded Status
"is_uploading": 2, // Number - Uploading Status
"local_path": "", // String - Local Path
"msgId": "", // String - MessageId
"originalHeight": 240, // Number - Original Height -Only For Image/Video
"originalWidth": 320, // Number - Original Width -Only For Image/Video
"thumb_image": "", // Base64 - Thumb Image
"webHeight": 248, // Number - Web Height -Only For Image/Video
"webWidth": 330 // Number - Web Width -Only For Image/Video
}
"contact": { // For Contact Message Only ['contact']
"mid": "fc524a2f-a342-4c94-827d-e89d0a865503",
"name": "",
"phone_number": [""],
"active_status": ["0"]
}
"location": { // For Location Message Only ['location']
"mid": "0554ca74-a5c0-4bcc-8cb3-01055d033337",
"latitude": "13.0122057",
"longitude": "80.2094575"
}
},
}
]
}

Notification types for handle in UI#

if (msgType === 'notification'){
if (message === '1'){ ==> `groupCreated`
//pubJID is the one group created
} else if (message === '2'){ ==> `userAdded`
//pubJID is the one did the action
//toUserJD is new particiapnt of the group
} else if (message === '3'){ ==> `userRemoved`
//pubJID is the one did the action
//toUserJD is removed particiapnt of the group
} else if (message === '4'){ ==> `profileUpdated`
//pubJID is the one did the action
} else if (message === '5'){ ==> `madeAdmin`
//pubJID is the one did the action
//toUserJD is admin particiapnt of the group
} else if (message === '6'){ ==> `userLeft`
//pubJID is the one did the action
}
}

Download Media#

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

await SDK.getMediaURL(`fileToken`);

Request Param#

StatusDescriptionTypeRequired
fileTokenFile UrlStringtrue

Example Requests#

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

Response Format#

{
"data": {
"fileUrl": "",// String - image Url
"token": "" // // String - image Token
},
"message": "",// String - Success/Error Message
"statusCode": "" // Number - status code,
}