Created
January 6, 2022 22:13
-
-
Save ssddanbrown/5e62dbbb96b6f239da3355c47772abd6 to your computer and use it in GitHub Desktop.
BookStack Webhook Call Before Hook Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use BookStack\Actions\Webhook; | |
use BookStack\Entities\Models\Page; | |
use BookStack\Facades\Theme; | |
use BookStack\Theming\ThemeEvents; | |
Theme::listen(ThemeEvents::WEBHOOK_CALL_BEFORE, function (string $event, Webhook $webhook, $detail) { | |
// Add a condition to only run this custom logic for specific webhook calls. | |
if ($webhook->name === 'Debug Webhook') { | |
// Build and return the data which will be sent as JSON to the endpoint. | |
$webhookData = [ | |
'the_event' => $event, | |
]; | |
if ($detail instanceof Page) { | |
$webhookData['text'] = 'The page updated was named: ' . $detail->name; | |
} | |
return $webhookData; | |
} | |
return null; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment