fix: corregir envío de plantillas con variables nombradas en chat turnero
El parámetro_name enviado a WhatsApp era el índice numérico ("1") en vez
del nombre real de la variable ("name", "fecha", etc.), causando el error
#100 Invalid parameter. Ahora se detecta si las variables son nombradas o
numéricas y se construye el payload correctamente, igual que conversations.php.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
34c6d2e643
commit
1bd799a501
@@ -1178,7 +1178,7 @@ const nuevoMensaje = (() => {
|
||||
row.className = 'tpl-var-row';
|
||||
const ph = v.example || v.placeholder || v.label;
|
||||
row.innerHTML = `<label>{{${v.index}}} — ${escHtml(v.label)}</label>` +
|
||||
`<input type="text" data-var-index="${v.index}" placeholder="${escHtml(ph)}">`;
|
||||
`<input type="text" data-var-index="${v.index}" data-var-placeholder="${escHtml(v.placeholder || '')}" placeholder="${escHtml(ph)}">`;
|
||||
varsBody.appendChild(row);
|
||||
});
|
||||
}
|
||||
@@ -1193,9 +1193,9 @@ const nuevoMensaje = (() => {
|
||||
async function enviar() {
|
||||
if (!_phone || !_tpl) return;
|
||||
const inputs = [...document.querySelectorAll('#nv-vars-body input[data-var-index]')];
|
||||
const params = inputs.map(el => ({ name: el.dataset.varIndex, value: el.value.trim() }));
|
||||
const missing = params.findIndex(p => !p.value);
|
||||
const missing = inputs.findIndex(el => !el.value.trim());
|
||||
if (missing !== -1) { inputs[missing].focus(); return; }
|
||||
const params = _buildParams(inputs);
|
||||
|
||||
const templateName = _tpl.template_name;
|
||||
const templateLang = _tpl.language_code;
|
||||
@@ -1293,7 +1293,7 @@ async function selectTemplate(tpl) {
|
||||
const label = v.label || ('Variable ' + v.index);
|
||||
const ph = v.example || v.placeholder || label;
|
||||
row.innerHTML = `<label>{{${v.index}}} — ${escHtml(label)}</label>` +
|
||||
`<input type="text" data-var-index="${v.index}" placeholder="${escHtml(ph)}">`;
|
||||
`<input type="text" data-var-index="${v.index}" data-var-placeholder="${escHtml(v.placeholder || '')}" placeholder="${escHtml(ph)}">`;
|
||||
varsBody.appendChild(row);
|
||||
});
|
||||
}
|
||||
@@ -1302,12 +1302,28 @@ async function selectTemplate(tpl) {
|
||||
}
|
||||
}
|
||||
|
||||
function _buildParams(inputs) {
|
||||
const hasNamed = inputs.some(el => {
|
||||
const n = (el.dataset.varPlaceholder || '').replace(/\{\{|\}\}/g, '').trim();
|
||||
return n && !/^\d+$/.test(n);
|
||||
});
|
||||
if (hasNamed) {
|
||||
const obj = {};
|
||||
inputs.forEach(el => {
|
||||
const n = (el.dataset.varPlaceholder || '').replace(/\{\{|\}\}/g, '').trim() || el.dataset.varIndex;
|
||||
obj[n] = el.value.trim();
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
return inputs.map(el => el.value.trim());
|
||||
}
|
||||
|
||||
async function sendTemplate() {
|
||||
if (!_tplSelected || !state.activeUserId) return;
|
||||
const inputs = [...document.querySelectorAll('#tpl-vars-body input[data-var-index]')];
|
||||
const params = inputs.map(el => ({ name: el.dataset.varIndex, value: el.value.trim() }));
|
||||
const missing = params.findIndex(p => !p.value);
|
||||
const missing = inputs.findIndex(el => !el.value.trim());
|
||||
if (missing !== -1) { inputs[missing].focus(); return; }
|
||||
const params = _buildParams(inputs);
|
||||
|
||||
const templateName = _tplSelected.template_name;
|
||||
const templateLang = _tplSelected.language_code;
|
||||
|
||||
Reference in New Issue
Block a user