feat(automation): integrate n8n webhook notifications for guestbook and contact form
This commit is contained in:
parent
edde996f43
commit
838b657696
|
|
@ -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'
|
||||||
|
});
|
||||||
|
|
@ -4,6 +4,7 @@ import { Observable, catchError, of, tap } from 'rxjs';
|
||||||
import { GuestbookPort } from '../../domain/ports/guestbook.port';
|
import { GuestbookPort } from '../../domain/ports/guestbook.port';
|
||||||
import { CreateGuestbookRequest, GuestbookEntry } from '../../domain/models/guestbook.model';
|
import { CreateGuestbookRequest, GuestbookEntry } from '../../domain/models/guestbook.model';
|
||||||
import { API_BASE_URL } from '../../core/tokens/api-config.token';
|
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';
|
const STORAGE_KEY = 'zen_guestbook_entries_cache';
|
||||||
|
|
||||||
|
|
@ -37,6 +38,7 @@ const INITIAL_MOCK_ENTRIES: GuestbookEntry[] = [
|
||||||
export class HttpGuestbookAdapter implements GuestbookPort {
|
export class HttpGuestbookAdapter implements GuestbookPort {
|
||||||
private readonly http = inject(HttpClient);
|
private readonly http = inject(HttpClient);
|
||||||
private readonly baseUrl = inject(API_BASE_URL);
|
private readonly baseUrl = inject(API_BASE_URL);
|
||||||
|
private readonly notifyWebhookUrl = inject(NOTIFY_WEBHOOK_URL);
|
||||||
|
|
||||||
getEntries(limit: number = 50): Observable<GuestbookEntry[]> {
|
getEntries(limit: number = 50): Observable<GuestbookEntry[]> {
|
||||||
return this.http.get<GuestbookEntry[]>(`${this.baseUrl}/guestbook?limit=${limit}`).pipe(
|
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> {
|
createEntry(request: CreateGuestbookRequest): Observable<GuestbookEntry> {
|
||||||
|
this.dispatchN8nNotification(request);
|
||||||
|
|
||||||
return this.http.post<GuestbookEntry>(`${this.baseUrl}/guestbook`, request).pipe(
|
return this.http.post<GuestbookEntry>(`${this.baseUrl}/guestbook`, request).pipe(
|
||||||
tap(created => {
|
tap(created => {
|
||||||
const cached = this.loadFromCache();
|
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[] {
|
private loadFromCache(): GuestbookEntry[] {
|
||||||
if (typeof localStorage === 'undefined') return INITIAL_MOCK_ENTRIES;
|
if (typeof localStorage === 'undefined') return INITIAL_MOCK_ENTRIES;
|
||||||
const raw = localStorage.getItem(STORAGE_KEY);
|
const raw = localStorage.getItem(STORAGE_KEY);
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,12 @@
|
||||||
{{ currentEndpoint().method }}
|
{{ currentEndpoint().method }}
|
||||||
</div>
|
</div>
|
||||||
<div class="url-text font-mono">
|
<div class="url-text font-mono">
|
||||||
<span class="url-host">api.bryan-bano.com</span>
|
@if (currentEndpoint().path.startsWith('http')) {
|
||||||
<span class="url-path">{{ currentEndpoint().path }}</span>
|
<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>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { API_BASE_URL } from '../../../core/tokens/api-config.token';
|
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 {
|
export interface ApiEndpointDef {
|
||||||
readonly key: ApiEndpointKey;
|
readonly key: ApiEndpointKey;
|
||||||
|
|
@ -50,6 +50,20 @@ export const API_ENDPOINTS: readonly ApiEndpointDef[] = [
|
||||||
badgeTag: 'DEV_ZEN'
|
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',
|
key: 'ping',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
@ -111,7 +125,7 @@ export class ApiExplorerComponent {
|
||||||
|
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
const endpoint = this.currentEndpoint();
|
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
|
// Animación visual secuencial de paquetes
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,10 @@ import {
|
||||||
FormControl,
|
FormControl,
|
||||||
Validators
|
Validators
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { I18nService } from '../../../application/services/i18n.service';
|
import { I18nService } from '../../../application/services/i18n.service';
|
||||||
import { GuestbookComponent } from '../guestbook/guestbook.component';
|
import { GuestbookComponent } from '../guestbook/guestbook.component';
|
||||||
|
import { NOTIFY_WEBHOOK_URL } from '../../../core/tokens/notify-config.token';
|
||||||
|
|
||||||
interface DigitalRainColumn {
|
interface DigitalRainColumn {
|
||||||
x: number;
|
x: number;
|
||||||
|
|
@ -44,6 +46,8 @@ export class ContactSectionComponent implements OnInit, AfterViewInit, OnDestroy
|
||||||
@ViewChild('rainCanvas') private readonly rainCanvas?: ElementRef<HTMLCanvasElement>;
|
@ViewChild('rainCanvas') private readonly rainCanvas?: ElementRef<HTMLCanvasElement>;
|
||||||
|
|
||||||
protected readonly i18n = inject(I18nService);
|
protected readonly i18n = inject(I18nService);
|
||||||
|
private readonly http = inject(HttpClient);
|
||||||
|
private readonly notifyWebhookUrl = inject(NOTIFY_WEBHOOK_URL);
|
||||||
|
|
||||||
// Estado reactivo del formulario con Signals
|
// Estado reactivo del formulario con Signals
|
||||||
protected readonly isSubmitting = signal(false);
|
protected readonly isSubmitting = signal(false);
|
||||||
|
|
@ -267,10 +271,25 @@ export class ContactSectionComponent implements OnInit, AfterViewInit, OnDestroy
|
||||||
this.errorMessage.set(null);
|
this.errorMessage.set(null);
|
||||||
this.isSubmitting.set(true);
|
this.isSubmitting.set(true);
|
||||||
|
|
||||||
setTimeout(() => {
|
const formData = this.contactForm.getRawValue();
|
||||||
this.isSubmitting.set(false);
|
|
||||||
this.isSuccess.set(true);
|
this.http.post(this.notifyWebhookUrl, {
|
||||||
}, 600);
|
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 {
|
resetForm(): void {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue