View Channel List
1. Get Public Channels
You can view any public channel even if you are not a member.
The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.
const numOfRows = 20;
const resp = await client.getPublicChannels({
limit: numOfRows,
category: 'important_channels', // optional
subcategory: 'important_subcategory', // optional
});
// fetch more channels
if (resp.hasNext) {
const lastChannelId = resp.channels[resp.channels.length - 1].id;
const moreChannelsResp = await client.getPublicChannels({
lastChannelId,
limit: numOfRows,
});
}
// same query but using callback
client.getPublicChannels({}, function(err, resp) {
if (resp.hasNext) {
const lastChannelId = resp.channels[resp.channels.length - 1].id;
}
});
Response
{
"channels": [
{
"id": "channel123",
"name": "MyFirstChannel",
"ownerId": "user123",
"pushNotificationDisabled": false,
"imageUrl": "image url",
"data": {
"someMetaKey1": "someMetaValue1",
"someMetaKey2": "someMetaValue2"
},
"type": "public",
"isFrozen": false,
"memberCount": 1,
"maxMemberCount": 10,
"hideMessagesBeforeJoin": true,
"category": "",
"subcategory": "",
"privateTag": "",
"privateData": "",
"mutedUsers": [],
"members": [
{
"id": "user123",
"username": "john",
"profileImageUrl": "http://cnd.test.com/123.jpg",
"lastReadAt": 1583924400,
"lastSentAt": 1583924400,
"updatedAt": 1583924400,
"createdAt": 1583921400
}
],
"bannedUsers": [
{
"id": "user123",
"username": "john",
"profileImageUrl": "http://cnd.test.com/123.jpg",
"lastReadAt": 1583924400,
"lastSentAt": 1583924400,
"updatedAt": 1583924400,
"createdAt": 1583921400
}
],
"pushNotificationDisabled": false,
"pushNotificationSoundAOS": "",
"pushNotificationSoundIOS": "",
"updatedAt": 1583924400,
"createdAt": 1583921400,
"unreadCount": 1,
"lastReadAt": 1583914400,
"lastMessage": {
"id": "sdf2l5s9j",
"channelId": "channel123",
"userId": "user456",
"username": "myUsername",
"profileImageUrl": "http://cdn.test.com/123.jpg",
"type": "message",
"text": "Hello world",
"data": {
"customField": "customData"
},
"parentMessage": {},
"parentMessageId": "",
"reactions": {"happy": ["user1"]},
"createdAt": 1583921400
}
}
],
"hasNext": false
}
2. Get Joined Channels
View currently joined channels.
The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.
const numOfRows = 20;
const resp = await client.getChannels({
limit: numOfRows,
category: 'important_channels', // optional
subcategory: 'important_subcategory', // optional
isFrozen: false, // optional. filter by isFrozen status
privateTag: 'tag1', // optional. see: https://en.docs.talkplus.io/javascript/channel/member-settings
});
if (resp.hasNext) {
const lastChannelId = resp.channels[resp.channels.length - 1].id;
const moreChannelsResp = await client.getChannels({lastChannelId, limit: numOfRows});
}
// same query but using callback
client.getChannels({}, function(err, resp) {
if (resp.hasNext) {
const lastChannelId = resp.channels[resp.channels.length - 1].id;
}
});
3. Get Hidden Channels
View currently joined channels that have been marked as hidden.
The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.
const numOfRows = 20;
const resp = await client.getHiddenChannels({limit: numOfRows});
if (resp.hasNext) {
const lastChannelId = resp.channels[resp.channels.length - 1].id;
const moreChannelsResp = await client.getHiddenChannels({lastChannelId, limit: numOfRows});
}
// same query but using callback
client.getHiddenChannels({}, function(err, resp) {
if (resp.hasNext) {
const lastChannelId = resp.channels[resp.channels.length - 1].id;
}
});
Response
{
"channels": [
{
"id": "channel123",
"name": "MyFirstChannel",
"ownerId": "user123",
"pushNotificationDisabled": false,
"imageUrl": "image url",
"data": {
"someMetaKey1": "someMetaValue1",
"someMetaKey2": "someMetaValue2"
},
"type": "public",
"isFrozen": false,
"memberCount": 1,
"maxMemberCount": 10,
"hideMessagesBeforeJoin": true,
"category": "",
"subcategory": "",
"privateTag": "",
"privateData": "",
"mutedUsers": [],
"members": [
{
"id": "user123",
"username": "john",
"profileImageUrl": "http://cnd.test.com/123.jpg",
"lastReadAt": 1583924400,
"lastSentAt": 1583924400,
"updatedAt": 1583924400,
"createdAt": 1583921400
}
],
"bannedUsers": [
{
"id": "user123",
"username": "john",
"profileImageUrl": "http://cnd.test.com/123.jpg",
"lastReadAt": 1583924400,
"lastSentAt": 1583924400,
"updatedAt": 1583924400,
"createdAt": 1583921400
}
],
"pushNotificationDisabled": false,
"pushNotificationSoundAOS": "",
"pushNotificationSoundIOS": "",
"updatedAt": 1583924400,
"createdAt": 1583921400,
"unreadCount": 1,
"lastReadAt": 1583914400,
"lastMessage": {
"id": "sdf2l5s9j",
"channelId": "channel123",
"userId": "user456",
"username": "myUsername",
"profileImageUrl": "http://cdn.test.com/123.jpg",
"type": "message",
"text": "Hello world",
"data": {
"customField": "customData"
},
"parentMessage": {},
"parentMessageId": "",
"reactions": {"happy": ["user1"]},
"createdAt": 1583921400
}
}
],
"hasNext": false
}
4. Get Total Unread Message Count
Get the total number of unread messages from all joined channels.
const resp = await client.getUnreadCount();
console.log('unreadCount: ', resp.count);
5. Mark All Channels As Read
Mark as read all unread messages from joined channels.
await client.markAsReadAllChannel();
6. Search Joined Channels
Search joined channels using various filters.
You can filter channels by name, category, subcategory, private tag and joined members.
The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.
const resp = await client.searchChannels({
query: 'some channel name',
members: ['someUserId1', 'someUserId2'], // filter by joined members
category: 'someCategory', // optional
subcategory: 'someCategory', // optional
privateTag: 'myTag',
isFrozen: false, // optional. filter by isFrozen status
lastChannelId: 'someChannelID',
limit: 10,
});
if (resp.hasNext) {
// retrieve next page
}
Response
{
"channels": [
{
"id": "channel123",
"name": "MyFirstChannel",
"ownerId": "user123",
"pushNotificationDisabled": false,
"imageUrl": "image url",
"data": {
"someMetaKey1": "someMetaValue1",
"someMetaKey2": "someMetaValue2"
},
"type": "private",
"isFrozen": false,
"memberCount": 1,
"maxMemberCount": 10,
"hideMessagesBeforeJoin": true,
"category": "",
"subcategory": "",
"privateTag": "",
"privateData": "",
"mutedUsers": [],
"members": [
{
"id": "user123",
"username": "john",
"profileImageUrl": "http://cnd.test.com/123.jpg",
"lastReadAt": 1583924400,
"lastSentAt": 1583924400,
"updatedAt": 1583924400,
"createdAt": 1583921400
}
],
"bannedUsers": [
{
"id": "user123",
"username": "john",
"profileImageUrl": "http://cnd.test.com/123.jpg",
"lastReadAt": 1583924400,
"lastSentAt": 1583924400,
"updatedAt": 1583924400,
"createdAt": 1583921400
}
],
"pushNotificationDisabled": false,
"pushNotificationSoundAOS": "",
"pushNotificationSoundIOS": "",
"updatedAt": 1583924400,
"createdAt": 1583921400,
"unreadCount": 1,
"lastReadAt": 1583914400,
"lastMessage": {
"id": "sdf2l5s9j",
"channelId": "channel123",
"userId": "user456",
"username": "myUsername",
"profileImageUrl": "http://cdn.test.com/123.jpg",
"type": "message",
"text": "Hello world",
"data": {
"customField": "customData"
},
"parentMessage": {},
"parentMessageId": "",
"reactions": {"happy": ["user1"]},
"createdAt": 1583921400
}
}
],
"hasNext": false
}
Last updated