fix(chat): capture template name/lang before closing modal in sendTemplate

closeTemplatePicker() sets _tplSelected = null, so accessing
_tplSelected.template_name after the call threw a TypeError caught
as "Error de red al enviar plantilla".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-03 14:47:31 -05:00
co-authored by Claude Sonnet 4.6
parent ccdc35932d
commit f60df038d8
+5 -2
View File
@@ -1002,7 +1002,10 @@ async function sendTemplate() {
const missing = params.findIndex(p => !p); const missing = params.findIndex(p => !p);
if (missing !== -1) { inputs[missing].focus(); return; } if (missing !== -1) { inputs[missing].focus(); return; }
const templateName = _tplSelected.template_name;
const templateLang = _tplSelected.language_code;
closeTemplatePicker(); closeTemplatePicker();
try { try {
const res = await fetch(BASE + API_SEND, { const res = await fetch(BASE + API_SEND, {
method: 'POST', method: 'POST',
@@ -1010,8 +1013,8 @@ async function sendTemplate() {
body: JSON.stringify({ body: JSON.stringify({
user_id: state.activeUserId, user_id: state.activeUserId,
type: 'template', type: 'template',
template: _tplSelected.template_name, template: templateName,
lang: _tplSelected.language_code, lang: templateLang,
params params
}) })
}); });