Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//+:cnd:noEmit
using Twilio.Rest.Api.V2010;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace Boilerplate.Server.Api.Infrastructure.Services;

/// <summary>
/// Checks Twilio SMS service connectivity by fetching account info.
/// </summary>
public partial class TwilioHealthCheck : IHealthCheck
{
[AutoInject] private ServerApiSettings settings = default!;

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
if (settings.Sms?.Configured is not true)
return HealthCheckResult.Healthy("Twilio SMS is not configured — skipping check.");
Comment thread
msynk marked this conversation as resolved.

var account = await AccountResource.FetchAsync();

Comment thread
msynk marked this conversation as resolved.
return account.Status == AccountResource.StatusEnum.Active
? HealthCheckResult.Healthy("Twilio account is active.")
: HealthCheckResult.Degraded($"Twilio account status: {account.Status}.");
}
catch (Exception exp)
{
return HealthCheckResult.Unhealthy("Twilio SMS health check failed.", exp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static void AddServerApiProjectServices(this WebApplicationBuilder builde
builder.AddDefaultHealthChecks()
.AddDbContextCheck<AppDbContext>(tags: ["live"])
.AddHangfire(setup => setup.MinimumAvailableServers = 1, tags: ["live"])
.AddCheck<AppStorageHealthCheck>("storage", tags: ["live"]);
.AddCheck<AppStorageHealthCheck>("storage", tags: ["live"])
.AddCheck<TwilioHealthCheck>("sms", tags: ["live"]); ;
// TODO: Sms, Email, Push notification, AI, Google reCaptcha, Cloudflare

ServerApiSettings appSettings = new();
Expand Down
Loading