PHP code example of wallacemartinss / filament-whatsapp-conector

1. Go to this page and download the library: Download wallacemartinss/filament-whatsapp-conector library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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()
    ->viewMessageHistory()    // Enable message history resource
    ->viewWebhookLogs()       // Enable webhook logs resource

FilamentEvolutionPlugin::make()
    ->whatsappInstanceResource()  // Show instances (default: true)
    ->viewMessageHistory()        // Show message history
    ->viewWebhookLogs()           // Show webhook logs

// config/filament-evolution.php

return [
    // Queue settings
    'queue' => [
        'enabled' => true,
        'connection' => null,  // null = default connection
        'name' => 'default',   // queue name
    ],

    // Storage settings
    'storage' => [
        'webhooks' => true,    // save webhooks to database
        'messages' => true,    // save messages to database
    ],

    // Cleanup policy (automatic deletion of old records)
    'cleanup' => [
        'webhooks_days' => 30, // delete webhooks older than 30 days
        'messages_days' => 90, // delete messages older than 90 days
    ],

    // Instance defaults
    'instance' => [
        'reject_call' => false,
        'always_online' => false,
        // ...
    ],

    // Multi-tenancy
    'tenancy' => [
        'enabled' => false,
        'column' => 'team_id',
        'table' => 'teams',
        'model' => 'App\\Models\\Team',
    ],
];

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(),
    ];
}

SendWhatsappMessageAction::make()
    ->number('5511999999999')              // Default phone number
    ->instance($instanceId)                 // Default instance
    ->message('Hello World!')               // Default message

// 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\Facades\Whatsapp;

// Send text
Whatsapp::sendText($instanceId, '5511999999999', 'Hello!');

// Send image with caption
Whatsapp::sendImage($instanceId, '5511999999999', 'path/to/image.jpg', 'Check this out!');

// Send video with caption
Whatsapp::sendVideo($instanceId, '5511999999999', 'path/to/video.mp4', 'Watch this!');

// Send audio
Whatsapp::sendAudio($instanceId, '5511999999999', 'path/to/audio.mp3');

// Send document
Whatsapp::sendDocument($instanceId, '5511999999999', 'path/to/file.pdf', 'report.pdf', 'Monthly Report');

// Send location
Whatsapp::sendLocation($instanceId, '5511999999999', -23.5505, -46.6333, 'My Office', 'São Paulo, SP');

// Send contact card
Whatsapp::sendContact($instanceId, '5511999999999', 'John Doe', '+5511888888888');

// Generic send method
Whatsapp::send($instanceId, '5511999999999', 'text', 'Hello World!');
Whatsapp::send($instanceId, '5511999999999', 'image', 'path/to/image.jpg', ['caption' => 'Nice!']);

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',
);

Whatsapp::sendCta(
    instanceId: $instanceId,
    number: '5511999999999',
    description: 'Tap below to visit our site or call us.',
    buttons: [
        ['type' => 'url',  'displayText' => 'Visit Site', 'url' => 'https://example.com'],
        ['type' => 'call', 'displayText' => 'Call Us',    'phoneNumber' => '+5511888888888'],
        // Also supported: ['type' => 'copy', 'displayText' => 'Copy Code', 'copyCode' => 'PROMO10']
    ],
);

Whatsapp::sendPix(
    instanceId: $instanceId,
    number: '5511999999999',
    description: 'Pay your invoice with PIX',
    pix: [
        'currency' => 'BRL',
        'name'     => 'ACME LTDA',
        'keyType'  => 'phone',  // phone | email | cpf | cnpj | random
        'key'      => '5511888888888',
        'amount'   => 199.90,   // optional — omit to let the recipient type the value
    ],
    title: 'Invoice #12345',
    footer: 'Due today',
);

