Skip to main content

getChannelMessages(channelId, skip);

Call this method to fetch the messages in a channel/sub-room.

JavaScript

const messages = await sdk.getChannelMessages(channelId, skip);

Parameters

Parameter NameDescriptionTypeRequired
channelIdThe id of the channel for which you want to fetch the messagesstringyes
skipLatest 18 message are returned, by default. Set the skip to the number of messages you want to skip in the call.IntegerNo

Response

PropertiesDescriptionType
eventIdThe Id of the eventString
messagesArray of Objects with MessagesArray

Messages

PropertiesDescriptionType
_idid of the messagesString
LikesArray of likes of the messageArray
createddate when the message was createdString
user_id and username of the userObject
channelchannel idString
messagethe message itselfString

User

PropertiesDescriptionType
_idid of the userString
usernameusername of the userString

Example

In the example below we are fetching messages from channel 6325e6cdf0357f1c648791a5.

const messages = await sdk.getChannelMessages('6325e6cdf0357f1c648791a5');
console.log("messages:", messages);

Sample Response

This returns a Array of Objects containing the Active Channels.

JSON Sample response getChannelMessages
{
"eventId": "fae72723-c875-4122-822c-9d1b0a0f23f1",
"messages": [
{
"_id": "6325f6c8f0357f1c648791aa",
"likes": [],
"created": "2022-09-17T16:33:12.294Z",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "support"
},
"channel": "6325e6cdf0357f1c648791a5",
"message": "What is happening here",
"__v": 0
},
{
"_id": "6325f6c0f0357f1c648791a9",
"likes": [],
"created": "2022-09-17T16:33:04.687Z",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "support"
},
"channel": "6325e6cdf0357f1c648791a5",
"message": "I am good ",
"__v": 0
},
{
"_id": "6325f6bdf0357f1c648791a8",
"likes": [],
"created": "2022-09-17T16:33:01.339Z",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "support"
},
"channel": "6325e6cdf0357f1c648791a5",
"message": "how are you",
"__v": 0
},
{
"_id": "6325e6dff0357f1c648791a7",
"likes": [],
"created": "2022-09-17T15:25:19.210Z",
"user": {
"_id": "63233015c3aa3508a4c8fc34",
"username": "support"
},
"channel": "6325e6cdf0357f1c648791a5",
"message": "hi",
"__v": 0
}
]
}