Update WhatsAppService.php
This commit is contained in:
@@ -64,7 +64,8 @@ class WhatsAppService
|
|||||||
$bodyParameters = [],
|
$bodyParameters = [],
|
||||||
$headerParameters = [],
|
$headerParameters = [],
|
||||||
$rawComponents = null,
|
$rawComponents = null,
|
||||||
$meta = null
|
$meta = null,
|
||||||
|
$dryRun = false
|
||||||
) {
|
) {
|
||||||
// Si se pasan components completos (por ejemplo flow/button/image), úsalos tal cual
|
// Si se pasan components completos (por ejemplo flow/button/image), úsalos tal cual
|
||||||
if (is_array($rawComponents) && !empty($rawComponents)) {
|
if (is_array($rawComponents) && !empty($rawComponents)) {
|
||||||
@@ -81,7 +82,7 @@ class WhatsAppService
|
|||||||
'template' => $template
|
'template' => $template
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->sendMessage($data);
|
return $dryRun ? $data : $this->sendMessage($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$components = [];
|
$components = [];
|
||||||
@@ -127,11 +128,18 @@ class WhatsAppService
|
|||||||
if (is_array($paramValue) && isset($paramValue['type'])) {
|
if (is_array($paramValue) && isset($paramValue['type'])) {
|
||||||
// already detailed param object: remove any unexpected keys like 'name'
|
// already detailed param object: remove any unexpected keys like 'name'
|
||||||
$paramObj = $paramValue;
|
$paramObj = $paramValue;
|
||||||
unset($paramObj['name']);
|
// ensure parameter name is set using 'parameter_name' (preferred) or fall back to 'name'
|
||||||
|
if (!isset($paramObj['parameter_name']) && !isset($paramObj['name'])) {
|
||||||
|
$paramObj['parameter_name'] = $paramName;
|
||||||
|
}
|
||||||
|
// remove legacy 'name' to avoid API errors
|
||||||
|
if (isset($paramObj['name'])) unset($paramObj['name']);
|
||||||
$normalizedBody[] = $paramObj;
|
$normalizedBody[] = $paramObj;
|
||||||
} else {
|
} else {
|
||||||
|
// include parameter_name so WhatsApp recognizes named params
|
||||||
$normalizedBody[] = [
|
$normalizedBody[] = [
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
|
'parameter_name' => $paramName,
|
||||||
'text' => (string)$paramValue
|
'text' => (string)$paramValue
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -184,7 +192,7 @@ class WhatsAppService
|
|||||||
$data['__app_meta'] = $meta;
|
$data['__app_meta'] = $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->sendMessage($data);
|
return $dryRun ? $data : $this->sendMessage($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user