refactor stateHandlers

This commit is contained in:
Lucas Tettamanti
2026-01-25 23:58:56 -03:00
parent debad78781
commit b1c8a3685c
9 changed files with 1602 additions and 1362 deletions

View File

@@ -0,0 +1,46 @@
/**
* Handler para el estado WAITING_WEBHOOKS
*/
import { ConversationState } from "../fsm.js";
import { createEmptyOrder, formatCartForDisplay } from "../orderModel.js";
/**
* Maneja el estado WAITING_WEBHOOKS (esperando confirmación de pago)
*/
export async function handleWaitingState({ tenantId, text, nlu, order, audit }) {
const intent = nlu?.intent || "other";
const currentOrder = order || createEmptyOrder();
// view_cart
if (intent === "view_cart") {
const cartDisplay = formatCartForDisplay(currentOrder);
const status = currentOrder.is_paid ? "✓ Pagado" : "Esperando pago...";
return {
plan: {
reply: `${cartDisplay}\n\nEstado: ${status}`,
next_state: ConversationState.WAITING_WEBHOOKS,
intent: "view_cart",
missing_fields: [],
order_action: "none",
},
decision: { actions: [], order: currentOrder, audit },
};
}
// Default
const reply = currentOrder.payment_type === "link"
? "Tu pedido está en proceso. Avisame si necesitás algo más o esperá la confirmación de pago."
: "Tu pedido está listo. Avisame si necesitás algo más.";
return {
plan: {
reply,
next_state: ConversationState.WAITING_WEBHOOKS,
intent: "other",
missing_fields: [],
order_action: "none",
},
decision: { actions: [], order: currentOrder, audit },
};
}