Chat history

To retreive the user's all chats in a conversation you can use the below API.

info

{api-base-url} can be obtained from the MirrorFly console.

HTTP request#

curl -X GET "https://{api-base-url}/api/v1/chat/history?chatType=groupchat&participant=efdc5953-bbd5-482e-ad8d-f91bdc1df70f&page=1&size=10&messageId=0e736ecc-35ec-4a46-b57f-0c6ceeacd2a3&direction=forward&topicId=xxxx"
-H "accept: */*"
-H "Authorization: :AuthToken"

Request Params#

ParamDataTypeRequiredDescription
chatTypeStringYesChat type. Possible values are singlechat, groupchat
participantStringYesParticipant userid or groupid of chat if chatType is groupchat
pageNumberNoPage number to get the particular page data default value is 1
sizeNumberNoNumber of chats per page default value is 10
messageIdStringNoMessage id of the message to get paginated data (includes given messageId)
directionStringNoDirection of paginated data if messageId provided. Possible values are forward, backward default value is forward
topicIdStringNoTopicId to filter the records

Note : If it is a media message, use the fileUrl from the media object to download the media by using this Download Media API. Topics can be created from here Create Topic.

Responses#

If successful, this action returns chats list in a conversation, in the response body.

{
"status": 200,
"data": {
"chatList": [
{
"fromUser": "99xxxxxx11", // String - Sender userid
"fromUserName": "samplename", // String - Sender nickname
"fromUserImage": "sampleimage", // String - Sender image
"fromUserThumbImage": "samplethumbimage", // String - Sender thumbImage
"toUser": "99xxxxxx22", // String - Receiver userid
"toUserName": "sampleusernmae", // String - Receiver nickname
"toUserImage": "receivedimage", // String - Receiver image
"toUserThumbImage": "receivedthumbimage", // String - Receiver thumbImage
"messageType": "samplemessagetype", // String - Message type
"messageId": "xxxxxx", // String - Unique id of this message
"message": "samplemessage", // String - Actual message text
"replyTo": "samplemessageId", // String - Message Id, if its a replied message
"deliveryStatus": 0, // Number - Message delivery status code
"recallStatus": 0, // Number - Message recall status
"starredStatus": 0, // Number - Message starred status
"deletedStatus": 0, // Number - Message delete status
"sentTime": "dd/mm/yyyy hh:mm:ss", // String - Message sent time
"epochTimestamp": 0, // Number - sentTime as epoch timestamp
"fileId": "", // String - Unique fileid, if its non-text message
"mimeType": "", // String - mime type, if its non-text message
"deliveryAndReadInfo": [
{
"delivered": [ // String - Message delivery details
{
"userid": "99xxxxxx22", // String - Receiver userid
"username": "sampleusernmae", // String - Receiver nickname
"image": "receivedimage", // String - Receiver image
"thumbImage": "receivedthumbimage", // String - Receiver thumbImage
"timestamp": "dd/mm/yyyy hh:mm:ss", // String - Message delivery time
"epochTimestamp": 0 // Number - epoch timestamp
}
],
"read": [ // String - Message read details
{
"userid": "99xxxxxx22", // String - Receiver userid
"username": "sampleusernmae", // String - Receiver nickname
"image": "receivedimage", // String - Receiver image
"thumbImage": "receivedthumbimage", // String - Receiver thumbImage
"timestamp": "dd/mm/yyyy hh:mm:ss", // String - Message read time
"epochTimestamp": 0 // Number - epoch timestamp
}
]
}
],
"messageNotification": 0, // Number - Notification code, if it is notification
"media":{
"androidHeight": 0, // Number - android height
"androidWidth": 0, // Number - android width
"audioType": "", // String - audio file upload or recording
"caption": "", // String - caption for uploaded video
"duration": 0, // Number - duration of audio or video
"fileKey": "", // String - key to encrypt/decrypt for uploaded file
"fileName": "", // String - name of the uploaded file
"fileSize": 0, // Number - uploaded file size
"fileUrl": "", // String - token of the uploaded file to cloud
"isDownloaded": 0,// Number - isDownloaded
"isUploading": 0,// Number - isUploading
"localPath": "",// String - localPath
"msgId": "", // String - Unique id of this message
"originalHeight": 0, // Number - original height
"originalWidth": 0, // Number - original width
"thumbImage": "",// String - uploaded image/video thumb image
"webHeight": 0, // Number - web height
"webWidth": 0, // Number - web height
"isLargeFile": false // Boolean - large file or not
},
"location": {
"latitude": "",// String - location latitude
"longitude": "",// String - location longitude
"mid": "",// String - mid
"locationResolvedKey": ""// String - locationResolvedKey
},
"contact": {
"contactResolvedKey": "",// String - contactResolvedKey
"mid": "",// String - mid
"name": "samplename",// String - contact name
"phoneNumber": [
""// String - contact number
]
},
"jid": "99xxxxxx11", // String - Jid of the User
"mentionedUsersIds": [
"99xxxxxx00" // String - mentioned users, applicable to group chat only
],
"id": 0, //Number - unique id for this record
"metaData": {
// metadata key/value if any set
},
"topicId": "xxxxxxx" // String - topicId
}
],
"totalPages": 1, // Number - Total pages based on the size
"totalRecords": 1, // Number - Total chats for the logged-in user (count may vary if searched with messageId)
"totalCount": 1 // Number - Total chats for the logged-in user
},
"message": "Data retrieved successfully"
}

Error#

In the case of an error, an error object like below is returned.

When the token passed in Headers is expired

{
"status": 401,
"message": "Token Expired"
}

In the case of a Bad Request, an error message is returned

{
"status": 400,
"message": "Error Message"
}