getConversationStarter static method

Future<void> getConversationStarter(
  1. String receiverId,
  2. String receiverType, {
  3. Map? configuration,
  4. required dynamic onSuccess(
    1. List<String> conversationStarters
    ),
  5. required dynamic onError(
    1. CometChatException excep
    ),
})

Get AI-generated conversation starter suggestions.

Migration Note: Migrated from platform channels to native Dart implementation. Uses AiRepository for AI-powered conversation starters. Behavior and signature remain identical for backward compatibility.

Android Reference: CometChat.getConversationStarter(String receiverId, String receiverType, CallbackListener<List<String>>)

Implementation

static Future<void> getConversationStarter(
  String receiverId,
  String receiverType, {
  Map? configuration,
  required Function(List<String> conversationStarters) onSuccess,
  required Function(CometChatException e) onError,
}) async {
  try {
    // Validate parameters
    if (receiverId.isEmpty) {
      onError(
        CometChatException(
          ErrorCode.errorInvalidReceiverId,
          ErrorMessage.errorMessageInvalidReceiverId,
          ErrorMessage.errorMessageInvalidReceiverId,
        ),
      );
      return;
    }
    if (receiverType.isEmpty) {
      onError(
        CometChatException(
          ErrorCode.errorInvalidReceiverType,
          ErrorMessage.errorMessageInvalidReceiverType,
          ErrorMessage.errorMessageInvalidReceiverType,
        ),
      );
      return;
    }

    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call native Dart AI repository
    final starters = await sdk.ai.getConversationStarter(
      receiverId,
      receiverType,
    );

    // Call success callback
    onSuccess(starters);
  } on SdkException catch (sdkEx) {
    // Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    onError(cometChatEx);
  } catch (e) {
    onError(
      CometChatException(
        ErrorCode.errorUnhandledException,
        e.toString(),
        e.toString(),
      ),
    );
  }
}