Merge pull request 'feat(automation): integrate n8n webhook notifications for guestbook and contact form' (#7) from feature/n8n-smart-notifications into develop
CI Pipeline - Quality & Build / Build & Validate Frontend (push) Successful in 38s Details
CI Pipeline - Quality & Build / Build & Test Backend (.NET) (push) Successful in 22s Details

This commit is contained in:
Bryan.bano 2026-10-20 15:50:54 +00:00
commit f604091091
5 changed files with 72 additions and 8 deletions

View File

@ -0,0 +1,6 @@
import { InjectionToken } from '@angular/core';
export const NOTIFY_WEBHOOK_URL = new InjectionToken<string>('NOTIFY_WEBHOOK_URL', {
providedIn: 'root',
factory: () => 'https://n8n.bryan-bano.com/webhook/portfolio-notify'
});

View File

@ -4,6 +4,7 @@ import { Observable, catchError, of, tap } from 'rxjs';
import { GuestbookPort } from '../../domain/ports/guestbook.port';
import { CreateGuestbookRequest, GuestbookEntry } from '../../domain/models/guestbook.model';
import { API_BASE_URL } from '../../core/tokens/api-config.token';
import { NOTIFY_WEBHOOK_URL } from '../../core/tokens/notify-config.token';
const STORAGE_KEY = 'zen_guestbook_entries_cache';
@ -37,6 +38,7 @@ const INITIAL_MOCK_ENTRIES: GuestbookEntry[] = [
export class HttpGuestbookAdapter implements GuestbookPort {
private readonly http = inject(HttpClient);
private readonly baseUrl = inject(API_BASE_URL);
private readonly notifyWebhookUrl = inject(NOTIFY_WEBHOOK_URL);
getEntries(limit: number = 50): Observable<GuestbookEntry[]> {
return this.http.get<GuestbookEntry[]>(`${this.baseUrl}/guestbook?limit=${limit}`).pipe(
@ -46,6 +48,8 @@ export class HttpGuestbookAdapter implements GuestbookPort {
}
createEntry(request: CreateGuestbookRequest): Observable<GuestbookEntry> {
this.dispatchN8nNotification(request);
return this.http.post<GuestbookEntry>(`${this.baseUrl}/guestbook`, request).pipe(
tap(created => {
const cached = this.loadFromCache();
@ -67,6 +71,23 @@ export class HttpGuestbookAdapter implements GuestbookPort {
);
}
private dispatchN8nNotification(request: CreateGuestbookRequest): void {
try {
this.http.post(this.notifyWebhookUrl, {
eventType: 'GUESTBOOK_SIGNATURE',
senderName: request.senderName,
senderContact: request.senderContact || 'Firma de Visitante Web',
message: request.message,
serviceType: request.origin ?? 'WebForm'
}).subscribe({
next: () => {},
error: () => {}
});
} catch {
// Ignorar fallos de red en notificación
}
}
private loadFromCache(): GuestbookEntry[] {
if (typeof localStorage === 'undefined') return INITIAL_MOCK_ENTRIES;
const raw = localStorage.getItem(STORAGE_KEY);

View File

@ -26,8 +26,12 @@
{{ currentEndpoint().method }}
</div>
<div class="url-text font-mono">
<span class="url-host">api.bryan-bano.com</span>
<span class="url-path">{{ currentEndpoint().path }}</span>
@if (currentEndpoint().path.startsWith('http')) {
<span class="url-path">{{ currentEndpoint().path }}</span>
} @else {
<span class="url-host">api.bryan-bano.com</span>
<span class="url-path">{{ currentEndpoint().path }}</span>
}
</div>
<button
type="button"

View File

@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { API_BASE_URL } from '../../../core/tokens/api-config.token';
export type ApiEndpointKey = 'telemetry' | 'projects' | 'guestbook' | 'sign' | 'ping';
export type ApiEndpointKey = 'telemetry' | 'projects' | 'guestbook' | 'sign' | 'n8n_notify' | 'ping';
export interface ApiEndpointDef {
readonly key: ApiEndpointKey;
@ -50,6 +50,20 @@ export const API_ENDPOINTS: readonly ApiEndpointDef[] = [
badgeTag: 'DEV_ZEN'
}
},
{
key: 'n8n_notify',
method: 'POST',
path: 'https://n8n.bryan-bano.com/webhook/portfolio-notify',
title: 'n8n AI Push Dispatcher',
description: 'Dispara triage cognitivo con IA y notificación instantánea a Telegram de Bryan',
sampleBody: {
eventType: 'LEAD_PROSPECT_ALERT',
senderName: 'Director de Ingeniería (Headhunting)',
senderContact: 'hiring@tech-scale.io',
serviceType: 'Contratación Senior .NET / Angular',
message: 'Revisamos tu portafolio y queremos agendar una entrevista técnica inmediata para un rol remoto.'
}
},
{
key: 'ping',
method: 'GET',
@ -111,7 +125,7 @@ export class ApiExplorerComponent {
const startTime = performance.now();
const endpoint = this.currentEndpoint();
const targetUrl = `${this.baseUrl}${endpoint.path}`;
const targetUrl = endpoint.path.startsWith('http') ? endpoint.path : `${this.baseUrl}${endpoint.path}`;
// Animación visual secuencial de paquetes
setTimeout(() => {

View File

@ -15,8 +15,10 @@ import {
FormControl,
Validators
} from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { I18nService } from '../../../application/services/i18n.service';
import { GuestbookComponent } from '../guestbook/guestbook.component';
import { NOTIFY_WEBHOOK_URL } from '../../../core/tokens/notify-config.token';
interface DigitalRainColumn {
x: number;
@ -44,6 +46,8 @@ export class ContactSectionComponent implements OnInit, AfterViewInit, OnDestroy
@ViewChild('rainCanvas') private readonly rainCanvas?: ElementRef<HTMLCanvasElement>;
protected readonly i18n = inject(I18nService);
private readonly http = inject(HttpClient);
private readonly notifyWebhookUrl = inject(NOTIFY_WEBHOOK_URL);
// Estado reactivo del formulario con Signals
protected readonly isSubmitting = signal(false);
@ -267,10 +271,25 @@ export class ContactSectionComponent implements OnInit, AfterViewInit, OnDestroy
this.errorMessage.set(null);
this.isSubmitting.set(true);
setTimeout(() => {
this.isSubmitting.set(false);
this.isSuccess.set(true);
}, 600);
const formData = this.contactForm.getRawValue();
this.http.post(this.notifyWebhookUrl, {
eventType: 'CONTACT_FORM',
senderName: formData.fullNameOrCompany,
senderContact: formData.email + (formData.phone ? ` | Tel: ${formData.phone}` : ''),
serviceType: formData.serviceType || 'General',
message: formData.projectDetails
}).subscribe({
next: () => {
this.isSubmitting.set(false);
this.isSuccess.set(true);
},
error: () => {
// En caso de fallo de red en webhook, la experiencia del usuario no se interrumpe
this.isSubmitting.set(false);
this.isSuccess.set(true);
}
});
}
resetForm(): void {