> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Methods

> Methods — CometChat documentation.

## Overview

The UI Kit's core function is to extend the [Chat SDK](/sdk/flutter/overview), 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](/sdk/flutter/overview) 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.

<Note>
  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](#login-using-auth-token) to log in securely.
</Note>

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`:

| Method                            | Type                          | Description                                                                                                                           |
| --------------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| **appId**                         | `String`                      | Sets the unique ID for the app, available on dashboard                                                                                |
| **region**                        | `String`                      | Sets the region for the app ('us' or 'eu' or 'in')                                                                                    |
| **authKey**                       | `String`                      | Sets the auth key for the app, available on dashboard                                                                                 |
| **subscriptionType**              | `String`                      | Sets subscription type for tracking the presence of all users                                                                         |
| **roles**                         | `String`                      | Sets subscription type for tracking the presence of users with specified roles                                                        |
| **autoEstablishSocketConnection** | `Boolean`                     | Configures if web socket connections will established automatically on app initialization or be done manually, set to true by default |
| **aiFeature**                     | `List<AIExtensionDataSource>` | Sets the AI Features that need to be added in UI Kit                                                                                  |
| **extensions**                    | `List<ExtensionsDataSource>`  | Sets the list of extension that need to be added in UI Kit                                                                            |

***

The concluding code block:

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    UIKitSettings uiKitSettings = (UIKitSettingsBuilder()
      ..subscriptionType = CometChatSubscriptionType.allUsers
      ..autoEstablishSocketConnection = true
      ..region = "your_region"// Replace with your region
      ..appId = "your_appID" // Replace with your app Id
      ..authKey = "your_authKey" // Replace with your app auth key
    ).build();

    CometChatUIKit.init(uiKitSettings: uiKitSettings,onSuccess: (successMessage) async {
      // TODO("Not yet implemented")
    }, onError: (error) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

### 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](#login-using-auth-token) instead of Auth Key.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.login(uid, onSuccess: (s) {
        // TODO("Not yet implemented")
    }, onError: (e) {
        // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

### Login using Auth Token

This advanced authentication procedure does not use the Auth Key directly in your client code thus ensuring safety.

1. [Create a User](/rest-api/chat-apis) via the CometChat API when the user signs up in your app.

2. [Create an Auth Token](/rest-api/chat-apis) 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.loginWithAuthToken("authToken", onSuccess: (user) {
        // TODO("Not yet implemented")
    }, onError: (e) {
        // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

### 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

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.logout(onSuccess: (s) {
        // TODO("Not yet implemented")
    } , onError: (e) {
        // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChat.createUser(userObject, 'authKey', onSuccess: (user) {
      // TODO("Not yet implemented")
    }, onError: (e) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

### 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 the `sendMessage()` function. This function requires a `TextMessage` object as its argument, which contains the necessary information for delivering the message.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.sendTextMessage(textMessageObject, onSuccess: (p0) {
      // TODO("Not yet implemented")
    }, onError: (p0) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

#### 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 the `sendMediaMessage()` function. This function requires a `MediaMessage` object as its argument, which contains the necessary information for delivering the message.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.sendMediaMessage(mediaMessageObject, onSuccess: (p0) {
      // TODO("Not yet implemented")
    }, onError: (p0) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

#### Custom Message

As a developer, if you need to send a media message to a single user or a group, you'll need to utilize the `sendCustomMessage()` function. This function requires a `CustomMessage` object as its argument, which contains the necessary information for delivering the message.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.sendCustomMessage(customMessageObject, onSuccess: (p0) {
      // TODO("Not yet implemented")
    }, onError: (p0) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

### 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

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.sendFormMessage(formMessageObject, onSuccess: (p0) {
      // TODO("Not yet implemented")
    }, onError: (p0) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

#### 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

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.sendCardMessage(cardMessageObject, onSuccess: (p0) {
      // TODO("Not yet implemented")
    }, onError: (p0) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

#### 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

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.sendSchedulerMessage(schedulerMessageObject, onSuccess: (p0) {
      // TODO("Not yet implemented")
    }, onError: (p0) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***

#### 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

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUIKit.sendCustomInteractiveMessage(interactiveMessageObject, onSuccess: (p0) {
      // TODO("Not yet implemented")
    }, onError: (p0) {
      // TODO("Not yet implemented")
    });
    ```
  </Tab>
</Tabs>

***
