Logia de agente de Whatsapp

This commit is contained in:
unknown
2026-05-31 22:02:58 -04:00
parent aa7555b49d
commit ef78d9a14c
28 changed files with 12736 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Conversacion, RolMensaje } from './conversacion.entity';
@Injectable()
export class ConversacionService {
constructor(
@InjectRepository(Conversacion)
private readonly convRepo: Repository<Conversacion>,
) {}
async guardarMensaje(
leadId: number,
rol: RolMensaje,
mensaje: string,
): Promise<Conversacion> {
const entry = this.convRepo.create({ lead_id: leadId, rol, mensaje });
return this.convRepo.save(entry);
}
async obtenerHistorial(leadId: number): Promise<Conversacion[]> {
return this.convRepo.find({
where: { lead_id: leadId },
order: { created_at: 'ASC' },
});
}
/**
* Devuelve el historial en formato OpenAI/Claude messages array.
*/
async obtenerHistorialComoMessages(
leadId: number,
): Promise<Array<{ role: string; content: string }>> {
const historial = await this.obtenerHistorial(leadId);
return historial.map((h) => ({
role: h.rol,
content: h.mensaje,
}));
}
}