feat(whatsapp): mensajes automáticos semanales con proveedor intercambiable

- Puerto MessagingProvider con adaptadores OpenWA (MVP, QR) y Kapso
  (setup link de Meta + templates), elegido con WHATSAPP_PROVIDER.
- Vinculación del WhatsApp del profesor en el onboarding y en Ajustes.
- Job semanal (lunes 10:00 AR): recordatorio de pago y reenganche a
  alumnos en riesgo (cooldown 14 días), con switches por grupo.
- Idempotencia por (kind, attendee, semana ISO), webhooks firmados con
  HMAC y deduplicados, normalización de teléfonos a E.164.
- Servicio openwa en docker-compose y guía en docs/whatsapp.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-10-22 08:38:09 -03:00
parent 8c5caecdda
commit ec65c2198d
90 changed files with 6784 additions and 117 deletions

View File

@@ -114,6 +114,42 @@ export function mpProviderErrorProblem(): ProblemDetails {
};
}
/** The server is missing the variables of the active WhatsApp provider. */
export function whatsappNotConfiguredProblem(): ProblemDetails {
return {
type: `${PROBLEM_DOMAIN}/problems/whatsapp-not-configured`,
title: 'Service Unavailable',
status: 503,
detail: 'La vinculación con WhatsApp no está disponible en este momento.',
code: 'whatsapp_not_configured',
};
}
export function whatsappNotConnectedProblem(): ProblemDetails {
return conflictProblem({
detail: 'No tenés un WhatsApp vinculado.',
code: 'whatsapp_not_connected',
});
}
export function whatsappNumberInUseProblem(): ProblemDetails {
return conflictProblem({
detail: 'Ese número de WhatsApp ya está vinculado a otro profesor.',
code: 'whatsapp_number_in_use',
});
}
/** The WhatsApp gateway refused the request, or could not be reached. */
export function whatsappProviderErrorProblem(): ProblemDetails {
return {
type: `${PROBLEM_DOMAIN}/problems/whatsapp-unavailable`,
title: 'Bad Gateway',
status: 502,
detail: 'No pudimos comunicarnos con WhatsApp. Intentá de nuevo en unos minutos.',
code: 'whatsapp_provider_error',
};
}
export function onboardingAlreadyCompletedProblem(): ProblemDetails {
return conflictProblem({
detail: 'Ya completaste el onboarding de Gruperly.',

View File

@@ -34,6 +34,14 @@ export function isPublicApiRequest(method: string, path: string): boolean {
if (method === 'POST' && normalizedPath === '/api/v1/classes/notify-absence') {
return true;
}
// WhatsApp provider webhooks: no session, authenticated by their HMAC signature.
if (
method === 'POST'
&& (normalizedPath === '/api/v1/whatsapp/webhooks/openwa'
|| normalizedPath === '/api/v1/whatsapp/webhooks/kapso')
) {
return true;
}
return (
normalizedPath === '/api/v1/health'