This commit is contained in:
Lizandro Guarnizo
2026-01-24 12:41:55 -05:00
parent 723dde95ef
commit 10386cf408
2 changed files with 59 additions and 4 deletions
+29 -1
View File
@@ -1367,10 +1367,38 @@ class SimpleWhatsAppManager {
return;
}
// Prepare template payload; support named parameters (e.g. { name: 'Juan' })
const tplName = templateSelect.value;
let tplParams = null;
// If there's a hidden input with JSON parameters (index.php), use it
const paramsInput = document.getElementById('template-params');
if (paramsInput && paramsInput.value) {
try {
tplParams = JSON.parse(paramsInput.value);
} catch (e) {
console.warn('Invalid JSON in #template-params, ignoring', e);
tplParams = null;
}
}
// If no params provided and template is contacto_nuevo, prompt operator for name
if ((!tplParams || (typeof tplParams === 'object' && Object.keys(tplParams).length === 0)) && tplName === 'contacto_nuevo') {
const defaultName = '';
const inputName = prompt('Ingrese el nombre para la plantilla contacto_nuevo (dejar vacío para usar el número):', defaultName);
if (inputName === null) {
// user cancelled
return;
}
const clean = (typeof inputName === 'string') ? inputName.trim() : '';
tplParams = { name: clean || recipient };
}
messageData = {
recipient: recipient,
type: 'template',
template_name: templateSelect.value
template_name: tplName,
parameters: tplParams || {}
};
}