Update WhatsAppService.php

This commit is contained in:
Lizandro Guarnizo
2026-01-24 12:13:29 -05:00
parent 2d769ad18d
commit 9204220d40
+9 -5
View File
@@ -122,15 +122,16 @@ class WhatsAppService
if ($isNamed) { if ($isNamed) {
// bodyParameters is like ['name' => 'Alice', ...] // bodyParameters is like ['name' => 'Alice', ...]
// Convert named params to the WhatsApp API expected parameter objects
foreach ($bodyParameters as $paramName => $paramValue) { foreach ($bodyParameters as $paramName => $paramValue) {
if (is_array($paramValue) && isset($paramValue['type'])) { if (is_array($paramValue) && isset($paramValue['type'])) {
// already detailed param object: ensure name is set // already detailed param object: remove any unexpected keys like 'name'
if (!isset($paramValue['name'])) $paramValue['name'] = $paramName; $paramObj = $paramValue;
$normalizedBody[] = $paramValue; unset($paramObj['name']);
$normalizedBody[] = $paramObj;
} else { } else {
$normalizedBody[] = [ $normalizedBody[] = [
'type' => 'text', 'type' => 'text',
'name' => $paramName,
'text' => (string)$paramValue 'text' => (string)$paramValue
]; ];
} }
@@ -139,7 +140,10 @@ class WhatsAppService
// Indexed array: preserve objects or convert strings // Indexed array: preserve objects or convert strings
foreach ($bodyParameters as $bp) { foreach ($bodyParameters as $bp) {
if (is_array($bp) && isset($bp['type'])) { 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)) { } elseif (is_string($bp) || is_numeric($bp)) {
$normalizedBody[] = [ $normalizedBody[] = [
'type' => 'text', 'type' => 'text',