refactor stateHandlers
This commit is contained in:
46
src/modules/3-turn-engine/stateHandlers/waiting.js
Normal file
46
src/modules/3-turn-engine/stateHandlers/waiting.js
Normal 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 },
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user