public async Task <bool> SendMessageMail(string email, string subject, string messageSubject, string messageBody, string senderEmail, string senderName, string sentOn, int messageId) { var templateModel = new Dictionary <string, object> { { "sender_name", senderName }, { "title", subject }, { "body", HtmlToTextHelper.ConvertHtml(messageBody) }, //{ "attachment_details", new []{ //new Dictionary<string,object> { // { "attachmnet_url", "attachmnet_url_Value" }, // { "attachment_name", "attachment_name_Value" }, // { "attachment_size", "attachment_size_Value" }, // { "attachment_type", "attachment_type_Value" }, //} //} //}, { "action_url", $"https://resgrid.com/User/Messages/ViewMessage?messageId={messageId}" }, { "timestamp", sentOn }, { "commenter_name", senderName } }; if (SystemBehaviorConfig.OutboundEmailType == OutboundEmailTypes.Postmark) { var message = new TemplatedPostmarkMessage { From = DONOTREPLY_EMAIL, To = email, TemplateId = Config.OutboundEmailServerConfig.PostmarkMessageTemplateId, TemplateModel = templateModel, }; var client = new PostmarkClient(Config.OutboundEmailServerConfig.PostmarkApiKey); try { PostmarkResponse response = await client.SendMessageAsync(message); if (response.Status != PostmarkStatus.Success) { return(false); } return(true); } catch (Exception) { } } else { var template = Mustachio.Parser.Parse(GetTempate("Message.html")); var content = template(templateModel); Email newEmail = new Email(); newEmail.HtmlBody = content; newEmail.Sender = FROM_EMAIL; newEmail.To.Add(email); return(await _emailSender.Send(newEmail)); } return(false); }
private void SendCallViaEmailSmsGateway(Call call, string address, UserProfile profile) { MailMessage email = new MailMessage(); email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber())); email.From = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "RGCall"); email.Subject = call.Name; if (!string.IsNullOrEmpty(call.NatureOfCall)) { email.Body = HtmlToTextHelper.ConvertHtml(call.NatureOfCall); email.Body = StringHelpers.StripHtmlTagsCharArray(email.Body); } email.Body = email.Body + " " + address; if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl)) { email.Body = email.Body + " " + call.ShortenedAudioUrl; } //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl)) //{ // email.Body = email.Body + " " + call.ShortenedCallUrl; //} email.IsBodyHtml = false; _emailSender.SendEmail(email); }
public void TestConvertHtml() { var testHtml = "<h1 style=margin-top:0px;margin-bottom:0px;padding:0px;'>Just testing to see if the text message section of resgrid works</h1>"; var test = HtmlToTextHelper.ConvertHtml(testHtml); test.Should().Be("Just testing to see if the text message section of resgrid works"); }
public void SendNotification(string userId, int departmentId, string message, string departmentNumber, UserProfile profile = null) { if (profile == null) { profile = _userProfileService.GetProfileByUserId(userId); } var email = new MailMessage(); if (profile != null && profile.SendNotificationSms) { if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId)) { _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), message, departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, true, false); } else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier)) { //string departmentNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(departmentId); _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), message, departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, false); } else { email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber())); email.From = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "Resgrid"); email.Subject = "Notification"; email.Body = HtmlToTextHelper.ConvertHtml(message); email.IsBodyHtml = false; _emailSender.SendEmail(email); } } }
private string FormatTextForMessage(string title, string body) { string text = HtmlToTextHelper.ConvertHtml(body); text = StringHelpers.StripHtmlTagsCharArray(text); return(String.Format("{0} : {1}", title, text)); }
public async Task <bool> SendMessageAsync(Message message, string departmentNumber, int departmentId, UserProfile profile = null) { if (profile == null && !String.IsNullOrWhiteSpace(message.ReceivingUserId)) { profile = await _userProfileService.GetProfileByUserIdAsync(message.ReceivingUserId); } MailMessage email = new MailMessage(); if (profile != null && profile.SendMessageSms) { if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId)) { string text = HtmlToTextHelper.ConvertHtml(message.Body); text = StringHelpers.StripHtmlTagsCharArray(text); _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(message.Subject, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, true, false); } else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier)) { string text = HtmlToTextHelper.ConvertHtml(message.Body); text = StringHelpers.StripHtmlTagsCharArray(text); _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(message.Subject, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, false); } else { email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber())); email.From = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "RGMsg"); email.Subject = message.Subject; if (!string.IsNullOrEmpty(message.Body)) { email.Body = HtmlToTextHelper.ConvertHtml(message.Body); email.Body = StringHelpers.StripHtmlTagsCharArray(email.Body); } email.IsBodyHtml = false; _emailSender.SendEmail(email); } } return(true); }
public async Task <bool> SendTextAsync(string userId, string title, string message, int departmentId, string departmentNumber, UserProfile profile = null) { // TODO: This method should only be working with Twilio for inbound text message support if (profile == null) { profile = await _userProfileService.GetProfileByUserIdAsync(userId); } var email = new MailMessage(); if (profile != null && profile.SendMessageSms) { if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier)) { //string departmentNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(departmentId); _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(title, message), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, false); } else { email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber())); email.From = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "RGNot"); if (!string.IsNullOrEmpty(title)) { email.Subject = title; } if (!string.IsNullOrEmpty(message)) { email.Body = HtmlToTextHelper.ConvertHtml(message); email.Body = StringHelpers.StripHtmlTagsCharArray(email.Body); } email.IsBodyHtml = false; _emailSender.SendEmail(email); } } return(true); }
public async Task <bool> SendCallAsync(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null) { if (Config.SystemBehaviorConfig.DoNotBroadcast && !Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId)) { return(false); } if (profile == null) { profile = await _userProfileService.GetProfileByUserIdAsync(dispatch.UserId); } if (profile != null && profile.SendSms) { if (String.IsNullOrWhiteSpace(address)) { if (!String.IsNullOrWhiteSpace(call.Address)) { address = call.Address; } else if (!string.IsNullOrEmpty(call.GeoLocationData)) { try { string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { address = await _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])); } } catch { } } } if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId)) { string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall); text = StringHelpers.StripHtmlTagsCharArray(text); text = text + " " + address; if (call.Protocols != null && call.Protocols.Any()) { string protocols = String.Empty; foreach (var protocol in call.Protocols) { if (!String.IsNullOrWhiteSpace(protocol.Data)) { if (String.IsNullOrWhiteSpace(protocols)) { protocols = protocol.Data; } else { protocols = protocol + "," + protocol.Data; } } } if (!String.IsNullOrWhiteSpace(protocols)) { text = text + " (" + protocols + ")"; } } if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl)) { text = text + " " + call.ShortenedAudioUrl; } //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl)) //{ // text = text + " " + call.ShortenedCallUrl; //} _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, true, true); if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally) { SendCallViaEmailSmsGateway(call, address, profile); } } else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier)) { string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall); text = StringHelpers.StripHtmlTagsCharArray(text); text = text + " " + address; if (call.Protocols != null && call.Protocols.Any()) { string protocols = String.Empty; foreach (var protocol in call.Protocols) { if (!String.IsNullOrWhiteSpace(protocol.Data)) { if (String.IsNullOrWhiteSpace(protocols)) { protocols = protocol.Data; } else { protocols = protocol + "," + protocol.Data; } } } if (!String.IsNullOrWhiteSpace(protocols)) { text = text + " (" + protocols + ")"; } } if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl)) { text = text + " " + call.ShortenedAudioUrl; } //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl)) //{ // text = text + " " + call.ShortenedCallUrl; //} _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, true); if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally) { SendCallViaEmailSmsGateway(call, address, profile); } } else { SendCallViaEmailSmsGateway(call, address, profile); } } return(true); }
public MessageResult GetMessage(int messageId) { var department = _departmentsService.GetDepartmentById(DepartmentId, false); var savedMessage = _messageService.GetMessageById(messageId); bool outboxMessage = false; if (savedMessage != null) { if (!_authorizationService.CanUserViewMessage(UserId, savedMessage)) { Unauthorized(); } if (savedMessage.SendingUserId == UserId) { outboxMessage = true; } _messageService.ReadMessageRecipient(messageId, UserId); var message = new MessageResult(); message.Mid = savedMessage.MessageId; message.Sub = savedMessage.Subject; message.Sys = savedMessage.SystemGenerated; if (!String.IsNullOrEmpty(savedMessage.Body)) { message.Bdy = HtmlToTextHelper.ConvertHtml(savedMessage.Body); } message.Son = savedMessage.SentOn.TimeConverter(department); message.SUtc = savedMessage.SentOn; message.Typ = savedMessage.Type; message.Exp = savedMessage.ExpireOn; if (!String.IsNullOrWhiteSpace(savedMessage.SendingUserId)) { message.Uid = savedMessage.SendingUserId; } if (!outboxMessage) { var respose = savedMessage.MessageRecipients.FirstOrDefault(x => x.UserId == UserId); if (respose != null) { if (!String.IsNullOrWhiteSpace(respose.Response)) { message.Rsp = true; message.Rty = respose.Response; } message.Not = respose.Note; message.Ron = respose.ReadOn; } else { message.Ron = savedMessage.ReadOn; } message.Rcpts = new List <MessageRecipientResult>(); foreach (var recipient in savedMessage.MessageRecipients) { var recipResult = new MessageRecipientResult(); recipResult.Mid = savedMessage.MessageId; recipResult.Uid = recipient.UserId; recipResult.Rty = recipient.Response; recipResult.Not = recipient.Note; recipResult.Ron = recipient.ReadOn; message.Rcpts.Add(recipResult); } } else { message.Rcpts = new List <MessageRecipientResult>(); foreach (var recipient in savedMessage.MessageRecipients) { var recipResult = new MessageRecipientResult(); recipResult.Mid = savedMessage.MessageId; recipResult.Uid = recipient.UserId; recipResult.Rty = recipient.Response; recipResult.Not = recipient.Note; recipResult.Ron = recipient.ReadOn; message.Rcpts.Add(recipResult); } } return(message); } return(null); }
public async Task <bool> SendCallMail(string email, string subject, string title, string priority, string natureOfCall, string mapPage, string address, string dispatchedOn, int callId, string userId, string coordinates, string shortenedAudioUrl) { string callQuery = String.Empty; try { callQuery = HttpUtility.UrlEncode(SymmetricEncryption.Encrypt(callId.ToString(), Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase)); } catch { } var templateModel = new Dictionary <string, object> { { "subject", title }, { "date", dispatchedOn }, { "nature", HtmlToTextHelper.ConvertHtml(natureOfCall) }, { "priority", priority }, { "address", address }, { "map_page", mapPage }, { "action_url", $"{Config.SystemBehaviorConfig.ResgridBaseUrl}/User/Dispatch/CallExportEx?query={callQuery}" }, { "userId", userId }, { "coordinates", coordinates } }; if (!String.IsNullOrWhiteSpace(shortenedAudioUrl)) { templateModel.Add("hasCallAudio", "true"); templateModel.Add("callAudio_url", shortenedAudioUrl); } if (SystemBehaviorConfig.OutboundEmailType == OutboundEmailTypes.Postmark) { var message = new TemplatedPostmarkMessage { From = DONOTREPLY_EMAIL, To = email, TemplateId = Config.OutboundEmailServerConfig.PostmarkCallEmailTemplateId, TemplateModel = templateModel }; var client = new PostmarkClient(Config.OutboundEmailServerConfig.PostmarkApiKey); try { PostmarkResponse response = await client.SendMessageAsync(message); if (response.Status != PostmarkStatus.Success) { return(false); } return(true); } catch (Exception) { } } else { var template = Mustachio.Parser.Parse(GetTempate("Call.html")); var content = template(templateModel); Email newEmail = new Email(); newEmail.HtmlBody = content; newEmail.Sender = FROM_EMAIL; newEmail.To.Add(email); return(await _emailSender.Send(newEmail)); } return(false); }
public void SendCall(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null) { if (Config.SystemBehaviorConfig.DoNotBroadcast) { return; } if (profile == null) { profile = _userProfileService.GetProfileByUserId(dispatch.UserId); } if (profile != null && profile.SendSms) { if (String.IsNullOrWhiteSpace(address)) { if (!String.IsNullOrWhiteSpace(call.Address)) { address = call.Address; } else if (!string.IsNullOrEmpty(call.GeoLocationData)) { try { string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { address = _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])); } } catch { } } } if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId)) { string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall); text = StringHelpers.StripHtmlTagsCharArray(text); text = text + " " + address; if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl)) { text = text + " " + call.ShortenedAudioUrl; } else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl)) { text = text + " " + call.ShortenedCallUrl; } _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, true); if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally) { SendCallViaEmailSmsGateway(call, address, profile); } } else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier)) { string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall); text = StringHelpers.StripHtmlTagsCharArray(text); text = text + " " + address; if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl)) { text = text + " " + call.ShortenedAudioUrl; } else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl)) { text = text + " " + call.ShortenedCallUrl; } _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier); if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally) { SendCallViaEmailSmsGateway(call, address, profile); } } else { SendCallViaEmailSmsGateway(call, address, profile); } } }