initChat method

Future<void> initChat(
  1. EnifUserParams? params
)

Implementation

Future<void> initChat(EnifUserParams? params) async {
  if (EnifController.businessId == null) {
    throw Exception(
        'BusinessId must be set, please call "EnifController.setBusinessId("")" before calling this method');
  }
  value = value.copyWith(isLoading: true);
  var response = await _repository.initChat(InitChatDto(
      customer: params?.name ?? value.name ?? '',
      phoneNo: params?.phoneNo ?? value.phoneNo?.replaceAll(' ', '') ,
      email: params?.email ?? value.email)); // fetch from cache

  if (response.isSuccessful && response.body != null) {
    // print(response.body?.toJson());
    value = SuccessChatConnectionState(value, response.body!);
    EnifController.setChatSession(response.body!);
  } else {
    value = ErrorChatConnectionState(value, response.error as ApiError);
  }
}