fix(template): send parameter_name for named-variable templates
WhatsApp API returns "(#100) Invalid parameter — Parameter name is missing or empty" for templates that use named variables. - chat.php sendTemplate(): collect params as [{name, value}] objects using data-var-index as the parameter name - WhatsAppService::sendTemplateMessage(): handle {name, value} objects in the indexed-array path by emitting {type, parameter_name, text} (backward-compatible — plain strings still work as positional params) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
a8380ddc81
commit
3d6147bf0d
@@ -998,8 +998,8 @@ async function selectTemplate(tpl) {
|
||||
async function sendTemplate() {
|
||||
if (!_tplSelected || !state.activeUserId) return;
|
||||
const inputs = [...document.querySelectorAll('#tpl-vars-body input[data-var-index]')];
|
||||
const params = inputs.map(el => el.value.trim());
|
||||
const missing = params.findIndex(p => !p);
|
||||
const params = inputs.map(el => ({ name: el.dataset.varIndex, value: el.value.trim() }));
|
||||
const missing = params.findIndex(p => !p.value);
|
||||
if (missing !== -1) { inputs[missing].focus(); return; }
|
||||
|
||||
const templateName = _tplSelected.template_name;
|
||||
|
||||
@@ -181,6 +181,13 @@ class WhatsAppService
|
||||
$bpCopy = $bp;
|
||||
unset($bpCopy['name']);
|
||||
$normalizedBody[] = $bpCopy; // already detailed
|
||||
} elseif (is_array($bp) && isset($bp['name'], $bp['value'])) {
|
||||
// {name: 'param_name', value: 'text'} — include parameter_name for named-variable templates
|
||||
$normalizedBody[] = [
|
||||
'type' => 'text',
|
||||
'parameter_name' => (string)$bp['name'],
|
||||
'text' => (string)$bp['value'],
|
||||
];
|
||||
} elseif (is_string($bp) || is_numeric($bp)) {
|
||||
$normalizedBody[] = [
|
||||
'type' => 'text',
|
||||
|
||||
Reference in New Issue
Block a user