public Task <GroupMessagesChatLogModel> PersistChatGroupMessage(GroupMessagesChatLogModel model) { throw new NotImplementedException(); }
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); } }