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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ SEED_ADMIN_PASSWORD=SuaSenhaAdmin123!

# WhatsApp via Meta Cloud API (opcional — NullWhatsAppNotifier se PhoneNumberId/AccessToken vazios)
# Onde pegar: Meta App > WhatsApp > API Setup (PhoneNumberId, token), App > Settings > Basic (AppSecret).
#
# WHATSAPP_HABILITADO: kill-switch explícito. false (default) = NullWhatsAppNotifier SEMPRE,
# mesmo com credenciais válidas configuradas. Só true reativa o envio real.
# WHATSAPP_HABILITADO=false
# WHATSAPP_PHONE_NUMBER_ID=<phone-number-id-do-meta>
# WHATSAPP_ACCESS_TOKEN=<token-permanente-do-meta> # System User token (não o temporário de 24h)
# WHATSAPP_API_VERSION=v21.0
Expand Down
1 change: 1 addition & 0 deletions docker-compose.homolog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
Seed__ZapTestEmail: ${SEED_ZAP_TEST_EMAIL:-zap-test@forzion.tech}
Seed__ZapTestPassword: ${SEED_ZAP_TEST_PASSWORD:-}
# WhatsApp via Meta Cloud API (opcional — PhoneNumberId+AccessToken vazios → NullWhatsAppNotifier)
WhatsApp__Habilitado: ${WHATSAPP_HABILITADO:-false}
WhatsApp__PhoneNumberId: ${WHATSAPP_PHONE_NUMBER_ID:-}
WhatsApp__AccessToken: ${WHATSAPP_ACCESS_TOKEN:-}
WhatsApp__ApiVersion: ${WHATSAPP_API_VERSION:-v21.0}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
Seed__AdminPassword: ${SEED_ADMIN_PASSWORD:-}
Seed__ZapTestEmail: ${SEED_ZAP_TEST_EMAIL:-zap-test@forzion.tech}
Seed__ZapTestPassword: ${SEED_ZAP_TEST_PASSWORD:-}
WhatsApp__Habilitado: ${WHATSAPP_HABILITADO:-false}
WhatsApp__PhoneNumberId: ${WHATSAPP_PHONE_NUMBER_ID:-}
WhatsApp__AccessToken: ${WHATSAPP_ACCESS_TOKEN:-}
WhatsApp__ApiVersion: ${WHATSAPP_API_VERSION:-v21.0}
Expand Down
3 changes: 3 additions & 0 deletions forzion.tech.Api/Endpoints/Pagamentos/WebhookEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public static IEndpointRouteBuilder MapWebhookEndpoints(this IEndpointRouteBuild
[FromServices] ILogger<ProcessarWebhookWhatsAppHandler> logger,
CancellationToken cancellationToken) =>
{
if (!configuration.GetValue<bool>("WhatsApp:Habilitado"))
return Results.Ok();

httpContext.Request.Body = new LimitedStream(httpContext.Request.Body, MaxWebhookBodyBytes);

using var reader = new StreamReader(httpContext.Request.Body);
Expand Down
3 changes: 3 additions & 0 deletions forzion.tech.Application/Settings/WhatsAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace forzion.tech.Application.Settings;
/// </summary>
public class WhatsAppSettings
{
/// <summary>Kill-switch explícito. Default false: DI força <c>NullWhatsAppNotifier</c> mesmo com credenciais presentes.</summary>
public bool Habilitado { get; set; }

public bool MarcarComoTeste { get; set; }

/// <summary>CSV de telefones (E.164). Em não-prod, redireciona o destinatário p/ o 1º alvo.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ public static IServiceCollection AddInfrastructure(
// WhatsApp notifier — Meta Cloud API when configured, no-op otherwise. Sempre
// embrulhado no EnvironmentWhatsAppDecorator: passthrough em prod, redirect/allowlist
// de telefone em não-prod.
var whatsAppHabilitado = configuration.GetValue<bool>("WhatsApp:Habilitado");
var whatsAppPhoneNumberId = configuration["WhatsApp:PhoneNumberId"];
var whatsAppAccessToken = configuration["WhatsApp:AccessToken"];
var whatsAppApiVersion = configuration["WhatsApp:ApiVersion"] ?? "v21.0";
if (!string.IsNullOrWhiteSpace(whatsAppPhoneNumberId) && !string.IsNullOrWhiteSpace(whatsAppAccessToken))
if (whatsAppHabilitado && !string.IsNullOrWhiteSpace(whatsAppPhoneNumberId) && !string.IsNullOrWhiteSpace(whatsAppAccessToken))
{
services.AddHttpClient<MetaWhatsAppCloudNotifier>(client =>
{
Expand Down
3 changes: 3 additions & 0 deletions forzion.tech.Infrastructure/Health/WhatsAppHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public async Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
CancellationToken cancellationToken = default)
{
if (!configuration.GetValue<bool>("WhatsApp:Habilitado"))
return HealthCheckResult.Healthy("WhatsApp desativado temporariamente.");

var phoneNumberId = configuration["WhatsApp:PhoneNumberId"];
var accessToken = configuration["WhatsApp:AccessToken"];

Expand Down
Loading
Loading