Chat object
Once you initialize the Unity Chat SDK and create its instance, you'll get immediate access to the Chat entity from which you can call the PubNub server.
To communicate with PubNub, you can use various methods. For example, you can use DeleteChannel() to remove a given channel (chat.DeleteChannel("support")) or WherePresent() to check which channels a given user is subscribed to (chat.WherePresent("support_agent_15")).
By calling methods on the Chat entity, you create chat objects like Channel, User, Message, Membership, ThreadChannel, and ThreadMessage. These objects also expose Chat API under various methods, letting you perform CRUD operations on messages, channels, users, the related user-channel membership, and many more.
Each of these entities comes with a set of "read-only" parameters you define when creating, modifying, and deleting specific channels, users, messages, or memberships in your chat app.
Properties
The Chat object has the following properties:
1public async Task<Chat> CreateInstance(PubnubChatConfig config)
2
3...
4
5public class PubnubChatConfig
6{
7 public PNConfiguration PnConfiguration { get; }
8 public int TypingTimeout { get; }
9 public int TypingTimeoutDifference { get; }
10 public bool StoreUserActivityTimestamp { get; }
11 public int StoreUserActivityInterval { get; }
12}
For details, refer to Initial configuration.
To initialize the Unity Chat SDK, you must provide a PNConfiguration object.
Events
The Chat object has the following events:
1// Base event that is generated each time any other event type is generated
2public event Action<ChatEvent> OnAnyEvent;
Example
Get an event that is triggered when any chat event occurs.
1
Methods
You can call the following methods on the Chat object.
Click on each method for more details.
CreateUser()CreateDirectConversation()CreateGroupConversation()CreatePublicConversation()DeleteChannel()DeleteUser()EmitEvent()GetEventsHistory()GetChannel()GetChannelMemberships()GetChannels()GetCurrentUserMentions()GetUserMemberships()GetThreadChannel()GetCurrentUser()GetUser()GetUsers()GetUnreadMessagesCounts()IsPresent()MarkAllMessagesAsReadSetRestriction()UpdateChannel()UpdateUser()WherePresent()WhoIsPresent()
Use case
For example, you can use the Chat object methods to: