modularizado de prompts
This commit is contained in:
@@ -232,22 +232,36 @@ const runStatus = llmMeta?.error ? "warn" : "ok";
|
||||
for (const act of actions) {
|
||||
try {
|
||||
if (act.type === "create_order") {
|
||||
const basketToUse = reducedContext?.order_basket || plan?.basket_resolved || { items: [] };
|
||||
// Construir address con phone de fallback desde wa_chat_id
|
||||
const baseAddress = reducedContext?.delivery_address || reducedContext?.address || {};
|
||||
const phoneFromWa = from?.replace(/@.*$/, "")?.replace(/[^0-9]/g, "") || "";
|
||||
const addressWithPhone = {
|
||||
...baseAddress,
|
||||
phone: baseAddress.phone || phoneFromWa,
|
||||
};
|
||||
const order = await createOrder({
|
||||
tenantId,
|
||||
wooCustomerId: externalCustomerId,
|
||||
basket: reducedContext?.order_basket || plan?.basket_resolved || { items: [] },
|
||||
address: reducedContext?.delivery_address || reducedContext?.address || null,
|
||||
basket: basketToUse,
|
||||
address: addressWithPhone,
|
||||
run_id: null,
|
||||
});
|
||||
actionPatch.woo_order_id = order?.id || null;
|
||||
actionPatch.order_total = calcOrderTotal(order);
|
||||
newTools.push({ type: "create_order", ok: true, order_id: order?.id || null });
|
||||
} else if (act.type === "update_order") {
|
||||
const baseAddrUpd = reducedContext?.delivery_address || reducedContext?.address || {};
|
||||
const phoneFromWaUpd = from?.replace(/@.*$/, "")?.replace(/[^0-9]/g, "") || "";
|
||||
const addressWithPhoneUpd = {
|
||||
...baseAddrUpd,
|
||||
phone: baseAddrUpd.phone || phoneFromWaUpd,
|
||||
};
|
||||
const order = await updateOrder({
|
||||
tenantId,
|
||||
wooOrderId: reducedContext?.woo_order_id || prev?.last_order_id || null,
|
||||
basket: reducedContext?.order_basket || plan?.basket_resolved || { items: [] },
|
||||
address: reducedContext?.delivery_address || reducedContext?.address || null,
|
||||
address: addressWithPhoneUpd,
|
||||
run_id: null,
|
||||
});
|
||||
actionPatch.woo_order_id = order?.id || null;
|
||||
|
||||
Reference in New Issue
Block a user