### Install filament-multifactor-whatsapp with Composer Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Install the package via Composer. Requires PHP 8.2+, Laravel 11.0+, Filament 5.0, and the Evolution API client package. ```bash composer require jeffersongoncalves/filament-multifactor-whatsapp ``` -------------------------------- ### Start Queue Worker Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Command to start a queue worker for handling notification queues. Required when VerifyWhatsappAuthentication implements ShouldQueue. ```bash php artisan queue:work ``` -------------------------------- ### SendWhatsappMessageAction UI examples Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md UI actions to send WhatsApp messages using SendWhatsappMessageAction. Shows usage in a resource table and in a page header with optional defaults for number and message. ```php use WallaceMartinss\FilamentEvolution\Actions\SendWhatsappMessageAction; // In a resource table public function table(Table $table): Table { return $table ->actions([ SendWhatsappMessageAction::make(), ]); } // In a page header protected function getHeaderActions(): array { return [ SendWhatsappMessageAction::make() // Optional sensible defaults ->number('5511999999999') ->message('Hello from EvolutionKit!'), ]; } ``` -------------------------------- ### Publish Config and Migrations Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Artisan commands to publish the plugin's configuration and migration files, then run migrations. Run these in your project root. ```bash php artisan vendor:publish --tag="filament-evolution-config" php artisan vendor:publish --tag="filament-evolution-migrations" php artisan migrate ``` -------------------------------- ### Optional configuration (config/filament-evolution.php) Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Optional configuration file (config/filament-evolution.php) after publishing. Tune queue, storage, cleanup, instance defaults, and tenancy settings. ```php return [ 'queue' => [ 'enabled' => true, 'connection' => null, // default connection 'name' => 'default', ], 'storage' => [ 'webhooks' => true, // persist webhook payloads 'messages' => true, // persist sent/received messages ], 'cleanup' => [ 'webhooks_days' => 30, 'messages_days' => 90, ], 'instance' => [ 'reject_call' => false, 'always_online' => false, // ...other defaults ], 'tenancy' => [ 'enabled' => false, 'column' => 'team_id', 'table' => 'teams', 'model' => 'App\\Models\\Team', ], ]; ``` -------------------------------- ### Config File (filament-multifactor-whatsapp.php) Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Configuration array for the package, specifying the phone column name. ```php return [ 'phone_column_name' => 'phone', ]; ``` -------------------------------- ### Run static analysis and format code Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Run static analysis and code formatting using Composer scripts. These commands are used during development to ensure code quality. ```bash composer analyse ``` ```bash composer format ``` -------------------------------- ### Publish Config with Artisan Command Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Command to publish the package configuration file. ```bash php artisan vendor:publish --tag=filament-multifactor-whatsapp-config ``` -------------------------------- ### Enable WhatsApp authentication in panel with multiFactorAuthentication() Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Activates WhatsApp authentication in the panel by passing a WhatsAppAuthentication instance to the multiFactorAuthentication() method. ```php use Filament\Panel; use JeffersonGoncalves\Filament\MultiFactorWhatsApp\WhatsAppAuthentication; public function panel(Panel $panel): Panel { return $panel // ... ->multiFactorAuthentication([ WhatsAppAuthentication::make(), ]); } ``` -------------------------------- ### Prefill from records Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Prefill the action's number and instance from record attributes using numberFrom and instanceFrom. ```php SendWhatsappMessageAction::make() ->numberFrom('phone') // attribute on the record ->instanceFrom('whatsapp_instance_id'); ``` -------------------------------- ### Media storage environment variables Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Optional environment variables for media storage configuration. You can also specify a custom disk per action with SendWhatsappMessageAction::make()->disk('s3'). ```env EVOLUTION_MEDIA_DISK=public EVOLUTION_MEDIA_DIRECTORY=whatsapp-media EVOLUTION_MEDIA_MAX_SIZE=16384 ``` -------------------------------- ### Implement HasWhatsAppAuthentication on User model Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Implements the HasWhatsAppAuthentication contract on the User model. Requires the 'has_whatsapp_authentication' column and defines the cast and the two required methods. ```php use Filament\Models\Contracts\FilamentUser; use Illuminate\Foundation\Auth\User as Authenticatable; use JeffersonGoncalves\Filament\MultiFactorWhatsApp\Contracts\HasWhatsAppAuthentication; class User extends Authenticatable implements FilamentUser, HasWhatsAppAuthentication { protected function casts(): array { return [ 'has_whatsapp_authentication' => 'boolean', ]; } public function hasWhatsappAuthentication(): bool { return $this->has_whatsapp_authentication; } public function toggleWhatsappAuthentication(bool $condition): void { $this->has_whatsapp_authentication = $condition; $this->save(); } } ``` -------------------------------- ### WhatsAppAuthentication Class Definition Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Main provider class implementing the multi-factor authentication contracts. ```php namespace JeffersonGoncalves\Filament\MultiFactorWhatsApp; use Filament\Auth\MultiFactor\Contracts\HasBeforeChallengeHook; use Filament\Auth\MultiFactor\Contracts\MultiFactorAuthenticationProvider; class WhatsAppAuthentication implements HasBeforeChallengeHook, MultiFactorAuthenticationProvider { public static function make(): static; public function getId(): string; // returns 'whatsapp_code' public function codeExpiryMinutes(int $minutes): static; // default: 4 public function getCodeExpiryMinutes(): int; public function generateCodesUsing(?Closure $callback): static; public function generateCode(): string; // 6-digit zero-padded public function codeNotification(string $notification): static; public function getCodeNotification(): string; public function beforeChallenge(Authenticatable $user): void; // sends code before login challenge public function sendCode(HasWhatsAppAuthentication $user): bool; // rate-limited (max 2) public function verifyCode(string $code): bool; // checks session hash + expiry public function isEnabled(Authenticatable $user): bool; public function enableWhatsappAuthentication(HasWhatsAppAuthentication $user): void; public function getLoginFormLabel(): string; public function getChallengeFormComponents(Authenticatable $user): array; public function getManagementSchemaComponents(): array; public function getActions(): array; } ``` -------------------------------- ### Register WhatsAppAuthentication in Filament panel Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Registers the WhatsApp authentication provider in the Filament panel by passing WhatsAppAuthentication::make() to the multiFactorAuthentication method. ```php use Filament\Panel; use JeffersonGoncalves\Filament\MultiFactorWhatsApp\WhatsAppAuthentication; public function panel(Panel $panel): Panel { return $panel ->multiFactorAuthentication([ WhatsAppAuthentication::make(), ]); } ``` -------------------------------- ### Evolution API Environment Variables Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Required environment variables for the Evolution API integration. Set these in your .env file to configure the API URL, API key, and webhook URL. ```env EVOLUTION_URL=https://your-evolution-api.com EVOLUTION_API_KEY=your_api_key EVOLUTION_WEBHOOK_URL=https://your-app.com/api/webhooks/evolution ``` -------------------------------- ### Schedule cleanup command Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Schedule the cleanup command to run daily using Laravel's scheduler. ```php // routes/console.php use Illuminate\Support\Facades\Schedule; Schedule::command('evolution:cleanup')->daily(); ``` -------------------------------- ### Custom Notification Class Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Sets a custom notification class for sending the code. ```php WhatsAppAuthentication::make() ->codeNotification(MyCustomWhatsAppNotification::class), ``` -------------------------------- ### HasWhatsAppAuthentication Contract Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Interface that models must implement to support WhatsApp authentication. ```php namespace JeffersonGoncalves\Filament\MultiFactorWhatsApp\Contracts; interface HasWhatsAppAuthentication { public function hasWhatsAppAuthentication(): bool; public function toggleWhatsAppAuthentication(bool $condition): void; } ``` -------------------------------- ### Cleanup command Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Cleanup command to remove old webhook and message records. Use --dry-run to preview deletions, or specify custom retention days. ```bash php artisan evolution:cleanup # uses config defaults php artisan evolution:cleanup --dry-run # preview deletions php artisan evolution:cleanup --webhooks-days=7 --messages-days=30 ``` -------------------------------- ### Customize Code Expiry Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Sets the code expiry to 2 minutes, overriding the default of 4 minutes. ```php WhatsAppAuthentication::make() ->codeExpiryMinutes(2), // default: 4 minutes ``` -------------------------------- ### Add has_whatsapp_authentication column to users table Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Adds the 'has_whatsapp_authentication' boolean column to the users table with a default of false. Run this migration to enable the MFA feature. ```php use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; Schema::table('users', function (Blueprint $table) { $table->boolean('has_whatsapp_authentication')->default(false); }); ``` -------------------------------- ### WhatsAppChannel Class Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Channel class responsible for sending the notification. ```php namespace JeffersonGoncalves\Filament\MultiFactorWhatsApp\Notifications; class WhatsAppChannel { public function send(object $notifiable, Notification $notification): void; } ``` -------------------------------- ### Custom Code Generator Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Provides a custom closure to generate a 4-digit zero-padded code. ```php WhatsAppAuthentication::make() ->generateCodesUsing(fn (): string => str_pad((string) random_int(0, 9999), 4, '0', STR_PAD_LEFT)), ``` -------------------------------- ### VerifyWhatsappAuthentication Notification Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/resources/boost/skills/filament-multifactor-whatsapp-development/SKILL.md Notification class that sends the verification code via WhatsApp. ```php namespace JeffersonGoncalves\Filament\MultiFactorWhatsApp\Notifications; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; class VerifyWhatsappAuthentication extends Notification implements ShouldQueue { public function __construct(public string $code, public int $codeExpiryMinutes); public function via(object $notifiable): string; // returns WhatsAppChannel::class public function toWhatsapp(object $notifiable): array; // sends via Evolution API } ``` -------------------------------- ### Limit message types and hide fields Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Limit message types to TEXT and IMAGE, and hide the instance select and number input fields. The textOnly() method further restricts to text messages. ```php use WallaceMartinss\FilamentEvolution\Enums\MessageTypeEnum; SendWhatsappMessageAction::make() ->allowedTypes([MessageTypeEnum::TEXT, MessageTypeEnum::IMAGE]) ->hideInstanceSelect() ->hideNumberInput() ->textOnly(); ``` -------------------------------- ### Cast has_whatsapp_authentication to boolean in User model Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Casts the has_whatsapp_authentication column to boolean in the User model. Required for the column to be treated as a boolean. ```php use Filament\Models\Contracts\FilamentUser; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements FilamentUser { /** * @return array */ protected function casts(): array { return [ // ... 'has_whatsapp_authentication' => 'boolean', ]; } // ... } ``` -------------------------------- ### Set WhatsApp code expiration to 2 minutes with codeExpiryMinutes() Source: https://github.com/jeffersongoncalves/filament-multifactor-whatsapp/blob/2.x/README.md Changes the WhatsApp code expiration time to 2 minutes using the codeExpiryMinutes() method. The default expiration is 4 minutes. ```php use Filament\Panel; use JeffersonGoncalves\Filament\MultiFactorWhatsApp\WhatsAppAuthentication; public function panel(Panel $panel): Panel { return $panel // ... ->multiFactorAuthentication([ WhatsAppAuthentication::make() ->codeExpiryMinutes(2), ]); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.