/// <summary> /// Sends notification to a person /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task SendNotificationToPersonAsync(SendNotificationToPersonInput input) { var validationResults = new List <ValidationResult>(); Person person = null; if (input.PersonId == Guid.Empty) { validationResults.Add(new ValidationResult($"'{nameof(input.PersonId)}' is mandatory")); } else { person = await _personRepository.GetAll().Where(p => p.Id == input.PersonId).FirstOrDefaultAsync(); if (person == null) { validationResults.Add(new ValidationResult("Person not found")); } } if (validationResults.Any()) { throw new AbpValidationException("Failed to send message", validationResults); } var app = _firebaseApplicationProvider.GetApplication(); var messaging = FirebaseMessaging.GetMessaging(app); var devices = await _deviceRepository.GetAll().Where(d => d.Person == person).ToListAsync(); foreach (var device in devices) { try { var message = new Message() { Token = device.DeviceRegistrationId, Notification = new FirebaseAdmin.Messaging.Notification() { Body = input.Body, Title = input.Title }, Data = input.Data }; await messaging.SendAsync(message); } catch (FirebaseMessagingException e) { // } } }
/// inheritedDoc public Task SendNotificationToPersonAsync(SendNotificationToPersonInput input) { Logger.Info($"Send push notification. PersonId: {input.PersonId}, Title: {input.Title}, Body: {input.Body}"); return(Task.CompletedTask); }