terpise/laravel-webhook

1.0.9 2023-08-15 10:29 UTC

This package is auto-updated.

Last update: 2024-05-15 12:14:01 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A webhook is a way for an app to provide information to another app about a particular event. The way the two apps communicate is with a simple HTTP request.

Installation

You can install the package via composer:

composer require terpise/laravel-webhook

You can publish the config file with:

php artisan vendor:publish --tag=webhook-config

You can publish the migrations file with:

php artisan vendor:publish --tag=webhook-migrations

Run migrations:

php artisan migrate

You can make client with:

php artisan webhook:make
php artisan queue:work

Client

Setup callback:

Route::get('callback', [WebhookClientController::class, 'verify'])->middleware(VerifyToken::class);
Route::post('callback', [WebhookClientController::class, 'callback'])->middleware(VerifyToken::class);

// verify use callback authentication when registering
// callback method you can get data from webhook
// middleware for checking the authenticity of the callback, use 'verify_token'

public function verify(Request $request)
{
    return new Response(['challenge' => $request->get('challenge')]);
}

Create subscribe:

$  curl -X POST https://www.domain.com/webhooks/subscribe \
      -F client_id=10 \
      -F client_secret=7b2946535949ae70f015d696d8ac602830ece412 \
      -F callback_url=https://www.domain-client.com/callback \
      -F verify_token=5359435949ae70f015d694656d8ac6

View subscribe:

$  curl -X GET https://www.domain.com/webhooks/subscribe \
      -F client_id=10 \
      -F client_secret=7b2946535949ae70f015d696d8ac602830ece412

Unsubscribe:

$  curl -X POST https://www.domain.com/webhooks/unsubscribe \
      -F client_id=10 \
      -F client_secret=7b2946535949ae70f015d696d8ac602830ece412

Use

WebhookEvent::dispatch([
    "event_time" => now(),
    "event_type" => 'create',
    "object_id" => 888888,
    "object_type" => "users",
]);

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.