corregidos bugs de: ret, vs delivery, efectivo vs link, charsets, price query

This commit is contained in:
Lucas Tettamanti
2026-01-26 23:27:47 -03:00
parent 53293ce9b3
commit 493f26af17
13 changed files with 757 additions and 193 deletions

View File

@@ -25,25 +25,17 @@ function isDeliveryInfoQuestion(text) {
}
/**
* Formatea los días de entrega para mostrar
* Detecta si el usuario pregunta por horarios de retiro
*/
function formatDeliveryDays(daysStr) {
if (!daysStr) return null;
const dayMap = {
"lun": "Lunes", "mar": "Martes", "mie": "Miércoles", "mié": "Miércoles",
"jue": "Jueves", "vie": "Viernes", "sab": "Sábado", "sáb": "Sábado", "dom": "Domingo",
};
const days = daysStr.split(",").map(d => d.trim().toLowerCase());
const formatted = days.map(d => dayMap[d] || d).filter(Boolean);
if (formatted.length === 0) return null;
if (formatted.length === 1) return formatted[0];
// "Lunes, Martes, Miércoles y Jueves"
const last = formatted.pop();
return `${formatted.join(", ")} y ${last}`;
function isPickupInfoQuestion(text) {
const t = String(text || "").toLowerCase();
const patterns = [
/horario.*(retir|buscar|pasar)/i,
/cu[aá]ndo.*(retir|buscar|pasar)/i,
/a\s+qu[eé]\s+hora.*(retir|buscar)/i,
/d[ií]as?.*(retir|buscar)/i,
];
return patterns.some(p => p.test(t));
}
/**
@@ -71,19 +63,17 @@ export async function handleWaitingState({ tenantId, text, nlu, order, audit, st
// Preguntas sobre horarios/días de entrega
if (isDeliveryInfoQuestion(text)) {
const deliveryDays = formatDeliveryDays(storeConfig.delivery_days);
const startHour = storeConfig.delivery_hours_start?.slice(0, 5);
const endHour = storeConfig.delivery_hours_end?.slice(0, 5);
// Usar deliveryHours que ya viene formateado desde getStoreConfig
// (agrupa días con mismos horarios: "Lunes a Viernes de 9:00 a 14:00, Sábado de 9:00 a 13:00")
const deliveryHours = storeConfig.deliveryHours;
let reply = "";
if (deliveryDays) {
reply = `Hacemos entregas los días ${deliveryDays}`;
if (startHour && endHour) {
reply += ` de ${startHour} a ${endHour}`;
}
reply += ". ";
if (deliveryHours && deliveryHours !== "No disponible") {
reply = `Hacemos entregas: ${deliveryHours}. `;
} else if (storeConfig.deliveryEnabled === false) {
reply = "Por el momento no ofrecemos delivery. ";
} else {
reply = "Todavía no tengo configurado los días de entrega. ";
reply = "Todavía no tengo configurados los horarios de entrega. ";
}
reply += "Tu pedido ya está en proceso, avisame cualquier cosa.";
@@ -100,6 +90,33 @@ export async function handleWaitingState({ tenantId, text, nlu, order, audit, st
};
}
// Preguntas sobre horarios de retiro
if (isPickupInfoQuestion(text)) {
const pickupHours = storeConfig.pickupHours;
let reply = "";
if (pickupHours && pickupHours !== "No disponible") {
reply = `Podés retirar: ${pickupHours}. `;
} else if (storeConfig.pickupEnabled === false) {
reply = "Por el momento no ofrecemos retiro en tienda. ";
} else {
reply = "Todavía no tengo configurados los horarios de retiro. ";
}
reply += "Tu pedido ya está en proceso, avisame cualquier cosa.";
return {
plan: {
reply,
next_state: ConversationState.WAITING_WEBHOOKS,
intent: "pickup_info",
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."