> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Assistant Chat History

## Overview

The `AI Assistant Chat History` component is a pre-built user interface element designed to display the conversation history between users and an AI assistant within a chat application. It provides a structured and visually appealing way to present past interactions, making it easy for users to review previous messages and context.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/iOmdgJzyAoKBq6hb/images/ai_assistant_chat_history.png?fit=max&auto=format&n=iOmdgJzyAoKBq6hb&q=85&s=142618c4e05b65bf7e7707d4dc81a293" width="3040" height="1760" data-path="images/ai_assistant_chat_history.png" />
</Frame>

***

## Usage

### Integration

`AIAssistantChatHistory`, as a Composite Component, offers flexible integration options, allowing it to be launched directly via button clicks or any user-triggered action.

The following code snippet exemplifies how you can seamlessly integrate the GroupMembers component into your application.

<Tabs>
  <Tab title="XML">
    ```xml theme={null}
        <com.cometchat.chatuikit.aiassistantchathistory.CometChatAIAssistantChatHistory
            android:id="@+id/cometchat_ai_assistant_chat_history"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    ```
  </Tab>
</Tabs>

If you're defining the Group members within the XML code, you'll need to extract them and set them on the Group object using the appropriate method.

<Tabs>
  <Tab title="Java">
    ```java theme={null}

    User user = new User();
    user.setUid("userId");
    user.setName("User Name");
    user.setRole("@agentic"); // User role must be @agentic to use AI Assistant features

    binding.cometChatAiAssistantChatHistory.setUser(user);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}

    val user = User()
    user.uid = "userId"
    user.name = "User Name"
    user.role = "@agentic" // User role must be @agentic to use AI Assistant features

    binding.cometChatAiAssistantChatHistory.setUser(user)
    ```
  </Tab>
</Tabs>

***

### Actions

[Actions](/ui-kit/android/components-overview#actions) dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.

##### setOnItemClickListener

Function invoked when a chat history item is clicked, typically used to open an ai assistant chat screen.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}

    binding.cometchatAiAssistantChatHistory.setOnItemClickListener((view, position, message) -> {

            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    binding.cometchatAiAssistantChatHistory.setOnItemClickListener { view, position, message ->

            }
    ```
  </Tab>
</Tabs>

***

##### setOnItemLongClick

Function executed when a user item is long-pressed, allowing additional actions like delete or block.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    binding.cometchatAiAssistantChatHistory.setOnItemLongClickListener((view, position, message) -> {

            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    binding.cometchatAiAssistantChatHistory.setOnItemLongClickListener { view, position, message ->

            }
    ```
  </Tab>
</Tabs>

***

##### setOnNewChatClickListener

Function triggered when the new chat button is clicked, typically used to start a new conversation with the AI assistant.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    binding.cometchatAiAssistantChatHistory.setOnNewChatClickListener(() -> {

            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    binding.cometchatAiAssistantChatHistory.setOnNewChatClickListener {

            }
    ```
  </Tab>
</Tabs>

***

##### setOnCloseClickListener

Function activated when the close button is clicked, usually to exit the chat history view.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    binding.cometchatAiAssistantChatHistory.setOnCloseClickListener(() -> {

            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    binding.cometchatAiAssistantChatHistory.setOnCloseClickListener {

            }
    ```
  </Tab>
</Tabs>

## Customization

The `AIAssistantChatHistory` component offers a variety of customization options to tailor its appearance and functionality to better fit your application's needs. These customizations are categorized into three main areas: Style, Functionality, and Advanced.

### Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/iOmdgJzyAoKBq6hb/images/android-ai-assistant-chat-history-style.png?fit=max&auto=format&n=iOmdgJzyAoKBq6hb&q=85&s=d020d2fa9c2a89f42cece8782e9f1a8a" width="3040" height="1760" data-path="images/android-ai-assistant-chat-history-style.png" />
</Frame>

```xml themes.xml theme={null}
    <style name="CustomAIAssistantChatHistoryStyle">
        <item name="cometChatAIAssistantChatHistoryBackgroundColor">#FFFAF6</item>
        <item name="cometChatAIAssistantChatHistoryHeaderBackgroundColor">#FFFAF6</item>
        <item name="cometChatAIAssistantChatHistoryHeaderTextColor">?attr/cometchatTextColorPrimary</item>
        <item name="cometChatAIAssistantChatHistoryHeaderTextAppearance">@style/textStyleTimesNewRoman</item>
        <item name="cometChatAIAssistantChatHistoryNewChatBackgroundColor">#FFFAF6</item>
        <item name="cometChatAIAssistantChatHistoryNewChatTextColor">?attr/cometchatTextColorPrimary</item>
        <item name="cometChatAIAssistantChatHistoryNewChatTextAppearance">@style/textStyleTimesNewRoman</item>
        <item name="cometChatAIAssistantChatHistoryDateSeparatorTextAppearance">@style/textStyleTimesNewRoman</item>
        <item name="cometChatAIAssistantChatHistoryDateSeparatorTextColor">?attr/cometchatTextColorTertiary</item>
        <item name="cometChatAIAssistantChatHistoryDateSeparatorBackgroundColor">#FFFAF6</item>
        <item name="cometChatAIAssistantChatHistoryItemBackgroundColor">#FFFAF6</item>
        <item name="cometChatAIAssistantChatHistoryItemTextAppearance">@style/textStyleTimesNewRoman</item>
        <item name="cometChatAIAssistantChatHistoryItemTextColor">?attr/cometchatTextColorPrimary</item>
    </style>

    <style name="textStyleTimesNewRoman">
        <item name="android:fontFamily">@font/times_new_roman_regular</item>
    </style>
```

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    binding.cometchatAiAssistantChatHistory.setStyle(R.style.CustomAIAssistantChatHistoryStyle);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    binding.cometchatAiAssistantChatHistory.setStyle(R.style.CustomAIAssistantChatHistoryStyle);
    ```
  </Tab>
</Tabs>

***

To know more such attributes, visit the [attributes file](https://github.com/cometchat/cometchat-uikit-android/blob/v5/chatuikit/src/main/res/values/attr_cometchat_ai_assistant_chat_history.xml).

### Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can toggle the visibility of UI elements.

Below is a list of customizations along with corresponding code snippets

| Methods                 | Description                                                                                                                                      | Code                                   |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------- |
| setUser                 | Sets the user whose chat histories with the ai assistant need to be fetched. This is a required property for the component to function properly. | `.setUser(user);`                      |
| setErrorStateVisibility | Used to toggle the visibility of the error state of the component                                                                                | `.setErrorStateVisibility(View.GONE);` |
| setEmptyStateVisibility | Used to toggle the visibility of the empty state of the component                                                                                | `.setEmptyStateVisibility(View.GONE);` |
