Update WhatsAppService.php
This commit is contained in:
@@ -122,15 +122,16 @@ class WhatsAppService
|
||||
|
||||
if ($isNamed) {
|
||||
// bodyParameters is like ['name' => 'Alice', ...]
|
||||
// Convert named params to the WhatsApp API expected parameter objects
|
||||
foreach ($bodyParameters as $paramName => $paramValue) {
|
||||
if (is_array($paramValue) && isset($paramValue['type'])) {
|
||||
// already detailed param object: ensure name is set
|
||||
if (!isset($paramValue['name'])) $paramValue['name'] = $paramName;
|
||||
$normalizedBody[] = $paramValue;
|
||||
// already detailed param object: remove any unexpected keys like 'name'
|
||||
$paramObj = $paramValue;
|
||||
unset($paramObj['name']);
|
||||
$normalizedBody[] = $paramObj;
|
||||
} else {
|
||||
$normalizedBody[] = [
|
||||
'type' => 'text',
|
||||
'name' => $paramName,
|
||||
'text' => (string)$paramValue
|
||||
];
|
||||
}
|
||||
@@ -139,7 +140,10 @@ class WhatsAppService
|
||||
// Indexed array: preserve objects or convert strings
|
||||
foreach ($bodyParameters as $bp) {
|
||||
if (is_array($bp) && isset($bp['type'])) {
|
||||
$normalizedBody[] = $bp; // already detailed
|
||||
// ensure no unsupported keys like 'name' are passed through
|
||||
$bpCopy = $bp;
|
||||
unset($bpCopy['name']);
|
||||
$normalizedBody[] = $bpCopy; // already detailed
|
||||
} elseif (is_string($bp) || is_numeric($bp)) {
|
||||
$normalizedBody[] = [
|
||||
'type' => 'text',
|
||||
|
||||
Reference in New Issue
Block a user