Overview
The UI Kit’s core function is to extend the CometChat 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 CometChat 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 theCometChatUIKit
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.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.UIKitSettings
:
Method | Type | Description |
---|---|---|
set(appID:) | String | Sets the unique ID for the app, available on dashboard |
set(region:) | String | Sets the region for the app (‘us’ or ‘eu’) |
set(authKey:) | String | Sets the auth key for the app, available on dashboard |
subscribePresenceForAllUsers | String | Sets subscription type for tracking the presence of all users |
subscribePresenceForFriends | String | Sets subscription type for tracking the presence of friends |
subscribePresenceForRoles | String | Sets subscription type for tracking the presence of users with specified roles |
setAutoEstablishSocketConnection | Boolean | Configures if web socket connections will established automatically on app initialization or be done manually, set to true by default |
setAIFeatures | List<AIExtensionDataSource> | Sets the AI Features that need to be added in UI Kit |
setExtensions | List<ExtensionsDataSource> | Sets the list of extension that need to be added in UI Kit |
The concluding code block:
Login using Auth Key
Only theUID
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.
The concluding code block:
Login using Auth Token
This advanced authentication procedure does not use the Auth Key directly in your client code thus ensuring safety.- Create a User via the CometChat API when the user signs up in your app.
- Create an Auth Token via the CometChat API for the new user and save the token in your database.
- Load the Auth Token in your client and pass it to the
login(authToken:)
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(user:)
function.
The concluding code block:
Create User
As a developer, you can dynamically create users on CometChat using the.create(user:)
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.
The concluding code block:
Base Message
Text Message
As a developer, if you need to send a text message to a single user or a group, you’ll need to utilize thesendTextMessage()
function. This function requires a TextMessage
object as its argument, which contains the necessary information for delivering the message.
The concluding code block:
It’s essential to understand the difference betweenCometChatUIKit.sendTextMessage()
andCometChat.sendTextMessage()
. When you useCometChatUIKit.sendTextMessage()
, it automatically adds the message to the MessagesComponent and ConversationsComponent, taking care of all related cases for you. On the other hand,CometChat.sendTextMessage()
only sends the message and doesn’t automatically update these components in the UI Kit.
Media Message
As a developer, if you need to send a media message to a single user or a group, you’ll need to utilize thesendMediaMessage()
function. This function requires a MediaMessage
object as its argument, which contains the necessary information for delivering the message.
The concluding code block:
It’s essential to understand the difference betweenCometChatUIKit.sendMediaMessage()
andCometChat.sendMediaMessage()
. When you useCometChatUIKit.sendMediaMessage()
, it automatically adds the message to the MessagesComponent and ConversationsComponent, taking care of all related cases for you. On the other hand,CometChat.sendMediaMessage()
only sends the message and doesn’t automatically update these components in the UI Kit.
Custom Message
As a developer, if you need to send a custom message to a single user or a group, you’ll need to utilize thesendCustomMessage()
function. This function requires a CustomMessage
object as its argument, which contains the necessary information for delivering the message.
The concluding code block:
It’s essential to understand the difference betweenCometChatUIKit.sendCustomMessage()
andCometChat.sendCustomMessage()
. When you useCometChatUIKit.sendCustomMessage()
, it automatically adds the message to the MessagesComponent and ConversationsComponent, taking care of all related cases for you. On the other hand,CometChat.sendCustomMessage()
only sends the message and doesn’t automatically update these components in the UI Kit.
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 thesendFormMessage()
function. This function requires a FormMessage
object as its argument, which contains the necessary information to create a form bubble for that messages
The concluding code block:
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 thesendCardMessage()
function. This function requires a CardMessage
object as its argument, which contains the necessary information to create a card bubble for the messages.
The concluding code block:
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 thesendSchedulerMessage()
function. This function requires a SchedulerMessage
object as its argument, which contains the necessary information to create a SchedulerMessage bubble for the messages.
The concluding code block: