Comments (1)
I'd suggest the theme system, but I don't think the webhook event covers it:
public function __construct(Webhook $webhook, string $event, Loggable|string $detail)
{
$this->webhook = $webhook;
$this->initiator = user();
$this->initiatedTime = time();
$themeResponse = Theme::dispatch(ThemeEvents::WEBHOOK_CALL_BEFORE, $event, $this->webhook, $detail, $this->initiator, $this->initiatedTime);
$this->webhookData = $themeResponse ?? WebhookFormatter::getDefault($event, $this->webhook, $detail, $this->initiator, $this->initiatedTime)->format();
}
As far as I can tell, it can't change the webhook's data, only change the data that gets sent. It would be weird if you could change endpoints in place. The only other option would be to make a different webhook for each channel you want, and then set the output to empty if the event is for a book you don't care about for that endpoint:
<?php
use BookStack\Activity\Models\Loggable;
use BookStack\Activity\Models\Webhook;
use BookStack\Activity\Tools\WebhookFormatter;
use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;
use BookStack\Users\Models\User;
function selectiveFormat(array $defaultWebhookData): array
{
$book_id = $defaultWebhookData['related_item']['book_id'];
$webhook_name = $defaultWebhookData['webhook_name']
if ( !(
($book_id == 1 && $webhook_name == "Team 1 Webhook") ||
($book_id == 2 && $webhook_name == "Team 2 Webhook") ||
($book_id == 3 && $webhook_name == "Team 3 Webhook") ||
($book_id == 4 && $webhook_name == "Team 4 Webhook")
)
) {
// If it's a teams webhook, but the name and book ID don't match, then just return nothing and cause a 400 error.
return [];
}
return null;
}
Theme::listen(ThemeEvents::WEBHOOK_CALL_BEFORE, function (
string $event,
Webhook $webhook,
string|Loggable $detail,
User $initiator,
int $initTime,
) {
if (str_starts_with($webhook->endpoint, 'https://teams.webhook.whatever')) {
$defaultData = WebhookFormatter::getDefault($event, $webhook, $detail, $initiator, $initTime);
return selectiveFormat($defaultData->format());
}
// Otherwise return null to leave the webhook data alone
return null;
});
This will return []
when a book ID and webhook name according to your manual specifications don't match, but will return the normal value when they do.
The main problem with this is that it scales pretty badly with each team added - if you have 5 teams, that's 5 events firing and 5 webhooks trying to send data per action the webhook is listening to.
This is pretty heavily adapted from this page where Dan Brown went over formatting webhooks differently for Pushover.
(Disclaimer: I haven't tested this code due to time constraints on my end, so there might be some issues with how it grabs the data from the webhook for the webhook name and book ID, but that should be easy enough to debug)
from bookstack.
Related Issues (20)
- Tiered permissions - Managers can promote employees to managers, but not to admins. HOT 1
- LDAP Group sync dont works HOT 9
- Logging of mails that could not be delivered.
- How Fix Access Denied Error? HOT 3
- Improve/clarify backup code description text
- MFA setup view: Titles are not visible on dark mode
- Missing avatars after update to Bookstack v24.05 HOT 2
- Tamil Translation of Bookstack
- Div tag for whole page HOT 3
- Could not find driver issue HOT 4
- Request to open translation contribution for Bengali language in crowdin
- Scoped Webhooks
- Issues setting up M365 SMTP email sending HOT 2
- Diff arbitrary revisions of pages HOT 1
- Change inline code highlighted text HOT 2
- GIF Thumbnail creation fails, breaking the image picker window HOT 12
- Nested collapsible blocks: Ghost inline-code block
- Editor draft actions should dismiss existing notifications so success notifications are clear HOT 3
- Can't create a first page: Illegal offset type HOT 5
- "Override permissions for role" Not Working HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bookstack.