badges on the right, evolution api sender
This commit is contained in:
@@ -18,6 +18,8 @@ import { runTurnV3 } from "../../3-turn-engine/turnEngineV3.js";
|
||||
import { safeNextState } from "../../3-turn-engine/fsm.js";
|
||||
import { createOrder, updateOrder } from "../../4-woo-orders/wooOrders.js";
|
||||
import { createPreference } from "../../6-mercadopago/mercadoPago.js";
|
||||
import { handleCreateTakeover } from "../../0-ui/handlers/takeovers.js";
|
||||
import { sendTextMessage, isEvolutionEnabled } from "../../1-intake/services/evolutionSender.js";
|
||||
|
||||
function nowIso() {
|
||||
return new Date().toISOString();
|
||||
@@ -283,6 +285,23 @@ const runStatus = llmMeta?.error ? "warn" : "ok";
|
||||
actionPatch.woo_order_id = order?.id || null;
|
||||
actionPatch.order_total = calcOrderTotal(order);
|
||||
newTools.push({ type: "update_order", ok: true, order_id: order?.id || null });
|
||||
} else if (act.type === "request_human_takeover") {
|
||||
const takeoverResult = await handleCreateTakeover({
|
||||
tenantId,
|
||||
chatId: chat_id,
|
||||
pendingQuery: act.payload?.pending_query || "consulta pendiente",
|
||||
reason: act.payload?.reason || "product_not_found",
|
||||
contextSnapshot: act.payload?.context_snapshot || null,
|
||||
});
|
||||
newTools.push({ type: "request_human_takeover", ok: takeoverResult?.ok || false, takeover_id: takeoverResult?.takeover?.id || null });
|
||||
// Notificar via SSE para actualizar la campanita inmediatamente
|
||||
if (takeoverResult?.ok) {
|
||||
sseSend("takeover.created", {
|
||||
takeover_id: takeoverResult.takeover?.id,
|
||||
chat_id,
|
||||
pending_query: act.payload?.pending_query,
|
||||
});
|
||||
}
|
||||
} else if (act.type === "send_payment_link") {
|
||||
const total = Number(actionPatch?.order_total || reducedContext?.order_total || 0) || null;
|
||||
if (!total || total <= 0) {
|
||||
@@ -339,6 +358,15 @@ const runStatus = llmMeta?.error ? "warn" : "ok";
|
||||
});
|
||||
mark("after_insertMessage_out");
|
||||
|
||||
// Enviar a WhatsApp via Evolution API (si está habilitado y el mensaje vino de evolution)
|
||||
if (provider === "evolution" && !isSimulated && isEvolutionEnabled()) {
|
||||
try {
|
||||
await sendTextMessage({ chatId: chat_id, text: plan.reply });
|
||||
} catch (e) {
|
||||
console.error("[pipeline] Evolution send error:", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (llmMeta?.error) {
|
||||
const errMsgId = newId("err");
|
||||
await insertMessage({
|
||||
|
||||
Reference in New Issue
Block a user