CometChatUIKit
is a class that contains all necessary methods to help initialise the CometChat SDK with valid credentials for the UI Kit to utilise.
Init
This method initialises the settings required for CometChat SDK. First, ensure UIKitSettings is set and then call theinit()
method on app startup
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 method to log in securely.- JavaScript
getLoggedInUser
You can use this method to check if there is any existing session in the SDK. This method should return the details of the logged-in user.- JavaScript
Login
The login() method returns the User object containing all the information of the logged-in user.Login using Auth Key
This straightforward authentication method is ideal for proof-of-concept (POC) development or during the early stages of application development. For production environments, however, we strongly recommend using an Auth Token instead of an Auth Key to ensure enhanced security.
- JavaScript
- Make sure you replace the UID with a genuine UID in the above code.
- We have set up 5 users for testing having UIDs: cometchat-uid-1, cometchat-uid-2, cometchat-uid-3, cometchat-uid-4, and cometchat-uid-5.
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
loginWithAuthToken()
method.
- JavaScript
Logout
This method is used for ending user session of the logged in user- JavaScript
Create user
This method takes aUser
object and the Auth Key
as input parameters and returns the created User
object if the request is successful.
- JavaScript
Update user
This method takes aUser
object and the Auth Key
as inputs and returns the updated User
object on the successful execution of the request.
- JavaScript
Send text message
This method sends a text message in a 1:1 or group chat. You need to pass aTextMessage
object to it.
- 1:1 chat
- Group chat
Send media message
This method sends a media message in a 1:1 or group chat. You need to pass aMediaMessage
object to it.
Make sure you replace the
INPUT FILE OBJECT
with the actual file.- 1:1 chat
- Group chat
Send custom message
This method allows you to send custom messages which are neither text nor media messages.- 1:1 chat
- Group chat
Send Form message
This method allows you to send Form Message which are the extension of Interactive Message- 1:1 chat
- Group chat
Send Card message
This method allows you to send Card Message which are the extension of Interactive Message- 1:1 chat
- Group chat
Send CustomInteractive message
This method allows you to send Custom Interactive Message which are the extension of Interactive Message- 1:1 chat
- Group chat