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