Skip to main content

Overview

The UI Kit’s core function is to extend the Chat SDK, essentially translating the raw data and functionality provided by the underlying methods into visually appealing and easy-to-use UI components. To effectively manage and synchronize the UI elements and data across all components in the UI Kit, we utilize internal events. These internal events enable us to keep track of changes in real-time and ensure that the UI reflects the most current state of data. The CometChat UI Kit has thoughtfully encapsulated the critical Chat SDK methods within its wrapper to efficiently manage internal eventing. This layer of abstraction simplifies interaction with the underlying CometChat SDK, making it more user-friendly for developers.

Methods

You can access the methods using the CometChatUIKit class. This class provides access to all the public methods exposed by the CometChat UI Kit.

Init

As a developer, you need to invoke this method every time before you use any other methods provided by the UI Kit. This initialization is a critical step that ensures the UI Kit and Chat SDK function correctly and as intended in your application. Typical practice is to make this one of the first lines of code executed in your application’s lifecycle when it comes to implementing CometChat.
CometChatUIKit.init() must be called before rendering any UI Kit components or calling any SDK methods. Initialization must complete before login.
Auth Key is for development/testing only. In production, generate Auth Tokens on the server using the REST API and pass them to the client via loginWithAuthToken(). Never expose Auth Keys in production client code.
Make sure you replace the APP_ID, REGION and AUTH_KEY with your CometChat App ID, Region and Auth Key in the below code. The Auth Key is an optional property of the UIKitSettings Class. It is intended for use primarily during proof-of-concept (POC) development or in the early stages of application development. You can use the Auth Token to log in securely.
As a developer, the UIKitSettings is an important parameter of the init() function. It functions as a base settings object, housing properties such as appId, region, and authKey, contained within UIKitSettings. Here’s the table format for the properties available in UIKitSettings:
The concluding code block:

Login using Auth Key

Only the UID of a user is needed to log in. This simple authentication procedure is useful when you are creating a POC or if you are in the development phase. For production apps, we suggest you use AuthToken instead of Auth Key.

Login using Auth Token

Production-safe authentication that does not expose the Auth Key in client code.
  1. Create a User via the CometChat API when the user signs up in your app.
  2. Create an Auth Token via the CometChat API for the new user and save the token in your database.
  3. Load the Auth Token in your client and pass it to the loginWithAuthToken() method.

Logout

The CometChat UI Kit and Chat SDK effectively handle the session of the logged-in user within the framework. Before a new user logs in, it is crucial to clean this data to avoid potential conflicts or unexpected behavior. This can be achieved by invoking the .logout() function

Create User

As a developer, you can dynamically create users on CometChat using the .createUser() function. This can be extremely useful for situations where users are registered or authenticated by your system and then need to be created on CometChat.

Update User

As a developer, you can update user details using the .updateUser() function. This should ideally be achieved at your backend using the Restful APIs, but can also be done client-side when needed.

Get Logged In User

You can check if there is any existing session in the SDK and retrieve the details of the logged-in user using the .getLoggedInUser() function.

DateFormatter

By providing a custom implementation of the DateTimeFormatterCallback, you can globally configure how time and date values are displayed across all UI components in the CometChat UI Kit. This ensures consistent formatting for labels such as “Today”, “Yesterday”, “X minutes ago”, and more, throughout the entire application. Each method in the interface corresponds to a specific case:
  • time(int? timestamp) → Custom full timestamp format
  • today(int? timestamp) → Called when a message is from today
  • yesterday(int? timestamp) → Called for yesterday’s messages
  • lastWeek(int? timestamp) → Messages from the past week
  • otherDays(int? timestamp) → Older messages
  • minute(int? timestamp) / hour(int? timestamp) → Exact time unit
  • minutes(int? diffInMinutesFromNow, int? timestamp) → e.g., “5 minutes ago”
  • hours(int? diffInHourFromNow, int? timestamp) → e.g., “2 hours ago”

Base Message

Text Message

Sends a text message in a 1:1 or group chat. Takes a TextMessage object.

Media Message

Sends a media message in a 1:1 or group chat. Takes a MediaMessage object.

Custom Message

Sends a custom message (neither text nor media) in a 1:1 or group chat. Takes a CustomMessage object.

Interactive Message

Form Message

As a developer, if you need to send a Form message to a single user or a group, you’ll need to utilize the sendFormMessage() function. This function requires a FormMessage object as its argument, which contains the necessary information to create a form bubble for that messages

Card Message

As a developer, if you need to send a Card message to a single user or a group, you’ll need to utilize the sendCardMessage() function. This function requires a CardMessage object as its argument, which contains the necessary information to create a card bubble for the messages

Scheduler Message

As a developer, if you need to send a Scheduler message to a single user or a group, you’ll need to utilize the sendSchedulerMessage() function. This function requires a SchedulerMessage object as its argument, which contains the necessary information to create a SchedulerMessage bubble for the messages

Custom Interactive Message

As a developer, if you need to send a Interactive message to a single user or a group, you’ll need to utilize the sendCustomInteractiveMessage() function. This function requires a InteractiveMessage object as its argument, which contains the necessary information to create a custom interactive message bubble for the messages

Reactions

Add Reaction

As a developer, you can add a reaction to a message using the addReaction() function. This will update the UI of CometChatMessageList and CometChatReactions accordingly.

Remove Reaction

As a developer, you can remove a reaction from a message using the removeReaction() function. This will update the UI of CometChatMessageList and CometChatReactions accordingly.