<?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,
];
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`
}
}
/**
* 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
}
}
// 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',