getSmartReplies static method

Future<void> getSmartReplies(
  1. String receiverId,
  2. String receiverType,
  3. {Map? configuration,
  4. required dynamic onSuccess(
    1. HashMap<String, String>
    ),
  5. required dynamic onError(
    1. CometChatException e
    )}
)

Implementation

static Future<void> getSmartReplies(String receiverId, String receiverType, {Map? configuration, required Function(HashMap<String, String>) onSuccess, required Function(CometChatException e) onError}) async{
  try{
    if(receiverId.isEmpty){
      onError(CometChatException(ErrorCode.errorInvalidReceiverId, ErrorMessage.errorMessageInvalidReceiverId, ErrorMessage.errorMessageInvalidReceiverId));
    }else if(receiverType.isEmpty){
      onError(CometChatException(ErrorCode.errorInvalidReceiverType, ErrorMessage.errorMessageInvalidReceiverType, ErrorMessage.errorMessageInvalidReceiverType));
    }else{
      final arguments = {
        "receiverId": receiverId,
        "receiverType": receiverType,
        "configuration": configuration
      };
      final result = await channel.invokeMethod('getSmartReplies', arguments);
      debugPrint("result is $result");
      var hashMap = HashMap<String, String>();
      for (var entry in result.entries) {
        hashMap[entry.key as String] = entry.value as String;
      }
      onSuccess(hashMap);
    }
  } on PlatformException catch (e) {
    debugPrint("Error: $e");
    onError(CometChatException(e.code, e.details, e.message));
  } catch (e) {
    debugPrint("Error: $e");
    onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
  }
}