Skip to main content
CometChatUIKit is a class that contains all necessary methods to help initialize the CometChat SDK with valid credentials for the ui kit to utilize. The following properties and methods are present:
ParametersTypeDescription
initstatic init(uiKitSettings: UIKitSettings): Promise<boolean>method initializes the settings required for CometChat SDK. First, ensure authSettings is set and then call the init() method on app startup
loginstatic async login({ uid, authToken }: { uid?: string, authToken?: string }): Promise<CometChat.User>used for logging in with credentials but use this function only for testing purpose
logoutstatic logout(): Promise<Object>used for ending user session of logged in user
createUserstatic createUser( user: CometChat.User): Promise<CometChat.User>used for creating new user
updateUserstatic updateUser(user: CometChat.User): Promise<CometChat.User> {used for updating user object
sendCustomMessagestatic sendCustomMessage(message: CometChat.CustomMessage, onSuccess?: (msg: CometChat.CustomMessage | CometChat.BaseMessage) => void, onError?: (msg: CometChat.CometChatException) => void): voidcan be used to send a custom message
sendTextMessagestatic sendTextMessage(message: CometChat.TextMessage, onSuccess?: (msg: CometChat.TextMessage | CometChat.BaseMessage) => void, onError?: (msg: CometChat.CometChatException) => void): voidcan be used to send a text message
sendMediaMessagestatic sendMediaMessage(message: CometChat.CustomMessage, onSuccess?: (msg: CometChat.MediaMessage | CometChat.BaseMessage) => void, onError?: (msg: CometChat.CometChatException) => void): voidcan be used to send a media message
sendFormMessagestatic sendFormMessage(message: FormMessage, disableLocalEvents: boolean = false): Promise<CometChat.TextMessage | CometChat.BaseMessage>can be used to send a form message. disableLocalEvents - A boolean indicating whether to disable local events or not. Default value is false.
sendCardMessagestatic sendCardMessage(message: CardMessage, disableLocalEvents: boolean = false): Promise<CometChat.TextMessage | CometChat.BaseMessage>can be used to send a card message. disableLocalEvents - A boolean indicating whether to disable local events or not. Default value is false.
sendCustomInteractiveMessagestatic sendCustomInteractiveMessage(message: CustomInteractiveMessage, disableLocalEvents: boolean = false): Promise<CometChat.TextMessage | CometChat.BaseMessage>can be used to send a custom interactive message. disableLocalEvents - A boolean indicating whether to disable local events or not. Default value is false.

sendTextMessage

Used to send text messages.

sendMediaMessage

used to send media messages

sendCustomMessage

Used to send custom messages.

Send Form message

This method allows you to send Form messages which are the extension of Interactive Message

Send Card message

This method allows you to send Card messages which are the extension of Interactive Message

Send CustomInteractive message

This method allows you to send CustomInteractive messages which are the extension of Interactive Message

UIKitSettings

UIKitSettings is an object containing credentials to initialize CometChat SDK.
PropertiesTypeDescription
appIdstringthe unique ID for the app, available on dashboard
regionstringthe region for the app us or eu
authKeystringthe auth key for the app, available on dashboard
subscriptionTypestringsets user presence subscription for all users
autoEstablishSocketConnectionBoolconfigure if web socket connections will established automatically on app initialization or be done manually, set to true by default
disableCallingbooleandisable calling
overrideAdminHoststringused to set the admin host
overrideClientHoststringused to set the client host

How to initialize the UI Kit?

The UI Kit can be initialized to use CometChatUIKit by populating the auth settings first and the calling the init method. Preferably this should be done at the top most level when the app starts.
infoMake 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.

How to login a user of your App?

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.

How to login a user with Auth Token?

This advanced authentication procedure does not use the Auth Key directly in your client code thus ensuring safety.
  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 login({authToken: authToken}) method.

How to create a new user for your App?

Create an object the new user that needs to created with as little information as the name of the user and a uid and pass it to the create(user: User) method

How to update a user for your App?

Update an object the user that needs to updated with as little information as the name of the user and a uid and pass it to the update(user: User) method

How to logout from a logged-In User in App?

just pass the loggedIn-user to the logout method