getSmartReplies static method
Get AI-generated smart reply suggestions for a conversation.
Migration Note: Migrated from platform channels to native Dart implementation. Uses AiRepository for AI-powered smart replies. Behavior and signature remain identical for backward compatibility.
Android Reference: CometChat.getSmartReplies(String receiverId, String receiverType, CallbackListener<HashMap<String, String>>)
Implementation
static Future<void> getSmartReplies(String receiverId, String receiverType,
{Map? configuration,
required Function(HashMap<String, String>) 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 replies = await sdk.ai.getSmartReplies(receiverId, receiverType);
// Convert to HashMap for backward compatibility
var hashMap = HashMap<String, String>();
replies.forEach((key, value) {
hashMap[key] = value;
});
// Call success callback
onSuccess(hashMap);
} 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(),
));
}
}