Problem
Currently, BookStack does not have activity hooks or webhooks for attachment-related events. This makes it impossible to integrate external services (like AI processing, backup systems, or notification services) when attachments are uploaded, updated, or deleted.
Use Cases
- AI Processing: Automatically process uploaded documents (e.g., extract content from PDFs, generate summaries)
- Backup Systems: Trigger backups when files are uploaded or modified
- External Notifications: Notify Slack/Discord when files are uploaded
- Audit Logging: Track all file uploads/downloads for compliance
Current Workaround
The only available workaround is to monitor page_update events and parse HTML content for attachment links, which is unreliable and indirect.
Proposed Solution
Add three new activity types and webhooks:
attachment_create - Triggered when a file is uploaded to a page
attachment_update - Triggered when an attachment is updated/replaced
attachment_delete - Triggered when an attachment is deleted
Implementation Approach
Add constants to ActivityType.php:
const ATTACHMENT_CREATE = 'attachment_create';
const ATTACHMENT_UPDATE = 'attachment_update';
const ATTACHMENT_DELETE = 'attachment_delete';
Add activity logging in AttachmentService.php:
// In saveNewUpload()
Activity::add(ActivityType::ATTACHMENT_CREATE, $attachment);
// In saveUpdatedUpload()
Activity::add(ActivityType::ATTACHMENT_UPDATE, $attachment);
// In deleteFile()
Activity::add(ActivityType::ATTACHMENT_DELETE, $attachment);
Webhook Payload Example
{
"event": "attachment_create",
"text": "Admin uploaded attachment \"document.pdf\"",
"triggered_by": {
"id": 1,
"name": "Admin"
},
"related_item": {
"id": 5,
"name": "document.pdf",
"extension": "pdf",
"page_id": 123,
"external": false
}
}
Impact
- Low breaking change risk: Only adds new events, existing functionality unaffected
- Backward compatible: Existing webhooks continue to work
- Theme hooks compatible: Users can also use
Theme::listen(ThemeEvents::ACTIVITY_LOGGED) and filter by the new event types
Priority
Medium - This is a common enterprise requirement for document management systems.
Is this something the maintainers would consider? I'd be willing to contribute a PR if this is desired.
Problem
Currently, BookStack does not have activity hooks or webhooks for attachment-related events. This makes it impossible to integrate external services (like AI processing, backup systems, or notification services) when attachments are uploaded, updated, or deleted.
Use Cases
Current Workaround
The only available workaround is to monitor
page_updateevents and parse HTML content for attachment links, which is unreliable and indirect.Proposed Solution
Add three new activity types and webhooks:
attachment_create- Triggered when a file is uploaded to a pageattachment_update- Triggered when an attachment is updated/replacedattachment_delete- Triggered when an attachment is deletedImplementation Approach
Add constants to
ActivityType.php:Add activity logging in
AttachmentService.php:Webhook Payload Example
{ "event": "attachment_create", "text": "Admin uploaded attachment \"document.pdf\"", "triggered_by": { "id": 1, "name": "Admin" }, "related_item": { "id": 5, "name": "document.pdf", "extension": "pdf", "page_id": 123, "external": false } }Impact
Theme::listen(ThemeEvents::ACTIVITY_LOGGED)and filter by the new event typesPriority
Medium - This is a common enterprise requirement for document management systems.
Is this something the maintainers would consider? I'd be willing to contribute a PR if this is desired.