Chat object
The Chat object is your entry point to the Chat SDK after initialization. Use the Chat object to create and manage channels, users, messages, memberships, and other entities.
Key capabilities:
- Create and delete channels and users
- Track user presence across channels
- Send custom events
- Access the underlying Kotlin SDK
Properties
The Chat interface has the following properties:
1interface Chat {
2 val config: ChatConfiguration
3 val pubNub: PubNub
4 val currentUser: User
5
6 ...
7}
| Parameter | Description |
|---|---|
configType: ChatConfiguration | ChatConfiguration contains chat app configuration settings, such as logLevel or typingTimeout that you can provide when initializing your chat app with the init() method. You can later directly access these properties, like: chat.storeUserActivityInterval. |
pubNubType: PubNub | pubNub lets you access any Kotlin SDK method. For example, if you want to call a method available in the App Context API, you'd use chat.pubNub.getAllUUIDMetadata(). |
currentUserType: User | User object representing current user. |
ChatConfiguration includes these properties:
1interface ChatConfiguration {
2 val logLevel: LogLevel
3 val typingTimeout: Duration
4 val storeUserActivityInterval: Duration
5 val storeUserActivityTimestamps: Boolean
6 val pushNotifications: PushNotificationsConfig
7 val rateLimitFactor: Int
8 val rateLimitPerChannel: Map<ChannelType, Duration>
9 val customPayloads: CustomPayloads?
10}
PushNotificationsConfig includes these properties:
1class PushNotificationsConfig(
2 val sendPushes: Boolean,
3 val deviceToken: String?,
4 val deviceGateway: PNPushType,
5 val apnsTopic: String?,
6 val apnsEnvironment: PNPushEnvironment
7)
Initialize the Chat SDK with two required parameters: subscribeKey and userId. All other settings are optional. See Configuration for details.
Methods
The Chat object exposes the following methods.
createUser()createDirectConversation()createGroupConversation()createPublicConversation()currentUserdeleteChannel()deleteUser()emitEvent()getEventsHistory()getChannel()getChannelGroup()getChannels()getCurrentUserMentions()fetchUnreadMessagesCounts()getUser()getUsers()getPushChannels()init()isPresent()listenForEvents()markAllMessagesAsReadregisterPushChannels()removeChannelGroup()setRestrictions()unregisterPushChannels()unregisterAllPushChannels()updateChannel()updateUser()wherePresent()whoIsPresent()
Use case
For example, you can use the Chat object methods to: