This commit is contained in:
lizandrogd
2026-01-13 02:12:18 -05:00
parent 0544e81463
commit ccea8adefa
7 changed files with 331 additions and 36 deletions
+28 -2
View File
@@ -306,10 +306,36 @@ class WhatsAppService
$result = json_decode($response, true);
if (!isset($result['id'])) {
throw new Exception("No se obtuvo ID del archivo subido");
throw new Exception("No se obtuvo ID del archivo subido: " . $response);
}
return $result['id']; // Retorna el media_id
return $result; // Retorna el objeto completo con 'id'
}
/**
* Enviar mensaje usando media_id (archivo ya subido a WhatsApp)
*/
public function sendMediaById($to, $mediaId, $mediaType, $caption = null, $filename = null)
{
$data = [
'messaging_product' => 'whatsapp',
'to' => $this->formatPhoneNumber($to),
'type' => $mediaType
];
$mediaData = ['id' => $mediaId];
if ($caption && in_array($mediaType, ['image', 'video', 'document'])) {
$mediaData['caption'] = $caption;
}
if ($filename && $mediaType === 'document') {
$mediaData['filename'] = $filename;
}
$data[$mediaType] = $mediaData;
return $this->sendMessage($data);
}
/**