View Channel List
1. Get Public Channels
You can view any public channel even if you are not a member.
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
}
],
"bots": [],
"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.
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
hasUnread: true, // optional. only true is supported. when true, shows only unread channels.
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.
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
}
],
"bots": [],
"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.
// get total unread count
const resp = await client.getUnreadCount();
console.log('unreadCount: ', resp.count);
// filter unread message count by channel category, subcategory and privateTag.
// this feature is available starting from v0.5.6.
const filteredResp = await client.getUnreadCount({
category: 'someCategory', // optional
subcategory: 'someSubcategory', // optional
privateTag: 'some personal tag', // optional
});
console.log('filtered unreadCount: ', filteredResp.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.
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
hasUnread: true, // optional. only true is supported. when true, shows only unread channels.
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
}
],
"bots": [],
"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