public async Task <bool> SendMessageAsync(Message message, string sendersName, string departmentNumber, int departmentId, UserProfile profile = null) { if (profile == null && !String.IsNullOrWhiteSpace(message.ReceivingUserId)) { profile = await _userProfileService.GetProfileByUserIdAsync(message.ReceivingUserId); } if (profile == null || profile.SendMessageSms) { try { await _smsService.SendMessageAsync(message, departmentNumber, departmentId, profile); } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendMessageEmail) { try { await _emailService.SendMessageAsync(message, sendersName, profile, message.ReceivingUser); } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendMessagePush) { var spm = new StandardPushMessage(); spm.MessageId = message.MessageId; if (message.SystemGenerated) { spm.SubTitle = "Msg from System"; } else { spm.SubTitle = string.Format("Msg from {0}", sendersName); } spm.Title = "Msg:" + message.Subject.Truncate(200); if (!String.IsNullOrWhiteSpace(message.ReceivingUserId)) { await _pushService.PushMessage(spm, message.ReceivingUserId, profile); } else { await _pushService.PushMessage(spm, String.Empty, profile); } } return(true); }
public void SendNotification(string userId, int departmentId, string message, string departmentNumber, string title = "Notification", UserProfile profile = null) { if (profile == null) { profile = _userProfileService.GetProfileByUserId(userId, false); } if (profile == null || profile.SendNotificationSms) { try { #pragma warning disable 4014 Task.Run(() => { _smsService.SendNotification(userId, departmentId, $"{title} {message}", departmentNumber, profile); }) .ConfigureAwait(false); #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendNotificationEmail) { try { #pragma warning disable 4014 Task.Run(() => { _emailService.SendNotification(userId, $"{title} {message}", profile); }).ConfigureAwait(false); #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendNotificationPush) { var spm = new StandardPushMessage(); spm.Title = "Notification"; spm.SubTitle = $"{title} {message}"; try { #pragma warning disable 4014 Task.Run(async() => { await _pushService.PushNotification(spm, userId, profile); }).ConfigureAwait(false); #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } }
public async Task <bool> SendChat(string chatId, string sendingUserId, string group, string message, UserProfile sendingUser, List <UserProfile> recipients) { var spm = new StandardPushMessage(); if (recipients.Count == 1) { spm.Title = $"New Chat Message from {sendingUser.FullName.AsFirstNameLastName}"; spm.SubTitle = $"Chat: {sendingUser.LastName}: " + message; } else { spm.Title = $"New Chat Message in Group {group} from {sendingUser.FullName.AsFirstNameLastName}"; spm.SubTitle = $"Chat {group}: {sendingUser.LastName}: " + message; } try { if (recipients.Count == 1) { var sendingTo = recipients.FirstOrDefault(); spm.Id = $"T{sendingTo}"; if (sendingTo != null) { await _pushService.PushChat(spm, sendingTo.UserId, sendingTo); } } else { spm.Id = $"G{chatId}"; await recipients.ParallelForEachAsync(async person => { try { await _pushService.PushChat(spm, person.UserId, person); } catch (Exception ex) { Logging.LogException(ex); } }); } } catch (Exception ex) { Logging.LogException(ex); } return(true); }
public async Task <bool> SendNotificationAsync(string userId, int departmentId, string message, string departmentNumber, string title = "Notification", UserProfile profile = null) { if (profile == null) { profile = await _userProfileService.GetProfileByUserIdAsync(userId, false); } if (profile == null || profile.SendNotificationSms) { try { await _smsService.SendNotificationAsync(userId, departmentId, $"{title} {message}", departmentNumber, profile); } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendNotificationEmail) { try { await _emailService.SendNotificationAsync(userId, $"{title} {message}", profile); } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendNotificationPush) { var spm = new StandardPushMessage(); spm.Title = "Notification"; spm.SubTitle = $"{title} {message}"; try { await _pushService.PushNotification(spm, userId, profile); } catch (Exception ex) { Logging.LogException(ex); } } return(true); }
public async Task <bool> PushChat(StandardPushMessage message, string userId, UserProfile profile = null) { if (message == null) { return(false); } if (profile == null) { profile = await _userProfileService.GetProfileByUserIdAsync(userId); } if (profile != null && profile.SendMessagePush) { await _notificationProvider.SendAllNotifications(message.Title, message.SubTitle, userId, message.Id, ((int)PushSoundTypes.Message).ToString(), profile.CustomPushSounds, 1, "#000000"); } return(true); }
public async Task <bool> PushNotification(StandardPushMessage message, string userId, UserProfile profile = null) { if (message == null) { return(false); } if (profile == null) { profile = _userProfileService.GetProfileByUserId(userId); } if (profile != null && profile.SendNotificationPush) { await _notificationProvider.SendAllNotifications(message.Title, message.SubTitle, userId, string.Format("N{0}", message.MessageId), ((int)PushSoundTypes.Notifiation).ToString(), profile.CustomPushSounds, 1, "#000000"); } return(true); }
public void SendMessage(Message message, string sendersName, string departmentNumber, int departmentId, UserProfile profile = null) { if (profile == null && !String.IsNullOrWhiteSpace(message.ReceivingUserId)) { profile = _userProfileService.GetProfileByUserId(message.ReceivingUserId); } if (profile == null || profile.SendMessageSms) { try { _smsService.SendMessage(message, departmentNumber, departmentId, profile); } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendMessageEmail) { try { _emailService.SendMessage(message, sendersName, profile, message.ReceivingUser); } catch (Exception ex) { Logging.LogException(ex); } } if (profile == null || profile.SendMessagePush) { var spm = new StandardPushMessage(); spm.MessageId = message.MessageId; if (message.SystemGenerated) { spm.SubTitle = "Msg from System"; } else { spm.SubTitle = string.Format("Msg from {0}", sendersName); } spm.Title = "Msg:" + message.Subject.Truncate(200); try { if (!String.IsNullOrWhiteSpace(message.ReceivingUserId)) #pragma warning disable 4014 { Task.Run(async() => { await _pushService.PushMessage(spm, message.ReceivingUserId, profile); }).ConfigureAwait(false); } #pragma warning restore 4014 else #pragma warning disable 4014 { Task.Run(async() => { await _pushService.PushMessage(spm, String.Empty, profile); }).ConfigureAwait(false); } #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } }