Available in Classic and VPC
Channel
In Ncloud Chat, the channel is a virtual space where users can communicate in a group. Through channels, you can share information suitable for a specific subject or purpose, enhance teamwork, and systematize communication. Channel is a useful tool to increase business efficiency and to centralize and manage communication in a specific group. The following describes the channel functions of Ncloud Chat.
Main functions of channel
- Group communication: you can create a channel and communicate with members of a specific group. It is suitable for diverse forms of groups, such as project teams, divisions, or clubs.
- Message and file sharing: you can easily share various forms of files, such as text messages, images, videos, and documents in the channel.
- Real-time update: all activities in the channel are updated in real time so that every participant can obtain the latest information.
- Admin control: the creator or admin of the channel has the right to change channel settings or add and remove users.
- Calls and video conferencing function: some channels provide voice calls or video conferencing for effective communication between members.
- Notification settings: you can set notifications by channel so as not to miss important messages.
- Search features: you can easily search dialogs or files in the channel, so you can quickly find the information you need.
Manage channel
- Create channel: you can create a new channel suitable for your purpose and set information, such as channel name, descriptions, and members.
- Channel invitation: the admin of the channel can invite other users to the channel. The user who is invited can accept or decline the invitation.
- Manage members: the admin can set the permissions of the channel members or remove members from the channel.
Security
- Data security: all data in the channel is encrypted and transmitted, and is stored safely in the server.
- Personal information protection: the information shared in the channel can be accessed only among channel members and is protected against leak to the outside.
When you use the channel function of Ncloud Chat, you can have easy communication within the organization and among individuals, and manage information effectively. These features are very useful when you manage large-scale organizations or various projects.
Create channel
All conversations require you to create channels, and you need to participate in the channel to chat normally. The following guides you on how to create and subscribe to channels:
Javascript/Typescript
await nc.createChannel({
type: [TYPE],
name: [NAME],
customField: [CUSTOM_FIELD]
});
| ID |
Type |
Description |
Required |
| NAME |
string |
Channel name |
O |
| TYPE |
string |
Channel type (PUBLIC or PRIVATE) |
O |
| CUSTOM_FIELD |
string |
You can use it in various ways with user-defined field and JSON String. |
X |
Android (Kotlin)
NChat.createChannel([TYPE], [NAME], [CUSTOM_FIELD]) { result, e ->
if (e != null) {
// Failed
} else {
// Succeeded
}
}
| ID |
Type |
Description |
Required |
| NAME |
String |
Channel name |
O |
| TYPE |
String |
Channel type (PUBLIC or PRIVATE) |
O |
| CUSTOM_FIELD |
String |
You can use it in various ways with user-defined field and JSON String. |
X |
iOS (Swift)
NChat.createChannel(NCChannel(
name: [NAME],
type: [.publicChannel or .privateChannel]),
customField: [CUSTOM_FIELD])) { result in
switch(result)
{
case .success(let status) :
// Succeeded
break
case .failure(let error) :
// Error
break
}
}
| ID |
Type |
Description |
Required |
| NAME |
String |
Channel name |
O |
| TYPE |
String |
Channel type (PUBLIC or PRIVATE) |
O |
| CUSTOM_FIELD |
String |
You can use it in various ways with user-defined field and JSON String. |
X |
iOS (Objective-C)
NSDictionary *channelDict = @{
@"name": [NAME],
@"type": [TYPE],
@"customField": [CUSTOM_FIELD]
};
[NChatBridge.shared createChannelWithChannel:channelDict :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
| ID |
Type |
Description |
Required |
| NAME |
NSString* |
Channel name |
O |
| TYPE |
NSString* |
Channel type (PUBLIC or PRIVATE) |
O |
| CUSTOM_FIELD |
NSString* |
You can use it in various ways with user-defined field and JSON String. |
X |
Unity
await nc.createChannel(new NBaseSDK.Channel
{
name = [NAME],
type = [TYPE], // PUBLIC or PRIVATE
customField = [CUSTOM_FIELD]
});
| ID |
Type |
Description |
Required |
| NAME |
string |
Channel name |
O |
| TYPE |
string |
Channel type (PUBLIC or PRIVATE) |
O |
| UniqueID |
string |
Unique ID |
X |
| push |
boolean |
Push notification status |
X |
| linkUrl |
string |
Link status |
X |
| imageUrl |
string |
Link status |
X |
| integrationId |
string |
Integrated functions (translation, voice, etc.) |
X |
| disabled |
string |
Channel use status |
X |
| members |
array |
ID allowed to join if PRIVATE |
X |
| CustomField |
string |
You can use it in various ways with user-defined field and JSON String. |
X |
Note
- For security, create a channel through the server instead of creating a channel from the client's side.
Subscribe to channel
Subscribe to the desired channel (join the room). Once you join a channel, you will join automatically when you access it again until you unsubscribe from it.
Javascript/Typescript
await nc.subscribe([CHANNEL_ID], {"language":"en"});
| ID |
Type |
Description |
Required |
| CHANNEL_ID |
string |
Channel ID |
O |
| language |
string |
Language code |
X |
Android (Kotlin)
val options: Map<String, Any?> = mapOf(
"language" to "en",
)
NChat.subscribe([CHANNEL_ID], options) { data, e ->
if (e != null) {
//Error
} else {
// Succeeded
}
}
| ID |
Type |
Description |
Required |
| CHANNEL_ID |
String |
Channel ID |
O |
| language |
String |
Language code |
X |
iOS (Swift)
let options: [String: Any] = ["language": "en"]
NChat.subscribe(channelId: [CHANNEL_ID], options: [OPTION]) {
result in
switch(result)
{
case .success(let subscription) :
// Succeeded
break;
case .failure(let error) :
// Error
break;
}
}
iOS (Objective-C)
[NChatBridge.shared subscribeWithChannelId:[CHANNEL_ID] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
Hashtable option = new Hashtable
{
{ "language", "en" } // You can add more options besides the ones required for automatic translation.
};
await nc.subscribe([CHANNEL_ID], option);
Unsubscribe from channel
Unsubscribe from the channel. You will no longer receive messages from this channel.
Javascript/Typescript
await nc.unsubscribe([CHANNEL_ID]);
Android (Kotlin)
NChat.unsubscribe([CHANNEL_ID]) { data, e ->
if (e != null) {
//Error
} else {
// Succeeded
}
}
iOS (Swift)
NChat.unsubscribe(channelId: [CHANNEL_ID]) {
result in
switch(result)
{
case .success(let subscription) :
// Succeeded
break;
case .failure(let error) :
// Error
break;
}
}
iOS (Objective-C)
[NChatBridge.shared unsubscribeWithChannelId:[CHANNEL_ID] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
await nc.unsubscribe([CHANNEL_ID]);
Participant list
You can import the participant list (for a specific channel).
Javascript/Typescript
const filter = { channel_id: [CHANNEL_ID] };
const sort = { created_at: -1 };
const option = { offset: 0, per_page: 100 };
const subscriptions = await nc.getSubscriptions(filter, sort, option);
Android (Kotlin)
// Filter settings
val filter: Map<String, Any?> = mapOf(
"channel_id" to "[CHANNEL_ID]"
)
// Sorting settings
val sort: Map<String, Any?> = mapOf(
"created_at" to -1
)
// Option settings
val options: Map<String, Any?> = mapOf(
"per_page" to 10,
"offset" to 0
)
NChat.getSubscriptions(filter, sort, options) { subscriptions, e ->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS (Swift)
let filter: [String: Any] = ["channel_id": [CHANNEL_ID]]
let option: [String: Any] = ["per_page": 10, "offset": 0]
let sort: [String: Any] = ["created_at": "-1"]
NChat.getSubscriptions(filter: filter, option: option, sort: sort) { result in
switch(result)
{
case .success(let subscriptions) :
// Succeeded
break;
case .failure(let error) :
// Error
break;
}
}
iOS (Objective-C)
[NChatBridge.shared getSubscriptionsWithCompletion:^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
Hashtable filter = new Hashtable
{
{ "channel_id", channelId }
};
Hashtable sort = new Hashtable
{
{ "created_at", -1 }
};
Hashtable option = new Hashtable
{
{ "offset", 0 },
{ "per_page", 10 }
};
var subscriptions = await nc.getSubscriptions(filter, sort, option);
foreach (var subscription in subscriptions.edges)
{
string id = subscription.node.id.ToString();
Console.WriteLine("[CloudChatSample] id={0}", id);
}
| ID |
Type |
Description |
| filter |
object |
Search is available for all fields of a query through filtering |
| sort |
object |
Define a filter for the fields you want to sort |
| option |
object |
See the following when there are options |
| ID |
Type |
Description |
| project_id |
String |
Project ID |
| channel_id |
String |
Channel ID |
| user_id |
String |
User ID |
| language |
String |
Languages |
| uniquekey |
String |
Unique key |
| online |
Boolean |
Online status |
| push |
Boolean |
Push notification usage status |
| created_at |
String |
Creation date |
| updated_at |
String |
Renewal date |
| ID |
Type |
Description |
| created_at |
number |
Creation date ("1" for ascending, "-1" for descending order) |
| ID |
Type |
Description |
| offset |
number |
Start offset |
| per_page |
number |
Number of items returned (up to 100) |
Advanced
To import only a list of online users accessing a specific channel, add "online" as "true" to the filter.
Unity
Hashtable filter = new Hashtable
{
{ "channel_id", [CHANNEL_ID] },
{ "online" , true}
};
Hashtable sort = new Hashtable
{
{ "created_at", -1 }
};
Hashtable option = new Hashtable
{
{ "offset", 0 },
{ "per_page", 10 }
};
var subscriptions = await nc.getSubscriptions(filter, sort, option);
Subscribe to channel
| ID |
Type |
Description |
| id |
string |
Unique ID |
| channel_id |
string |
Channel ID |
| user_id |
string |
Unique ID of the user |
| created_at |
string |
Creation date |
| online |
boolean |
Online status |
| push |
boolean |
Whether the user allows push notifications |
| language |
string |
Language |
| channel |
string |
Channel information |
| mark.user_id |
string |
User who sent the last message |
| mark.message_id |
string |
Last message ID |
| mark.sort_id |
string |
Last message sorting ID |
| mark.unread |
string |
Number of unread messages since the last message |
Channel information
| ID |
Type |
Description |
| totalCount |
Int |
Number of all channels |
| channels |
Channel |
Channel data list |
| ID |
Type |
Description |
| id |
string |
Channel ID (unique) |
| project_id |
string |
Project ID |
| name |
string |
Channel name |
| user_id |
string |
User ID (that created the channel) |
| user |
User |
User information (that created the channel) |
| unique_id |
string |
Channel ID that can be set by the developer (unique) |
| type |
string |
Channel type (PUBLIC or PRIVATE) |
| members |
string |
Participating user list |
| push |
boolean |
Push message support status |
| disabled |
boolean |
Channel status |
| customField |
string |
User-defined data |
| subscribed |
boolean |
Channel subscription status for a calling user |
| unread |
int |
Number of unread messages |
| created_at |
string |
Creation date |
| updated_at |
string |
Renewal date |
| last_message |
Message |
Last message information |
Import channel data
Use the following code to import the channel data of a project in the form of a list:
Javascript/Typescript
const filter = { state: true };
const sort = { created_at: -1 };
const option = { offset: 0, per_page: 100 };
const channels = await nc.getChannels(filter, sort, option);
Android (Kotlin)
val filter: Map<String, Any?> = mapOf(
"state" to true
)
val sort: Map<String, Any?> = mapOf(
"created_at" to -1
)
val options: Map<String, Any?> = mapOf(
"per_page" to 10,
"offset" to 0
)
NChat.getChannels(filter, sort, options) { channelData, e ->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS (Swift)
let filter: [String: Any] = ["state": true]
let option: [String: Any] = ["per_page": 10, "offset": 0]
let sort: [String: Any] = ["created_at": "-1"]
NChat.getChannels(filter: filter, option: option, sort: sort) { result in
switch(result)
{
case .success(let channelData) :
// Succeeded
break;
case .failure(let error) :
// Failed
break;
}
}
iOS (Objective-C)
[NChatBridge.shared getChannelsWithFilter:@{} option:@{} sort:@{} :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
Hashtable filter = new Hashtable
{
{ "state", true }
};
Hashtable sort = new Hashtable
{
{ "created_at", -1 }
};
Hashtable option = new Hashtable
{
{ "offset", 0 },
{ "per_page", 10 }
};
var channels = await nc.getChannels(filter,sort,option);
foreach (var channel in channels.edges)
{
string id = channel.node.id.ToString();
Console.WriteLine("[CloudChatSample] id={0}", id);
}
| ID |
Type |
Description |
Required |
| filter |
object |
Search is available for all fields of a query through filtering |
O |
| sort |
object |
Define a filter for the fields you want to sort |
X |
| option |
object |
See the following when there are options |
X |
| ID |
Type |
Description |
| id |
String |
Channel ID |
| project_id |
String |
Project ID |
| name |
String |
Channel name |
| user_id |
String |
User ID |
| unique_id |
String |
Unique ID |
| type |
String |
Channel type |
| push |
Boolean |
Push notification usage status |
| disabled |
Boolean |
Deactivation status |
| customField |
String |
User-defined field |
| link_url |
String |
Link URL |
| image_url |
String |
Image URL |
| subscribed |
Boolean |
Subscription status |
| unread |
Int |
Number of unread messages |
| created_at |
String |
Creation date |
| updated_at |
String |
Update date |
| ID |
Type |
Description |
| created_at |
number |
Creation date ("1" for ascending, "-1" for descending order) |
| ID |
Type |
Description |
| offset |
number |
Start offset |
| per_page |
number |
Number of items returned (up to 100) |
Individual channel
- You can get information about individual channels.
Javascript/Typescript
const channel = await nc.getChannel(channelId);
Android (Kotlin)
NChat.getChannel([CHANNEL_ID]) { channel, e ->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS (Swift)
NChat.getChannel(channelId: [CHANNEL_ID]) { result in
switch(result)
{
case .success(let channel) :
// Succeeded
break;
case .failure(let error) :
// Failed
break;
}
}
iOS (Objective-C)
[NChatBridge.shared getChannelWithChannelId:[CHANNEL_ID] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
Channel channel = await nc.getChannel(id);
Invite user to channel
Invite a user to participate when the channel is private.
Javascript/Typescript
const channel = await nc.addUsers(channelId, [userIds], {
message: "user joins",
});
Android (Kotlin)
val userIds = listOf("user1", "user2")
NChat.addUsers([CHANNEL_ID],userIds) { channel, e->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS (Swift)
let userIds = ["userId1", "userId2", "userId3"] // Example user ID array
NChat.addUsers(channelId: [CHANNEL_ID], userIds: userIds) { result in
switch(result)
{
case .success(let channel) :
// Succeeded
break;
case .failure(let error) :
// Failed
break;
}
}
iOS (Objective-C)
[NChatBridge.shared addUsersWithChannelId:[CHANNEL_ID] userIds:@[[USER_ID]] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
await nc.addUsers(newChannelId, new string[] { "ID", "ID" });
Delete user from channel
Delete a user who is a participant when the channel is private.
Javascript/Typescript
const channel = await nc.removeUsers(channelId, [user_id], {
message: "user removed",
});
Android (Kotlin)
val userIds = listOf("user1", "user2")
NChat.removeUsers([CHANNEL_ID],userIds) { channel, e->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS (Swift)
let userIds = ["userId1", "userId2", "userId3"] // Example user ID array
NChat.removeUsers(channelId: [CHANNEL_ID], userIds: userIds) { result in
switch(result)
{
case .success(let channel) :
// Succeeded
break;
case .failure(let error) :
// Failed
break;
}
}
iOS (Objective-C)
[NChatBridge.shared removeUsersWithChannelId:[CHANNEL_ID] userIds:@[[USER_ID]] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
await nc.removeUsers(channelId, new string[] { "ID", "ID" });
Block user from channel
Block a user within a channel. It can only be used by users who have permission to create a channel, or the admin with full access.
Javascript/Typescript
const subscribe = await nc.banUser(channelId, id, {
timeout: 60 * 60,
reason: "Blocked due to abusive language.",
});
Android (Kotlin)
val options: Map<String, Any?> = mapOf(
"timeout" to [end time (seconds)],
"reason" to "[reason for blocking]"
)
NChat.banUser([CHANNEL_ID], userId, options) { channel, e->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS (Swift)
let option: [String: Any] = ["timeout": [end time (seconds)], "reason": "[reason for blocking]"]
NChat.banUser(channelId: [CHANNEL_ID], userId: userId, options: options) { result in
switch(result)
{
case .success(let channel) :
// Succeeded
break;
case .failure(let error) :
// Failed
break;
}
}
iOS (Objective-C)
[NChatBridge.shared banUserWithChannelId:[CHANNEL_ID] userId:[USER_ID] options:@{@"timeout": [End time(seconds)], @"reason": [Reason for blocking]} :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
Hashtable option = new Hashtable
{
{ "timeout", [endtime (seconds)] },
{ "reason", [reason for blocking] }
};
await nc.banUser(channelId, userId, options);
| ID |
Type |
Description |
| timeout |
string |
Block time (seconds) |
| reason |
string |
Reason for blocking |
Unblock user within channel
Unblock the blocked user within the channel. It can only be used by users who have permission to create a channel, or the admin with full access.
Javascript/Typescript
const subscribe = await nc.unbanUser(channelId, id);
Android (Kotlin)
NChat.unbanUser([CHANNEL_ID],userId) { channel, e->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS (Swift)
NChat.unbanUser(channelId: [CHANNEL_ID],userId: userId) { result in
switch(result)
{
case .success(let channel) :
// Succeeded
break;
case .failure(let error) :
// Failed
break;
}
}
iOS (Objective-C)
[NChatBridge.shared unbanUserWithChannelId:[CHANNEL_ID] userId:userId :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
await nc.unbanUser(channelId, userId);
Delete channel
Delete the channel (you can delete 1 channel or multiple channels).
Javascript/Typescript
const channel = await nc.deleteChannel(channelId);
Android(Kotlin)
NChat.deleteChannel([CHANNEL_ID]) { channel, e->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS(Swift)
NChat.deleteChannel(channelId: [CHANNEL_ID]) { result in
switch(result)
{
case .success(let channel) :
// Succeeded
break
case .failure(let error) :
// Failed
break
}
}
iOS (Objective-C)
[NChatBridge.shared deleteChannelWithChannelId:[CHANNEL_ID] :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
Channel channel = await nc.deleteChannel([CHANNEL_ID]);
Edit channel
Update the channel information.
Javascript/Typescript
const channel = await nc.updateChannel(channelId, {
name,
type: "PUBLIC",
members: [],
});
Android(Kotlin)
import com.nbase.adpater.cloudchat.model.Channel
val newChannel = Channel(name = "New Channel2")
NChat.updateChannel([CHANNEL_ID], newChannel) { channel, e->
if (e != null) {
// Error
} else {
// Succeeded
}
}
iOS(Swift)
var newChannel: NCChannel = NCChannel(name: "New Channel2")
NChat.updateChannel(channelId: [CHANNEL_ID], channel: newChannel) { result in
switch(result)
{
case .success(let channel) :
// Succeeded
break
case .failure(let error) :
// Failed
break
}
}
iOS (Objective-C)
NSMutableDictionary *channelDict = [NSMutableDictionary dictionary];
channelDict[@"name"] = @"New Channel2";
[NChatBridge.shared updateChannelWithChannelId:[CHANNEL_ID] channel:channelDict :^(NSDictionary * _Nullable result, NSError * _Nullable error) {
if (error) {
// Error
} else {
// Succeeded
}
}];
Unity
Channel channel = await nc.updateChannel([CHANNEL_ID],new NBaseSDK.Channel
{
name = "Update Channel",
type =[TYPE], // PUBLIC or PRIVATE
customField = [CUSTOM_FIELD]
});