askBot static method

Future<void> askBot(
  1. String receiverId,
  2. String receiverType,
  3. String botId,
  4. String question,
  5. {Map? configuration,
  6. required dynamic onSuccess(
    1. String conversationSummary
    ),
  7. required dynamic onError(
    1. CometChatException e
    )}
)

Implementation

static Future<void> askBot(String receiverId, String receiverType, String botId, String question, {Map? configuration, required Function(String conversationSummary) 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 if(botId.isEmpty){
      onError(CometChatException(ErrorCode.errorEmptyBotID, ErrorMessage.errorEmptyBotID, ErrorMessage.errorEmptyBotID));
    }else if(question.isEmpty){
      onError(CometChatException(ErrorCode.errorEmptyAskBotQuestion, ErrorMessage.errorEmptyBotID, ErrorMessage.errorEmptyBotID));
    }else{
      final arguments = {
        "receiverId": receiverId,
        "receiverType": receiverType,
        "configuration": configuration,
        "question": question,
        "botId": botId
      };
      final result = await channel.invokeMethod('askBot', arguments);
      String stringResult = result;
      onSuccess(stringResult);
    }
  } 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()));
  }
}