Create channels
Create channels (Channel
objects) of one of these types:
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Create direct channel
Direct channels enable private conversations between two users, letting one person initiate the chat and send an invitation to another person for:
-
Personal conversations - you can engage in private conversations with friends, family, or colleagues, sharing personal updates, discussing sensitive matters, or planning social events.
-
Professional collaboration - you can use 1:1 chat to have focused discussions, exchange confidential information, provide feedback, or coordinate tasks with colleagues and business partners.
CreateDirectConversation()
is a method that:
- Creates a
direct
(one-on-one) channel type. - Sets channel membership for the channel owner (so that they can join the channel).
- Invites the other user to join the channel. As a result, an event of the
invite
type gets created. You can listen to these events in your chat app and notify the invited users.
If you call this method to create a channel for users that already had a conversation which was not deleted, this conversation is retrieved.
Receive messages
Note that you still have to call the Connect()
method to subscribe to message event listeners and start receiving messages on the channel.
Method signature
This method takes the following parameters:
chat.CreateDirectConversation(
User user,
string channelId,
ChatChannelData channelData)
public class ChatChannelData
{
public string ChannelName { get; set; } = string.Empty;
public string ChannelDescription { get; set; } = string.Empty;
public string ChannelCustomDataJson { get; set; } = string.Empty;
public string ChannelUpdated { get; set; } = string.Empty;
public string ChannelStatus { get; set; } = string.Empty;
public string ChannelType { get; set; } = string.Empty;
}
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
user | User | Yes | n/a | User that you invite to join a channel. |
channelId | string | Yes | n/a | ID of the direct channel. |
channelData | object | No | n/a | Information about the channel. |
→ ChannelName | string | Channel ID | n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as id (value of channelId ). |
→ ChannelDescription | string | No | n/a | Additional details about the channel. |
→ ChannelCustomDataJson | string | No | n/a | Any custom properties or metadata associated with the channel. |
→ ChannelUpdated | string | No | n/a | Timestamp indicating when the channel was last updated or modified. |
→ ChannelStatus | string | No | n/a | Current status of the channel, such as online , offline , or archived . |
→ ChannelType | string | No | n/a | Type of the channel, like direct . |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
This method returns a tuple with the following data:
Parameter | Type | Description |
---|---|---|
createdChannel | Channel | Returned object containing the updated channel metadata. |
hostMembership | Membership | Returned object containing the updated host (channel owner) metadata. |
inviteeMembership | Membership | Returned object containing the updated data of the invited user. |
Basic usage
Invite agent-007
to a 1:1 conversation to talk about customer XYZ
.
if (!chat.TryGetUser("agent-007", out var user))
{
Console.WriteLine("Couldn't find user!");
return;
};
string channelId = "direct.agent-001&agent-007";
ChatChannelData channelData = new ChatChannelData
{
ChannelName = "Customer XYZ Discussion",
ChannelDescription = "Conversation about customer XYZ",
ChannelCustomDataJson = "{}",
ChannelStatus = "active",
ChannelType = "direct"
show all 19 linesCreate group channel
Group channels enable communication among multiple users, promoting collaboration and teamwork. A user can initiate a group chat and invite others to be channel members for:
-
Team collaboration - members of a project team can use group chat to share updates, exchange ideas, ask questions, and provide status updates. This boosts real-time collaboration and productivity and ensures everyone stays on the same page.
-
Community building - group chat allows like-minded individuals to connect, discuss shared interests, organize events, and build strong communities around specific topics, hobbies, or professional fields.
Such a chat type is restricted by invitation, and you can access it only when invited.
CreateGroupConversation()
is a method that:
- Creates a
group
channel type. - Sets channel membership for the channel owner (so that they can join the channel).
- Invites other users to join the channel.
Receive messages
Note that you still have to call the Connect()
method to subscribe to message event listeners and start receiving messages on the channel.
Method signature
This method takes the following parameters:
chat.CreateGroupConversation(
List<User> users,
string channelId,
ChatChannelData channelData)
public class ChatChannelData
{
public string ChannelName { get; set; } = string.Empty;
public string ChannelDescription { get; set; } = string.Empty;
public string ChannelCustomDataJson { get; set; } = string.Empty;
public string ChannelUpdated { get; set; } = string.Empty;
public string ChannelStatus { get; set; } = string.Empty;
public string ChannelType { get; set; } = string.Empty;
}
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
users | List<User> | Yes | n/a | List of users that you invite to join a channel. You can invite a maximum number of 100 users at once as this is the limitation set by the App Context API that the InviteMultiple() method calls. |
channelId | string | Yes | n/a | ID of the group channel. |
channelData | ChatChannelData | No | n/a | Information about the channel. |
→ ChannelName | string | Channel ID | n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as id (value of channelId ). |
→ ChannelDescription | string | No | n/a | Additional details about the channel. |
→ ChannelCustomDataJson | string | No | n/a | Any custom properties or metadata associated with the channel. |
→ ChannelUpdated | string | No | n/a | Timestamp indicating when the channel was last updated or modified. |
→ ChannelStatus | string | No | n/a | Current status of the channel, such as online , offline , or archived . |
→ ChannelType | string | No | n/a | Type of the channel, like group . |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
This method returns a tuple with the following data:
Parameter | Type | Description |
---|---|---|
createdChannel | Channel | Returned object containing the updated channel metadata. |
hostMembership | Membership | Returned object containing the updated host (channel owner) data. |
inviteesMemberships | List<Membership> | Returned object containing the updated metadata of the invited users. |
Basic usage
Create a group conversation and invite agent-007
and agent-008
to have weekly syncs on customer XYZ
.
// reference both agents you want to talk to
if (!chat.TryGetUser("agent-007", out var user1))
{
Console.WriteLine("Couldn't find first user!");
return;
};
if (!chat.TryGetUser("agent-008", out var user2))
{
Console.WriteLine("Couldn't find second user!");
};
List<User> users = new List<User> { user1, user2 };
// Define the channel's ID and details via ChatChannelData
string channelId = "group-chat-1"; // Optional, can be auto-generated
show all 26 linesCreate public channel
Supported features
The public channel type comes with certain limitations in place - you'll get errors when trying to implement such Unity Chat SDK features as typing indicator, invites, or read receipts in public channels since these features are neither useful nor practical for large audiences.
Public channels let users engage in open conversations with many people. Unlike group chats, anyone can join public channels. Example use cases include:
-
Knowledge sharing and Q&A - public chats provide a platform for users to seek advice, share knowledge, and participate in discussions related to specific topics, fostering a community-driven environment.
-
Events and webinars - organizations can host public chats during live events, webinars, or panel discussions, allowing attendees to interact with presenters, ask questions, and share insights in real time.
CreatePublicConversation()
is a method that creates such a public
channel type with specified metadata.
Receive messages
Note that you still have to call the Connect()
method to subscribe to message event listeners and start receiving messages on the channel.
Method signature
This method takes the following parameters:
chat.CreatePublicConversation(
string channelId,
ChatChannelData additionalData
)
public class ChatChannelData
{
public string ChannelName { get; set; } = string.Empty;
public string ChannelDescription { get; set; } = string.Empty;
public string ChannelCustomDataJson { get; set; } = string.Empty;
public string ChannelUpdated { get; set; } = string.Empty;
public string ChannelStatus { get; set; } = string.Empty;
public string ChannelType { get; set; } = string.Empty;
}
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channelId | string | Yes | n/a | ID of the group channel. |
channelData | ChatChannelData | No | n/a | Information about the channel. |
→ ChannelName | string | Channel ID | n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as id (value of channelId ). |
→ ChannelDescription | string | No | n/a | Additional details about the channel. |
→ ChannelCustomDataJson | string | No | n/a | Any custom properties or metadata associated with the channel. |
→ ChannelUpdated | string | No | n/a | Timestamp indicating when the channel was last updated or modified. |
→ ChannelStatus | string | Yes | n/a | Current status of the channel, such as online , offline , or archived . |
→ ChannelType | string | Yes | n/a | Type of the channel, like public . |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
Type | Description |
---|---|
Channel | Object returning the created channel metadata. |
Basic usage
Create a public ask-support
channel.
ChatChannelData additionalData = new ChatChannelData
{
ChannelName = "Support channel",
ChannelDescription = "Discussion about support for all suers",
ChannelStatus = "active",
ChannelType = "public"
};
chat.CreatePublicConversation("ask-support", additionalData)