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 Name | Description | Type | Required |
---|---|---|---|
channelId | The id of the channel for which you want to fetch the messages | string | yes |
skip | Latest 18 message are returned, by default. Set the skip to the number of messages you want to skip in the call. | Integer | No |
Response
Properties | Description | Type |
---|---|---|
eventId | The Id of the event | String |
messages | Array of Objects with Messages | Array |
Messages
Properties | Description | Type |
---|---|---|
_id | id of the messages | String |
Likes | Array of likes of the message | Array |
created | date when the message was created | String |
user | _id and username of the user | Object |
channel | channel id | String |
message | the message itself | String |
User
Properties | Description | Type |
---|---|---|
_id | id of the user | String |
username | username of the user | String |
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
}
]
}