PHP code example of binary-cats / laravel-bigbluebutton-webhooks

1. Go to this page and download the library: Download binary-cats/laravel-bigbluebutton-webhooks 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/ */

    

binary-cats / laravel-bigbluebutton-webhooks example snippets


return [

    /*
     * BigBlueButton will sign each webhook using a shared secret.
     */
    'signing_secret' => env('BBB_SECRET'),

    /*
     * You can define the job that should be run when a certain webhook hits your application
     * here. The key is the name of the BigBlueButton event type with the `.` replaced by a `_`.
     * 
     * The package will automatically convert the keys to lowercase, but you should
     * be cognisant of the fact that array keys are case-sensitive
     */
    'jobs' => [
        'meeting-created' => \BinaryCats\BigBlueButtonWebhooks\Jobs\MeetingCreatedJob::class,
    ],

    /*
     * The classname of the model to be used. The class should equal or extend
     * Spatie\WebhookClient\Models\WebhookCall
     */
    'model' => \BinaryCats\BigBlueButtonWebhooks\WebhookCall::class,

    /*
     * The classname of the model to be used. The class should equal or extend
     * Spatie\WebhookClient\ProcessWebhookJob
     */
    'process_webhook_job' => \BinaryCats\BigBlueButtonWebhooks\ProcessBigBlueButtonWebhookJob::class,
];

# routes\web.php
Route::bigbluebuttonWebhooks('webhooks/bigbluebutton');

protected $except = [
    'webhooks/bigbluebutton',
];



namespace App\Jobs\BigBlueButtonWebhooks;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;

class HandleDelivered implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /** @var \Spatie\WebhookClient\Models\WebhookCall */
    public $webhookCall;

    public function __construct(WebhookCall $webhookCall)
    {
        $this->webhookCall = $webhookCall;
    }

    public function handle()
    {
        // do your work here

        // you can access the payload of the webhook call with `$this->webhookCall->payload`
    }
}

// config/bigbluebutton-webhooks.php

'jobs' => [
    'meeting-created' => \App\Jobs\BigBlueButtonWebhooks\MeetingCreatedJob::class,
],

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'bigbluebutton-webhooks::meeting-created' => [
        App\Listeners\MeetingCreatedListener::class,
    ],
];



namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;

class MeetingCreatedListener implements ShouldQueue
{
    public function handle(WebhookCall $webhookCall)
    {
        // do your work here

        // you can access the payload of the webhook call with `$webhookCall->payload`
    }
}

use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Spatie\WebhookClient\Models\WebhookCall as Model;
use Spatie\WebhookClient\WebhookConfig;

class WebhookCall extends Model
{
    /**
     * @param  \Spatie\WebhookClient\WebhookConfig  $config
     * @param  \Illuminate\Http\Request  $request
     * @return \Spatie\WebhookClient\Models\WebhookCall
     */
    public static function storeWebhook(WebhookConfig $config, Request $request): Model
    {
        // bigblubutton payload is build in expectation of multiple events
        $payload = $request->input();
        // transform event
        if ($event = Arr::get($payload, 'event', null) and is_string($event)) {
            $payload['event'] = json_decode($event, true);
        }
        // take the headers form the top
        $headers = self::headersToStore($config, $request);
        // parse and return
        return self::create([
            'name' => $config->name,
            'url' => $request->fullUrl(),
            'headers' => $headers,
            'payload' => $payload,
        ]);
    }
}

use Spatie\WebhookClient\Models\WebhookCall;
use BinaryCats\BigBlueButtonWebhooks\ProcessBigBlueButtonWebhookJob;

dispatch(new ProcessBigBlueButtonWebhookJob(WebhookCall::find($id)));

use BinaryCats\BigBlueButtonWebhooks\ProcessBigBlueButtonWebhookJob;

class MyCustomBigBlueButtonWebhookJob extends ProcessBigBlueButtonWebhookJob
{
    public function handle()
    {
        // do some custom stuff beforehand

        parent::handle();

        // do some custom stuff afterwards
    }
}

Route::bigbluebuttonWebhooks('webhooks/bigbluebutton/{configKey}');

Route::post('webhooks/bigbluebutton/{configKey}', 'BinaryCats\BigBlueButtonWebhooks\BigBlueButtonWebhooksController');

// secret for when BigBlueButton posts to webhooks/bigbluebutton/account
'signing_secret_account' => 'whsec_abc',
// secret for when BigBlueButton posts to webhooks/bigbluebutton/my-named-secret
'signing_secret_my-named-secret' => 'whsec_123',
bash
php artisan vendor:publish --provider="BinaryCats\BigBlueButtonWebhooks\BigBlueButtonWebhooksServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="migrations"
bash
php artisan migrate