diff --git a/Xtkl.NceTransferWebhooks/Program.cs b/Xtkl.NceTransferWebhooks/Program.cs index df9ec0c..8d57f83 100644 --- a/Xtkl.NceTransferWebhooks/Program.cs +++ b/Xtkl.NceTransferWebhooks/Program.cs @@ -11,6 +11,9 @@ using Xtkl.NceTransferWebhooks.DTOs; using Xtkl.NceTransferWebhooks.Model; +const string EVENT_COMPLETE_TRANSFER = "complete-transfer"; +const string EVENT_FAIL_TRANSFER = "fail-transfer"; + var builder = WebApplication.CreateBuilder(args); builder.Logging.ClearProviders(); @@ -83,13 +86,13 @@ .WithMetadata(new SwaggerResponseAttribute(500, "Internal server error - unexpected error occurred")) .WithOpenApi(); -app.MapPost("/transfer-completed-us", async (TransferWebhookDto request, IConfiguration config) => +app.MapPost("/transfer-webhook-us", async (TransferWebhookDto request, IConfiguration config) => { try { - var transfer = await GetTransfer(request.AuditUri, TransferStatus.Complete, TenantRegion.US, config); + var transfer = await GetTransfer(request.AuditUri, TenantRegion.US, config); - await SendEmail(transfer, TenantRegion.US, config); + await SendEmail(transfer, request.EventName, TenantRegion.US, config); return await SendToCumulus(transfer, config); } @@ -98,16 +101,16 @@ return Results.Problem($"Error: {ex.Message}"); } }) - .WithName("TransferCompletedUsa") + .WithName("TransferWebhookUsa") .WithOpenApi(); -app.MapPost("/transfer-completed-ca", async (TransferWebhookDto request, IConfiguration config) => +app.MapPost("/transfer-webhook-ca", async (TransferWebhookDto request, IConfiguration config) => { try { - var transfer = await GetTransfer(request.AuditUri, TransferStatus.Complete, TenantRegion.CA, config); + var transfer = await GetTransfer(request.AuditUri, TenantRegion.CA, config); - await SendEmail(transfer, TenantRegion.CA, config); + await SendEmail(transfer, request.EventName, TenantRegion.CA, config); return await SendToCumulus(transfer, config); } @@ -116,113 +119,14 @@ return Results.Problem($"Error: {ex.Message}"); } }) - .WithName("TransferCompletedCanada") - .WithOpenApi(); - -app.MapPost("/transfer-failed-ca", async (TransferWebhookDto request, IConfiguration config) => - { - var apiKey = config["SendGrid:ApiKey"]; - var fromEmail = config["SendGrid:FromEmail"]; - var fromName = config["SendGrid:FromName"]; - var toEmail = config["SendGrid:ToEmail"]; - var toName = config["SendGrid:ToName"]; - - try - { - var client = new SendGridClient(apiKey); - var from = new EmailAddress(fromEmail, fromName); - var subject = "NCE Transfer Completed - CA"; - var to = new EmailAddress(toEmail, toName); - - var htmlContent = $@" - -
-Team,
-We would like to inform you that the NCE transfer process has been successfully completed. Please find the details below:
- -{JsonSerializer.Serialize(request)}
- -If you have any questions or need further assistance, please don’t hesitate to reach out.
- -Best regards,
- Sherweb Support Team
-
- ";
-
- var msg = MailHelper.CreateSingleEmail(from, to, subject, null, htmlContent);
-
- await client.SendEmailAsync(msg);
-
- return Results.Ok("Notification sent successfully.");
-
- }
- catch (Exception ex)
- {
- return Results.Problem($"Error: {ex.Message}");
- }
- })
- .WithName("TransferFailedCanada")
+ .WithName("TransferWebhookCanada")
.WithOpenApi();
-app.MapPost("/transfer-failed-us", async (TransferWebhookDto request, IConfiguration config) =>
- {
- var apiKey = config["SendGrid:ApiKey"];
- var fromEmail = config["SendGrid:FromEmail"];
- var fromName = config["SendGrid:FromName"];
- var toEmail = config["SendGrid:ToEmail"];
- var toName = config["SendGrid:ToName"];
-
- try
- {
- var client = new SendGridClient(apiKey);
- var from = new EmailAddress(fromEmail, fromName);
- var subject = "NCE Transfer Completed - US";
- var to = new EmailAddress(toEmail, toName);
-
- var htmlContent = $@"
-
-
Team,
-We would like to inform you that the NCE transfer process has been successfully completed. Please find the details below:
- -{JsonSerializer.Serialize(request)}
- -If you have any questions or need further assistance, please don’t hesitate to reach out.
- -Best regards,
- Sherweb Support Team
-
- ";
-
- var msg = MailHelper.CreateSingleEmail(from, to, subject, null, htmlContent);
-
- await client.SendEmailAsync(msg);
-
- return Results.Ok("Notification sent successfully.");
-
- }
- catch (Exception ex)
- {
- return Results.Problem($"Error: {ex.Message}");
- }
- })
- .WithName("TransferFailedUsa")
- .WithOpenApi();
app.Run();
#region Private
-async Task