marjose123/filament-webhook-server
Add a webhook server to your Filament app: receive, validate, and manage incoming webhooks with a clean admin UI. Configure endpoints and events, inspect payloads, and monitor delivery from your Filament panel—all in a Laravel-friendly package.
## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require marjose123/filament-webhook-server
php artisan vendor:publish --tag="filament-webhook-server-migrations"
php artisan migrate
Register Plugin:
Add the plugin to your Filament panel configuration (app/Providers/Filament/AdminPanelProvider.php):
use Marjose123\FilamentWebhookServer\WebhookPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
WebhookPlugin::make()->enablePlugin(),
]);
}
First Use Case:
User) and configuring the target URL, events (created, updated, deleted), and payload format (Summary, All, or Custom).Model Integration:
excludedModels()/includeModels() in the plugin configuration:
WebhookPlugin::make()
->includeModels([\App\Models\Order::class])
->excludedModels([\App\Models\Draft::class])
->enablePlugin()
Payload Customization:
Summary (basic fields) or All (full model data).Webhookable interface in your model:
use Marjose123\FilamentWebhookServer\Contracts\Webhookable;
class Order extends Model implements Webhookable
{
public function toWebhookPayload(): array
{
return [
'order_id' => $this->id,
'total' => $this->amount,
'customer_email' => $this->user->email,
];
}
}
Event Handling:
created, updated, and deleted events by default.AppServiceProvider:
public function boot()
{
\App\Models\User::created(function ($user) {
// Custom logic before webhook dispatch
});
}
API Access:
WebhookPlugin::make()->enableApiRoutes()->enablePlugin()
POST /filament/webhooks).Logging and History:
keepLogs():
WebhookPlugin::make()->keepLogs()->enablePlugin()
Dynamic Configuration:
WebhookPlugin::make()->polling(5)->enablePlugin() // Poll every 5 seconds
Multi-Tenant Support:
WebhookPlugin::make()->cluster('tenant-cluster')->enablePlugin()
Testing:
Http::fake():
use Illuminate\Support\Facades\Http;
public function test_webhook_delivery()
{
Http::fake();
$user = User::create([...]);
// Assert webhook was called
}
Security:
// In your webhook handler middleware
public function handle(Request $request, Closure $next)
{
if (!$this->validateSignature($request)) {
abort(403);
}
return $next($request);
}
Model Registration Issues:
php artisan vendor:publish --tag="filament-webhook-server-migrations" --force
php artisan migrate:fresh
Payload Serialization Errors:
toWebhookPayload():
public function toWebhookPayload(): array
{
return [
'user_email' => $this->user?->email ?? null,
];
}
Event Timing:
// In your model observer
public function created(User $user)
{
dispatch(new DispatchWebhook($user));
}
API Route Conflicts:
enableApiRoutes() clashing with existing routes.WebhookPlugin::make()
->enableApiRoutes()
->apiPrefix('admin/webhooks')
->enablePlugin()
Performance:
Summary format. For bulk operations, batch events:
// In your webhook service
public function dispatchBatch(array $events)
{
foreach (array_chunk($events, 50) as $chunk) {
Http::post($url, ['events' => $chunk]);
}
}
Log Webhook Payloads:
keepLogs() and check the Webhook History tab for raw payloads.Test Locally:
ngrok http 8000
https://your-ngrok-url.ngrok.io/webhook-endpoint.Validate Signatures:
public function handleStripeWebhook(Request $request)
{
$payload = $request->getContent();
$sigHeader = $request->header('Stripe-Signature');
if (!\Stripe\Webhook::constructEvent($payload, $sigHeader, config('services.stripe.webhook_secret'))) {
abort(400);
}
// Process event
}
Monitor Failures:
// In your webhook service
public function sendWebhook($url, $payload)
{
try {
Http::post($url, $payload);
} catch (\Exception $e) {
RetryFailedWebhook::dispatch($url, $payload, $e->getMessage());
}
}
Custom Pages:
WebhookPlugin::make()
->customPageUsing(
webhookPage: \App\Filament\Pages\CustomWebhookPage::class,
webhookHistoryPage: \App\Filament\Pages\CustomHistoryPage::class
)
->enablePlugin()
Event Extensions:
published for a Post model):
// In your model observer
public function published(Post $post)
{
event(new WebhookEvent($post, 'published'));
}
Middleware:
Route::middleware(['auth:sanctum', 'webhook.verify'])->post('/webhooks', [WebhookController::class, 'store']);
Translations:
// In your language provider
public function boot()
{
$this->loadTranslationsFrom(__DIR__.'/lang', 'filament-webhook-server');
}
Polling Intervals:
10 seconds) to avoid rate limits or excessive load.SSL Verification:
// In config/filament-webhook-server.php
'webhook' =>
How can I help you explore Laravel packages today?