Skip to content

Commit

Permalink
Merge pull request #5 from sherweb/TenantsWebhooks
Browse files Browse the repository at this point in the history
Specific endpoints for each tenant
  • Loading branch information
asantossheweb authored Nov 8, 2024
2 parents 5f01bb4 + 6482a63 commit c2e9974
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions Xtkl.NceTransferWebhooks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"];
Expand All @@ -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 = $@"
Expand Down Expand Up @@ -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);
Expand All @@ -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 = $@"
<html>
<body>
<p>Team,</p>
<p>We would like to inform you that the NCE transfer process has been successfully completed. Please find the details below:</p>
<ul style='list-style-type:none; padding: 0;'>
<li><strong>Resource URI:</strong> {request.ResourceUri}</li>
<li><strong>Date of Change (UTC):</strong> {request.ResourceChangeUtcDate.ToString("u")}</li>
</ul>
<p>If you have any questions or need further assistance, please don’t hesitate to reach out.</p>
<p>Best regards,<br/>
<strong>Sherweb Support Team</strong>
</body>
</html>";
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();
Expand Down

0 comments on commit c2e9974

Please sign in to comment.