initChat method
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);
}
}