Whatsapp::sendList(
    instanceId: $instanceId,
    number: '5511999999999',
    title: 'Main Menu',
    description: 'Pick an option to continue',
    buttonText: 'View options',
    sections: [
        [
            'title' => 'Support',
            'rows' => [
                ['title' => 'Track order',  'description' => 'Check delivery status', 'rowId' => 'track'],
                ['title' => 'Open ticket',  'description' => 'Talk to a human',       'rowId' => 'ticket'],
            ],
        ],
        [
            'title' => 'Sales',
            'rows' => [
                ['title' => 'Catalog',      'rowId' => 'catalog'],
                ['title' => 'Promotions',   'rowId' => 'promo'],
            ],
        ],
    ],
    footerText: 'We reply 24/7',
);

Whatsapp::sendCarousel(
    instanceId: $instanceId,
    number: '5511999999999',
    message: 'Check out our top picks 🛍️',
    cards: [
        [
            'imageUrl' => 'https://cdn.example.com/product-a.jpg',
            'header'   => 'Product A',
            'body'     => 'Limited edition • R$ 199',
            'buttons'  => [
                ['type' => 'reply', 'displayText' => 'Buy now', 'id' => 'buy-a'],
                ['type' => 'url',   'displayText' => 'Details', 'url' => 'https://example.com/a'],
            ],
        ],
        [
            'imageUrl' => 'https://cdn.example.com/product-b.jpg',
            'header'   => 'Product B',
            'body'     => 'Best seller • R$ 299',
            'buttons'  => [
                ['type' => 'reply', 'displayText' => 'Buy now', 'id' => 'buy-b'],
            ],
        ],
    ],
);

use WallaceMartinss\FilamentEvolution\Concerns\CanSendWhatsappMessage;

class CheckoutService
{
    use CanSendWhatsappMessage;

    public function sendPaymentOptions(Order $order): void
    {
        $this->sendWhatsappPix(
            number: $order->customer->phone,
            description: "Order #{$order->number} — R$ {$order->total}",
            pix: [
                'currency' => 'BRL',
                'name'     => config('app.name'),
                'keyType'  => 'random',
                'key'      => $order->pix_key,
            ],
            title: 'Complete your purchase',
        );
    }
}

Whatsapp::send($instanceId, '5511999999999', 'buttons', [
    'description' => 'Choose:',
    'title'       => 'Menu',
    'footer'      => null,
    'buttons'     => [
        ['type' => 'reply', 'displayText' => 'A', 'id' => 'a'],
        ['type' => 'reply', 'displayText' => 'B', 'id' => 'b'],
    ],
]);

Whatsapp::send($instanceId, '5511999999999', 'list', [
    'title'       => 'Menu',
    'description' => 'Pick one',
    'buttonText'  => 'Open',
    'sections'    => [/* ... */],
]);

Whatsapp::send($instanceId, '5511999999999', 'carousel', [
    'message' => 'Our products',
    'cards'   => [/* ... */],
]);

SendWhatsappMessageAction::make()
    ->allowedTypes([
        MessageTypeEnum::BUTTONS,
        MessageTypeEnum::CTA,
        MessageTypeEnum::PIX,
        MessageTypeEnum::LIST,
        MessageTypeEnum::CAROUSEL,
    ]);

// 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');

'tenancy' => [
    'enabled' => true,
    'column' => 'team_id',
    'table' => 'teams',
    'model' => 'App\\Models\\Team',
    'column_type' => 'uuid', // 'uuid' or 'id'
],

use WallaceMartinss\FilamentEvolution\Services\EvolutionClient;

$client = app(EvolutionClient::class);

// Create instance
$response = $client->createInstance('my-instance', '5511999999999', true, [
    'reject_call' => true,
    'always_online' => true,
]);

// Get connection state
$state = $client->getConnectionState('my-instance');

// Send text message
$client->sendText('my-instance', '5511999999999', 'Hello World!');

// Send image (path is base64 encoded by the service)
$client->sendImage('my-instance', '5511999999999', $base64Content, 'image.jpg', 'Check this!');
bash
php artisan vendor:publish --tag="filament-evolution-config"
bash
php artisan vendor:publish --tag="filament-evolution-migrations"
php artisan migrate
bash
php artisan queue:work
bash
php artisan vendor:publish --tag="filament-evolution-config"