> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Conversation Starter

> Conversation Starter — CometChat documentation.

**Conversation Starter** enables you to retrieve an initial message in a new conversation, often used to set the context for the conversation that is about to begin. This can be particularly useful for guiding users on how to interact within the chat or for delivering automated messages that engage users when they initiate a chat.

## Before you begin

1. Set up the AI settings through the CometChat dashboard as detailed in the [Overview section](/fundamentals/ai-user-copilot/overview).
2. Navigate to Chat > Features, under **AI User Copilot**, enable **Conversation Starter**.

   <Frame>
     <img src="https://mintcdn.com/cometchat-22654f5b/D1t_n71f5KROvakA/images/5e5dd82e-cometchat-ai-features-conversation-starter-3a48939de0ec4d575fb5c788552da0a2.png?fit=max&auto=format&n=D1t_n71f5KROvakA&q=85&s=d1dfd6ed754da08ca92ace93c7364944" width="1202" height="605" data-path="images/5e5dd82e-cometchat-ai-features-conversation-starter-3a48939de0ec4d575fb5c788552da0a2.png" />
   </Frame>
3. Implement the chat functionality in your applications using [CometChat's **v4** Chat SDKs](/sdk/javascript/overview).

## How does it work?

CometChat AI analyzes the user's tone and writing style by reviewing recent messages sent by that user within the application.

The SDK includes a method for retrieving conversation starters in a chat. This method returns an array containing three potential starters for the conversation.

The number of messages to be fetched to generate relevant conversation starter is configurable. By default the CometChat AI takes the latest `1000` messages. This can be configured to specific timestamps as well.

| Configuration | Value                                                  |
| ------------- | ------------------------------------------------------ |
| lastNMessages | This will fetch specific number of messages.           |
| fromTimestamp | This will fetch messages from a particular timestamp.  |
| toTimestamp   | This will fetch messages until a particular timestamp. |

<Note>
  While using any configuration mentioned above a maximum of **only** `1000` messages will be fetched.
</Note>

## Implementation

### SDKs

To implement Conversation Starter in the platform of your choice, you may utilize the following code samples:

<Tabs>
  <Tab title="JS/React Native/Ionic SDK">
    ```js theme={null}
    const receiverId = 'UID/GUID';
    const receiverType = 'user/group';
    const configuration = {lastNMessages: 100};

    CometChat.getConversationStarter(receiverId, receiverType, configuration).then(
    	(conversation-starter) => {
      	console.log("Conversation Starter", conversation-starter);
      },
      (error) => {
      	console.log("An error occurred while fetching conversation starter", error);
      }
    );
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    String receiveId = "";
    String receiverType = CometChatConstants.RECEIVER_TYPE_USER;

    JSONObject configuration = new JSONObject();
    try {
        configuration.put("lastNMessages", 100);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    CometChat.getConversationStarter(receiveId, receiverType, configuration, new CometChat.CallbackListener<List<String>>() {
        @Override
        public void onSuccess(List<String> strings) {
            Log.e(TAG, strings.toString());
        }
        @Override
        public void onError(CometChatException e) {
            Log.e(TAG, e.getMessage());
        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val receiveId = ""
    val receiverType: String = CometChatConstants.RECEIVER_TYPE_USER
    val configuration = JSONObject()
    try {
        configuration.put("lastNMessages", 100)
    } catch (e: JSONException) {
        throw RuntimeException(e)
    }

    CometChat.getConversationStarter(
        receiveId,
        receiverType,
        configuration,
        object : CallbackListener<List<String?>?>() {
            fun onSuccess(strings: List<String?>) {
                Log.e(SplashActivity.TAG, strings.toString())
            }

            override fun onError(e: CometChatException) {
                Log.e(SplashActivity.TAG, e.getMessage())
            }
        }
    )
    ```
  </Tab>

  <Tab title="Dart">
    ```dart theme={null}
    String receiveId = "";
    String receiverType = CometChatConversationType.user;
    Map configuration = { "lastNMessages": 100 };

    CometChat.getConversationStarter("cometchat-uid-2", "user", configuration: configuration, onSuccess: (List<String> starters) {
        debugPrint("getConversationStarter Sucess: $starters");
    }, onError: (CometChatException e) {
        debugPrint("getConversationStarter Error: $e");
    });
    ```
  </Tab>

  <Tab title="Swift">
    ```swift theme={null}
    let receiverId = ""
    let receiverType = CometChat.ReceiverType.group
    let configuration = [ "lastNMessages": 100 ]


    CometChat.getConversationStarter(receiverId: "cometchat-uid-1", receiverType: .user, configuration: configuration) { startersReplies in
        print("getConversationStarter success: \(startersReplies)")
    } onError: { error in
        print("getConversationStarter error: \(error?.errorDescription)")
    }
    ```
  </Tab>
</Tabs>

### UI Kits

Assuming the necessary prerequisites are met, Conversation Starter functions seamlessly starting from v4 of the Chat UI Kits. Similarly, Conversation Starter is triggered automatically when there are no messages in a conversation.
