private void ServiceNotification(NotificationPhone phone) { if (phone.PhoneCell != null && !string.IsNullOrEmpty(phone.PhoneCell.ToString())) { var phoneNumber = Regex.Replace(phone.PhoneCell.InternationalPhoneNumber, @"\s+", ""); _twilioMessagingService.SendMessaging(phoneNumber, phone.Message); } else { _logger.Error(string.Format("Phone number can not be null or empty user id: {0}", phone.UserId)); throw new Exception("Phone number can not be null or empty"); } }
public Notification NotifyViaSmsImmediate <T>(string notificationTypeAlias, string smsTemplateAlias, T model, long userId, long requestedBy, string source, string notes = null, int priority = 0, DateTime?notificationDate = null, bool sendBeforeSavingToDb = false) { var notificationType = _notificationTypeRepository.GetByAlias(notificationTypeAlias); if (!notificationType.IsQueuingEnabled) { return(null); } var emailTemplate = _emailTemplateRepository.GetByAlias(smsTemplateAlias); var notificationSubscriber = GetUserToNotify(userId); var formatMessage = _emailTemplateFormatter.FormatMessage(emailTemplate, model, emailTemplate.Id); var notificationSms = _notificationEmailFactory.CreateSmsNotification(notificationType, notificationSubscriber, formatMessage, source, userId, requestedBy); if (sendBeforeSavingToDb) { try { var phoneNumber = Regex.Replace(notificationSubscriber.CellNumber.InternationalPhoneNumber, @"\s+", ""); _twilioMessagingService.SendMessaging(phoneNumber, formatMessage.Body); notificationSms.ServiceStatus = NotificationServiceStatus.Serviced; notificationSms.AttemptCount = 1; notificationSms.ServicedDate = _calendar.Now; } catch { } } if (notificationDate != null) { notificationSms.NotificationDate = notificationDate.Value; } var notification = _notificationRepository.Save(notificationSms); return(notification); }