From b253e8a3084315f983d32cd4c74838ed05e73549 Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Thu, 5 Mar 2026 16:33:09 -0600 Subject: [PATCH] =?UTF-8?q?feat:=20actualizar=20env=C3=ADo=20de=20document?= =?UTF-8?q?os=20por=20WhatsApp=20para=20usar=20plantilla=20'facturas=5Fpdv?= =?UTF-8?q?'=20y=20eliminar=20el=20campo=20'caption'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/App/WhatsappController.php | 2 - app/Services/WhatsappService.php | 46 ++++++++++++++----- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/App/WhatsappController.php b/app/Http/Controllers/App/WhatsappController.php index e89cded..3cab282 100644 --- a/app/Http/Controllers/App/WhatsappController.php +++ b/app/Http/Controllers/App/WhatsappController.php @@ -19,7 +19,6 @@ public function sendDocument(Request $request) $validated = $request->validate([ 'phone_number' => ['required', 'string', 'regex:/^[0-9]{10,13}$/'], 'document_url' => ['required', 'url'], - 'caption' => ['required', 'string', 'max:1000'], 'filename' => ['required', 'string', 'max:255'], 'ticket' => ['required', 'string', 'max:100'], 'customer_name' => ['required', 'string', 'max:255'], @@ -33,7 +32,6 @@ public function sendDocument(Request $request) $result = $this->whatsAppService->sendDocument( phoneNumber: $validated['phone_number'], documentUrl: $validated['document_url'], - caption: $validated['caption'], filename: $validated['filename'], userEmail: auth()->user()->email, ticket: $validated['ticket'], diff --git a/app/Services/WhatsappService.php b/app/Services/WhatsappService.php index a8cf80b..0b8c3d0 100644 --- a/app/Services/WhatsappService.php +++ b/app/Services/WhatsappService.php @@ -27,28 +27,54 @@ public function __construct() } /** - * Enviar documento por WhatsApp + * Enviar documento por WhatsApp usando plantilla facturas_pdv */ public function sendDocument( string $phoneNumber, string $documentUrl, - string $caption, string $filename, string $userEmail, string $ticket, string $customerName ): array { try { - // Construir el mensaje de WhatsApp + // Construir el mensaje de WhatsApp usando plantilla $whatsappMessage = json_encode([ 'messaging_product' => 'whatsapp', - 'recipient_type' => 'individual', 'to' => $this->cleanPhoneNumber($phoneNumber), - 'type' => 'document', - 'document' => [ - 'link' => $documentUrl, - 'caption' => $caption, - 'filename' => $filename, + 'type' => 'template', + 'template' => [ + 'name' => 'facturas_pdv', + 'language' => [ + '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( phoneNumber: $phoneNumber, documentUrl: $pdfUrl, - caption: "Factura {$invoiceNumber} - {$customerName}", filename: "Factura_{$invoiceNumber}.pdf", userEmail: $this->email, ticket: $invoiceNumber, @@ -141,7 +166,6 @@ public function sendInvoice( $xmlResult = $this->sendDocument( phoneNumber: $phoneNumber, documentUrl: $xmlUrl, - caption: "XML - Factura {$invoiceNumber}", filename: "Factura_{$invoiceNumber}.xml", userEmail: $this->email, ticket: "{$invoiceNumber}_XML",