public async Task SendMessage(MessageAbstractionModel model) { if (model.RecipientTelephone != null) { //We remove the html properties model.BodyMessage = model.BodyMessage.Replace("<br/>", "\n\n"); string to = model.RecipientTelephone; await _smsProvider.SendMessageAsync(to, $"{model.AboutStudent.StudentName}: {model.Subject}", model.BodyMessage); } }
public async Task SendMessage(MessageAbstractionModel model) { //We remove the html properties model.BodyMessage = StripHTML(model.BodyMessage); await _pushNotificationProvider.SendNotificationAsync(new NotificationItemModel { personUniqueId = model.RecipientUniqueId, personType = "Parent", notification = new Notification { title = model.Subject, body = model.BodyMessage } }); }
public async Task SendMessage(MessageAbstractionModel model) { string legendBottom = "Please do not reply to this message, as this email inbox is not monitored. To contact us, visit <a href=\"https://familyportal.yesprep.org\">https://familyportal.yesprep.org</a> ."; string signByDefault = $"This message was sent from the YES Prep Family Portal on behalf of {model.SenderName}."; var legentBottomTranslate = new Hashtable(); var signByDefaultTranslate = new Hashtable(); if (string.IsNullOrEmpty(model.LanguageCode)) { model.LanguageCode = "en"; } if (!legentBottomTranslate.ContainsKey(model.LanguageCode)) { var legentBottomTrans = await TranslateText(legendBottom, model.LanguageCode); legentBottomTranslate.Add(model.LanguageCode, legentBottomTrans); } var translatedLegentBottom = legentBottomTranslate[model.LanguageCode].ToString(); if (!signByDefaultTranslate.ContainsKey(model.LanguageCode)) { var signByDefaultTrans = await TranslateText(signByDefault, model.LanguageCode); signByDefaultTranslate.Add(model.LanguageCode, signByDefaultTrans); } var translatedSignByDefault = signByDefaultTranslate[model.LanguageCode].ToString(); if (model.RecipientEmail != null) { model.BodyMessage = $"{model.BodyMessage} <br/> <br/> {translatedLegentBottom} <br/> {translatedSignByDefault}"; await _messagingProvider.SendMessageAsync(model.RecipientEmail, null, null, $"{model.AboutStudent.StudentName}: {model.Subject}", model.BodyMessage); } }
private async Task SendGroupMessageHandler(StudentParentAssociationModel model, string personUniqueId, string translatedMessage, string translatedSubject, string englishMessage, string englishSubject, string staffName, string studentName, string studentUniqueId, Guid queueId, string LanguageCode) { string ErrorMessage = string.Empty; ChatLogItemModel resultModel = new ChatLogItemModel(); try { // Based on current specification the message should be persisted in the chat log // and then to the preferred method of contact. // Fall back logic: Try to send to "preferred method of contact" if none is defined fall back to email. resultModel = await PersistMessage(new ChatLogItemModel { SenderTypeId = ChatLogPersonTypeEnum.Staff.Value, SenderUniqueId = personUniqueId, RecipientUniqueId = model.Parent.ParentUniqueId, RecipientTypeId = ChatLogPersonTypeEnum.Parent.Value, // By default we should mark them as read in the chat log. RecipientHasRead = true, EnglishMessage = $"{englishSubject}: {StripHTML(englishMessage)}", StudentUniqueId = studentUniqueId, TranslatedMessage = LanguageCode != "en" ? $"{translatedSubject}: {StripHTML(translatedMessage)}" : null, TranslatedLanguageCode = LanguageCode != "en" ? LanguageCode : null }); var subjectToSend = LanguageCode != "en" ? translatedSubject : englishSubject; var messageMetadata = new MessageAbstractionModel { SenderName = staffName, SenderUniqueId = personUniqueId, RecipientUniqueId = model.Parent.ParentUniqueId, RecipientEmail = model.Parent.Email, RecipientTelephone = model.Parent.Telephone, RecipientTelephoneSMSDomain = model.Parent.SMSDomain, Subject = subjectToSend, BodyMessage = LanguageCode != "en" ? translatedMessage : englishMessage, AboutStudent = new StudentMessageAbstractModel { StudentUniqueId = studentUniqueId, StudentName = studentName }, DelivaryMethod = model.Parent.ParentAlert.PreferredMethodOfContactTypeId.Value, LanguageCode = LanguageCode }; //Should use the provider for the Preferred Method of contact by parent var messageProvider = _messageProviders.SingleOrDefault(x => x.DeliveryMethod == messageMetadata.DelivaryMethod); await messageProvider.SendMessage(messageMetadata); } catch (Exception ex) { ErrorMessage = ex.Message; } finally { var chatLogModel = new GroupMessagesChatLogModel { GroupMessagesLogId = queueId, ChatLogId = resultModel.ChatId, Status = GroupMessagesStatusEnum.Sent }; if (!string.IsNullOrEmpty(ErrorMessage)) { chatLogModel.Status = GroupMessagesStatusEnum.Error; chatLogModel.ErrorMessage = ErrorMessage; await _communicationsRepository.PersistChatGroupMessage(chatLogModel); throw new Exception(ErrorMessage); } await _communicationsRepository.PersistChatGroupMessage(chatLogModel); } }