<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wallacemartinss / filament-whatsapp-conector example snippets
use WallaceMartinss\FilamentEvolution\FilamentEvolutionPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FilamentEvolutionPlugin::make(),
]);
}
FilamentEvolutionPlugin::make()
->whatsappInstanceResource() // Show instances (default: true)
->viewMessageHistory() // Show message history
->viewWebhookLogs() // Show webhook logs
use Illuminate\Support\Facades\Schedule;
Schedule::command('evolution:cleanup')->daily();
use WallaceMartinss\FilamentEvolution\Actions\SendWhatsappMessageAction;
// In a table
public function table(Table $table): Table
{
return $table
->actions([
SendWhatsappMessageAction::make(),
]);
}
// In a page header
protected function getHeaderActions(): array
{
return [
SendWhatsappMessageAction::make(),
];
}
// Using attribute name
SendWhatsappMessageAction::make()
->numberFrom('phone'),
// Using dot notation for relationships
SendWhatsappMessageAction::make()
->numberFrom('contact.phone'),
// Using closure for custom logic
SendWhatsappMessageAction::make()
->numberFrom(fn ($record) => $record->celular ?? $record->telefone),
// Also set instance from record
SendWhatsappMessageAction::make()
->numberFrom('phone')
->instanceFrom('whatsapp_instance_id'),
SendWhatsappMessageAction::make()
->hideInstanceSelect() // Hide instance selector
->hideNumberInput() // Hide phone number input
->textOnly() // Only allow text messages (hide file upload)
use WallaceMartinss\FilamentEvolution\Enums\MessageTypeEnum;
SendWhatsappMessageAction::make()
->allowedTypes([
MessageTypeEnum::TEXT,
MessageTypeEnum::IMAGE,
]);
SendWhatsappMessageAction::make()
->disk('s3') // Use S3 for file uploads
use WallaceMartinss\FilamentEvolution\Concerns\CanSendWhatsappMessage;
class InvoiceService
{
use CanSendWhatsappMessage;
public function sendPaymentReminder(Invoice $invoice): void
{
$this->sendWhatsappText(
$invoice->customer->phone,
"Hello {$invoice->customer->name}, your invoice #{$invoice->number} is due on {$invoice->due_date->format('d/m/Y')}."
);
}
public function sendInvoicePdf(Invoice $invoice): void
{
$this->sendWhatsappDocument(
$invoice->customer->phone,
$invoice->pdf_path,
"invoice-{$invoice->number}.pdf",
"Your invoice is ready!"
);
}
public function sendPromoImage(Customer $customer, string $imagePath): void
{
$this->sendWhatsappImage(
$customer->phone,
$imagePath,
"Special promotion just for you! 🎉"
);
}
}
class TenantInvoiceService
{
use CanSendWhatsappMessage;
protected function getWhatsappInstanceId(): ?string
{
// Use tenant's specific WhatsApp instance
return auth()->user()->tenant->whatsapp_instance_id;
}
}
use WallaceMartinss\FilamentEvolution\Facades\Whatsapp;
Whatsapp::sendButtons(
instanceId: $instanceId,
number: '5511999999999',
description: 'Would you like to confirm your appointment?',
buttons: [
['type' => 'reply', 'displayText' => 'Yes', 'id' => 'confirm-yes'],
['type' => 'reply', 'displayText' => 'No', 'id' => 'confirm-no'],
['type' => 'reply', 'displayText' => 'Reschedule', 'id' => 'reschedule'],
],
title: 'Appointment Confirmation',
footer: 'Reply within 24h',
);
// Using the Facade with S3
Whatsapp::sendDocument($instanceId, $number, 'documents/report.pdf', 'report.pdf', null, 's3');
// Using the Action with custom disk
SendWhatsappMessageAction::make()->disk('s3');