Hi guys! I’m still pretty new to this and I’m trying to create automations for the first time. While building this flow, I fixed things little by little as I learned, but this error has been taking me hours and I still can’t understand why.
I’m attaching a screenshot of the “Format Product Reply” node, which isn’t able to retrieve the “wa_id”, and then the error that appears in the last node, “Reply Whatsapp.”
I hope you can give me a hand with this so I can understand what’s causing the issue. If you need more information from the nodes before these two, I’ll gladly share it.
Thank you for your time!
Format Product Reply:
const inboundRaw = ($items("Normalizer", 0, 0)?.json?.raw) || ($items("Webhook Inbound", 0, 0)?.json) || {};
const body = inboundRaw.body || inboundRaw;
const wEntry = body.entry?.[0]?.changes?.[0]?.value || {};
const wMsg = wEntry.messages?.[0] || body.messages?.[0] || {};
// Destinatario (wa_id)
const waId = (
$json.to ||
body.to ||
inboundRaw.to ||
wMsg.from ||
wEntry.contacts?.[0]?.wa_id ||
body.contacts?.[0]?.wa_id ||
inboundRaw.contacts?.[0]?.wa_id ||
''
);
// message_id para el contexto
const msgId = (
$json.message_id ||
wMsg.id ||
wEntry.messages?.[0]?.id ||
body.message_id ||
inboundRaw.message_id ||
''
);
const products = items[0].json;
if (!waId) {
return [{ json: { error: 'missing_wa_id', message: 'No se pudo obtener el destino wa_id' } }];
}
if (!msgId) {
return [{ json: { error: 'missing_msg_id', message: 'No se pudo obtener message_id' } }];
}
if (!Array.isArray(products) || products.length === 0) {
return [{
json: {
to: waId,
message_id: msgId,
message: 'No encontré stock para lo que pediste. ¿Querés que lo revise un agente?'
}
}];
}
const base = 'https://testempresa3.mitiendanube.com';
const lines = products.slice(0, 3).map(p => {
const name = p.name?.es || p.name || 'Producto';
const price = p.price || p.price_cost || '';
const handle = typeof p.handle === 'string'
? p.handle
: (p.handle?.es || p.handle?.pt || p.url || '');
const link = handle ? `${base}/productos/${handle}` : (p.url || base);
return `• ${name}${price ? ' - $' + price : ''}\n${link}`;
});
const msg = `Te sugiero esto:\n\n${lines.join('\n\n')}\n\n¿Te sirve alguno?`;
return [{ json: { to: waId, message_id: msgId, message: msg, raw: body } }];
“Body Parameters” in “Reply Whatsapp”
{
"messaging_product": "whatsapp",
"to": "{{ $json.to || $items('Format Product Reply', 0, 0).json.to || $items('Normalizer', 0, 0).json.raw.entry[0].changes[0].value.messages[0].from }}",
"context": { "message_id": "{{ $json.message_id || $items('Format Product Reply', 0, 0).json.message_id || $items('Normalizer', 0, 0).json.raw.entry[0].changes[0].value.messages[0].id }}" },
"type": "text",
"text": { "body": "{{ $json.message || $items('Format Product Reply', 0, 0).json.message }}" }
}

