feat: actualizar envío de documentos por WhatsApp para usar plantilla 'facturas_pdv' y eliminar el campo 'caption'
This commit is contained in:
parent
19885a0aba
commit
b253e8a308
@ -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'],
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user