diff --git a/Xtkl.NceTransferWebhooks/Program.cs b/Xtkl.NceTransferWebhooks/Program.cs index 6f5f09a..e672946 100644 --- a/Xtkl.NceTransferWebhooks/Program.cs +++ b/Xtkl.NceTransferWebhooks/Program.cs @@ -7,7 +7,7 @@ builder.Logging.ClearProviders(); builder.Logging.AddConsole(); -//builder.Logging.SetMinimumLevel(LogLevel.Debug); +builder.Logging.SetMinimumLevel(LogLevel.Debug); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); @@ -19,7 +19,7 @@ app.UseHttpsRedirection(); -app.MapPost("/transfer-completed", async (CompleteTransferDto request, IConfiguration config) => +app.MapPost("/transfer-completed-us", async (CompleteTransferDto request, IConfiguration config) => { var apiKey = config["SendGrid:ApiKey"]; var fromEmail = config["SendGrid:FromEmail"]; @@ -31,7 +31,7 @@ { var client = new SendGridClient(apiKey); var from = new EmailAddress(fromEmail, fromName); - var subject = "NCE Transfer Completed"; + var subject = "NCE Transfer Completed - US"; var to = new EmailAddress(toEmail, toName); var htmlContent = $@" @@ -60,7 +60,7 @@ var jsonContent = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"); - var endpointUrl = "https://prod-15.canadacentral.logic.azure.com:443/workflows/3250236be48d4b069d080a5330250daf/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=zFc34-bcFhnnwPF-KttUgZZRIbh7RZT95_smn5MHrcw"; + var endpointUrl = config["Transfer:CumulusEndpoint"]; var httpResponse = await httpClient.PostAsync(endpointUrl, jsonContent); @@ -73,7 +73,64 @@ return Results.Problem($"Error sending email: {ex.Message}"); } }) - .WithName("TransferCompleted") + .WithName("TransferCompletedUsa") + .WithOpenApi(); + +app.MapPost("/transfer-completed-ca", async (CompleteTransferDto 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:

+ + + +

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); + + var httpClient = new HttpClient(); + + var jsonContent = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"); + + var endpointUrl = config["Transfer:CumulusEndpoint"]; + + var httpResponse = await httpClient.PostAsync(endpointUrl, jsonContent); + + return httpResponse.IsSuccessStatusCode + ? Results.Ok("Notification sent successfully.") + : Results.Problem("Error sending data to external endpoint."); + } + catch (Exception ex) + { + return Results.Problem($"Error sending email: {ex.Message}"); + } +}) + .WithName("TransferCompletedCanada") .WithOpenApi(); app.Run();