Skip to content

Commit

Permalink
Updated the daily email in support of #439.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Jul 13, 2024
1 parent 2d2d2f9 commit 43c5aca
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 34 deletions.
18 changes: 9 additions & 9 deletions Messaging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ public static async Task<Results<Ok<string>, NotFound<string>, BadRequest<string
if (messageRecord is not null && messageRecord.Id == id && !string.IsNullOrWhiteSpace(messageRecord.ToForward))
{
var toForward = JsonSerializer.Deserialize<ForwardedMessage>(messageRecord.ToForward);
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(toForward.To, out var toRegisteredNumber);
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(toForward?.To ?? string.Empty, out var toRegisteredNumber);

if (toForward is not null && checkTo)
{
Expand Down Expand Up @@ -1399,7 +1399,7 @@ public static async Task<Results<Ok<SendMessageResponse>, BadRequest<SendMessage
RawResponse = $"MSISDN {message?.MSISDN} could not be parsed as valid NANP (North American Numbering Plan) number.",
};

if (!string.IsNullOrWhiteSpace(message.MSISDN))
if (message is not null && !string.IsNullOrWhiteSpace(message.MSISDN))
{
bool checkFrom = PhoneNumbersNA.PhoneNumber.TryParse(message.MSISDN, out var fromPhoneNumber);
if (checkFrom && fromPhoneNumber is not null && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
Expand Down Expand Up @@ -1443,9 +1443,9 @@ public static async Task<Results<Ok<SendMessageResponse>, BadRequest<SendMessage
}
}

if (!string.IsNullOrWhiteSpace(message.To))
if (message is not null && !string.IsNullOrWhiteSpace(message.To))
{
List<string> numbers = new();
List<string> numbers = [];

string[] toParse = message.To.Split(',');
foreach (var number in toParse)
Expand Down Expand Up @@ -1501,7 +1501,7 @@ public static async Task<Results<Ok<SendMessageResponse>, BadRequest<SendMessage
{
FirstPointResponse sendMessage = new();
//Handle MMSes
if (message.MediaURLs.Length > 0 && !string.IsNullOrWhiteSpace(message.MediaURLs.FirstOrDefault()))
if (message is not null && message.MediaURLs.Length > 0 && !string.IsNullOrWhiteSpace(message.MediaURLs.FirstOrDefault()))
{
var multipartContent = new MultipartFormDataContent {
{ new StringContent(appSettings.ConnectionStrings.PComNetUsername), "username" },
Expand Down Expand Up @@ -1705,10 +1705,10 @@ public static async Task<Results<Ok<SendMessageResponse>, BadRequest<SendMessage

public class FirstPointMMS
{
public string msisdn { get; set; }
public string to { get; set; }
public string message { get; set; }
public string FullRecipientList { get; set; }
public string msisdn { get; set; } = string.Empty;
public string to { get; set; } = string.Empty;
public string message { get; set; } = string.Empty;
public string FullRecipientList { get; set; } = string.Empty;
}

public static async Task<Results<Ok<string>, BadRequest<string>, Ok<ForwardedMessage>, UnauthorizedHttpResult>>
Expand Down
39 changes: 27 additions & 12 deletions NumberSearch.Ingest/Orders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace NumberSearch.Ingest
{
public class Orders
{
public static async Task<IngestStatistics> EmailDailyAsync(IngestConfiguration appConfig)
public static async Task<IngestStatistics> EmailDailyAsync(Owned.SMSRouteChange[] smsRouteChanges, IngestConfiguration appConfig)
{
DateTime start = DateTime.Now;

var checkBriefing = await Orders.DailyBriefingEmailAsync(appConfig);
var checkBriefing = await Orders.DailyBriefingEmailAsync(smsRouteChanges, appConfig);

var combined = new IngestStatistics
{
Expand Down Expand Up @@ -51,7 +51,7 @@ public static async Task<IngestStatistics> EmailDailyAsync(IngestConfiguration a

return combined;
}
public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appConfig)
public static async Task<bool> DailyBriefingEmailAsync(Owned.SMSRouteChange[] smsRouteChanges, IngestConfiguration appConfig)
{
// Gather all of the info to put into the daily email.
var orders = await Order.GetAllAsync(appConfig.Postgresql);
Expand Down Expand Up @@ -88,7 +88,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
else if (order.Quote is false && order.Completed is false)
{
var portRequest = await PortRequest.GetByOrderIdAsync(order.OrderId, appConfig.Postgresql);
if (portRequest is not null && portRequest?.State is not "COMPLETE" && portRequest.DateSubmitted > order.DateSubmitted)
if (portRequest is not null && portRequest?.State is not "COMPLETE" && portRequest?.DateSubmitted > order.DateSubmitted)
{
ordersWithUnfinishedPortRequests.Add(order);
}
Expand All @@ -97,7 +97,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
else if (order.Quote is false && order.Completed is false)
{
var portRequest = await PortRequest.GetByOrderIdAsync(order.OrderId, appConfig.Postgresql);
if (portRequest is not null && portRequest?.State is not "COMPLETE" && portRequest.DateSubmitted < order.DateSubmitted)
if (portRequest is not null && portRequest?.State is not "COMPLETE" && portRequest?.DateSubmitted < order.DateSubmitted)
{
ordersWithUnsubmittedPortRequests.Add(order);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
var salesEmail = string.IsNullOrWhiteSpace(item.SalesEmail) ? "No sales rep assigned" : item.SalesEmail;
var installDate = item?.InstallDate is not null ? item?.InstallDate.GetValueOrDefault().ToShortDateString() : "No install date set";
var paid = item?.DateUpfrontInvoicePaid is not null && item.DateUpfrontInvoicePaid.Value > item.DateSubmitted ? $"Paid {item.DateUpfrontInvoicePaid.Value.ToShortDateString()}" : "Unpaid";
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName} - Install Date {installDate} - <strong>{paid}</strong></li>");
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName} - Install Date {installDate} - <strong>{paid}</strong></li>");
}
output.Append("</ul>");
}
Expand All @@ -163,7 +163,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
var orderName = string.IsNullOrWhiteSpace(item.BusinessName) ? $"{item.FirstName} {item.LastName}" : item.BusinessName;
var salesEmail = string.IsNullOrWhiteSpace(item.SalesEmail) ? "[email protected]" : item.SalesEmail;
var completedDate = item?.DateCompleted is not null ? item?.DateCompleted.GetValueOrDefault().ToShortDateString() : "No completed date set";
output.Append($"<li><a href='https://acceleratenetworks.com/cart/order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> submitted on {item.DateSubmitted.ToShortDateString()} - Completed on {completedDate}</li>");
output.Append($"<li><a href='https://acceleratenetworks.com/cart/order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> submitted on {item?.DateSubmitted.ToShortDateString()} - Completed on {completedDate}</li>");
}
output.Append("</ul>");
}
Expand All @@ -180,7 +180,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
var orderName = string.IsNullOrWhiteSpace(item.BusinessName) ? $"{item.FirstName} {item.LastName}" : item.BusinessName;
var salesEmail = string.IsNullOrWhiteSpace(item.SalesEmail) ? "No sales rep assigned" : item.SalesEmail;
var installDate = item?.InstallDate is not null ? item?.InstallDate.GetValueOrDefault().ToShortDateString() : "No install date set";
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a></li>");
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item?.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a></li>");
}
output.Append("</ul>");
}
Expand Down Expand Up @@ -255,6 +255,21 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
// output.Append("<li>None</li></ul>");
//}

output.Append("<p>Owned Numbers who's SMS Routing changed from yesterday:</p><ul>");
if (smsRouteChanges.Length > 0)
{
foreach (var item in smsRouteChanges)
{
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/OwnedNumbers/{item.DialedNumber}' target='_blank' rel='noopener noreferrer'>{item.DialedNumber} - Old Route: {item.OldRoute} - New Route: <strong>{item.NewRoute}</strong> - FirstCom Message: {item.Message}</li>");
}
output.Append("</ul>");
output.Append("<p>You can investigate these numbers and refresh their Upstream Status, attempt to Reregister them, and look at their current Carrier in <a href='https://ops.acceleratenetworks.com/Messaging' target='_blank' rel='noopener noreferrer'>Ops => Messaging Users</a></p>");
}
else
{
output.Append("<li>None</li></ul>");
}

output.Append("<p>Incomplete orders where the install date has passed in the last quarter:</p><ul>");
if (ordersToMarkCompleted.Count > 0)
{
Expand All @@ -263,7 +278,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
var orderName = string.IsNullOrWhiteSpace(item.BusinessName) ? $"{item.FirstName} {item.LastName}" : item.BusinessName;
var salesEmail = string.IsNullOrWhiteSpace(item.SalesEmail) ? "No sales rep assigned" : item.SalesEmail;
var installDate = item?.InstallDate is not null ? item?.InstallDate.GetValueOrDefault().ToShortDateString() : "No install date set";
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item?.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
}
output.Append("</ul>");
}
Expand All @@ -281,7 +296,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
var orderName = string.IsNullOrWhiteSpace(item.BusinessName) ? $"{item.FirstName} {item.LastName}" : item.BusinessName;
var salesEmail = string.IsNullOrWhiteSpace(item.SalesEmail) ? "No sales rep assigned" : item.SalesEmail;
var installDate = item?.InstallDate is not null ? item?.InstallDate.GetValueOrDefault().ToShortDateString() : "No install date set";
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item?.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
}
output.Append("</ul>");
}
Expand All @@ -298,7 +313,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
var orderName = string.IsNullOrWhiteSpace(item.BusinessName) ? $"{item.FirstName} {item.LastName}" : item.BusinessName;
var salesEmail = string.IsNullOrWhiteSpace(item.SalesEmail) ? "No sales rep assigned" : item.SalesEmail;
var installDate = item?.InstallDate is not null ? item?.InstallDate.GetValueOrDefault().ToShortDateString() : "No install date set";
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item?.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
}
output.Append("</ul>");
}
Expand All @@ -315,7 +330,7 @@ public static async Task<bool> DailyBriefingEmailAsync(IngestConfiguration appCo
var orderName = string.IsNullOrWhiteSpace(item.BusinessName) ? $"{item.FirstName} {item.LastName}" : item.BusinessName;
var salesEmail = string.IsNullOrWhiteSpace(item.SalesEmail) ? "No sales rep assigned" : item.SalesEmail;
var installDate = item?.InstallDate is not null ? item?.InstallDate.GetValueOrDefault().ToShortDateString() : "No install date set";
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
output.Append($"<li><a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a> - <a href=\"mailto:{item?.SalesEmail}?subject={orderName}&body=<a href='https://ops.acceleratenetworks.com/Home/Order/{item?.OrderId}' target='_blank' rel='noopener noreferrer'>{orderName}</a>\">{salesEmail}</a> - {installDate}</li>");
}
output.Append("</ul>");
}
Expand Down
Loading

0 comments on commit 43c5aca

Please sign in to comment.