feat: actualizar envío de documentos por WhatsApp para usar plantilla 'facturas_pdv' y eliminar el campo 'caption'

This commit is contained in:
Juan Felipe Zapata Moreno 2026-03-05 16:33:09 -06:00
parent 19885a0aba
commit b253e8a308
2 changed files with 35 additions and 13 deletions

View File

@ -19,7 +19,6 @@ public function sendDocument(Request $request)
$validated = $request->validate([ $validated = $request->validate([
'phone_number' => ['required', 'string', 'regex:/^[0-9]{10,13}$/'], 'phone_number' => ['required', 'string', 'regex:/^[0-9]{10,13}$/'],
'document_url' => ['required', 'url'], 'document_url' => ['required', 'url'],
'caption' => ['required', 'string', 'max:1000'],
'filename' => ['required', 'string', 'max:255'], 'filename' => ['required', 'string', 'max:255'],
'ticket' => ['required', 'string', 'max:100'], 'ticket' => ['required', 'string', 'max:100'],
'customer_name' => ['required', 'string', 'max:255'], 'customer_name' => ['required', 'string', 'max:255'],
@ -33,7 +32,6 @@ public function sendDocument(Request $request)
$result = $this->whatsAppService->sendDocument( $result = $this->whatsAppService->sendDocument(
phoneNumber: $validated['phone_number'], phoneNumber: $validated['phone_number'],
documentUrl: $validated['document_url'], documentUrl: $validated['document_url'],
caption: $validated['caption'],
filename: $validated['filename'], filename: $validated['filename'],
userEmail: auth()->user()->email, userEmail: auth()->user()->email,
ticket: $validated['ticket'], ticket: $validated['ticket'],

View File

@ -27,28 +27,54 @@ public function __construct()
} }
/** /**
* Enviar documento por WhatsApp * Enviar documento por WhatsApp usando plantilla facturas_pdv
*/ */
public function sendDocument( public function sendDocument(
string $phoneNumber, string $phoneNumber,
string $documentUrl, string $documentUrl,
string $caption,
string $filename, string $filename,
string $userEmail, string $userEmail,
string $ticket, string $ticket,
string $customerName string $customerName
): array { ): array {
try { try {
// Construir el mensaje de WhatsApp // Construir el mensaje de WhatsApp usando plantilla
$whatsappMessage = json_encode([ $whatsappMessage = json_encode([
'messaging_product' => 'whatsapp', 'messaging_product' => 'whatsapp',
'recipient_type' => 'individual',
'to' => $this->cleanPhoneNumber($phoneNumber), 'to' => $this->cleanPhoneNumber($phoneNumber),
'type' => 'document', 'type' => 'template',
'document' => [ 'template' => [
'link' => $documentUrl, 'name' => 'facturas_pdv',
'caption' => $caption, 'language' => [
'filename' => $filename, 'code' => 'es_MX',
],
'components' => [
[
'type' => 'header',
'parameters' => [
[
'type' => 'document',
'document' => [
'filename' => $filename,
'link' => $documentUrl,
],
],
],
],
[
'type' => 'body',
'parameters' => [
[
'type' => 'text',
'text' => $customerName,
],
[
'type' => 'text',
'text' => $ticket,
],
],
],
],
], ],
]); ]);
@ -129,7 +155,6 @@ public function sendInvoice(
$pdfResult = $this->sendDocument( $pdfResult = $this->sendDocument(
phoneNumber: $phoneNumber, phoneNumber: $phoneNumber,
documentUrl: $pdfUrl, documentUrl: $pdfUrl,
caption: "Factura {$invoiceNumber} - {$customerName}",
filename: "Factura_{$invoiceNumber}.pdf", filename: "Factura_{$invoiceNumber}.pdf",
userEmail: $this->email, userEmail: $this->email,
ticket: $invoiceNumber, ticket: $invoiceNumber,
@ -141,7 +166,6 @@ public function sendInvoice(
$xmlResult = $this->sendDocument( $xmlResult = $this->sendDocument(
phoneNumber: $phoneNumber, phoneNumber: $phoneNumber,
documentUrl: $xmlUrl, documentUrl: $xmlUrl,
caption: "XML - Factura {$invoiceNumber}",
filename: "Factura_{$invoiceNumber}.xml", filename: "Factura_{$invoiceNumber}.xml",
userEmail: $this->email, userEmail: $this->email,
ticket: "{$invoiceNumber}_XML", ticket: "{$invoiceNumber}_XML",