up
This commit is contained in:
+29
-1
@@ -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 || {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user