Skip to content

Feature Request: Add Activity Hooks and Webhooks for Attachment Events #6098

@thuanpham582002

Description

@thuanpham582002

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

  1. AI Processing: Automatically process uploaded documents (e.g., extract content from PDFs, generate summaries)
  2. Backup Systems: Trigger backups when files are uploaded or modified
  3. External Notifications: Notify Slack/Discord when files are uploaded
  4. 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:

  1. attachment_create - Triggered when a file is uploaded to a page
  2. attachment_update - Triggered when an attachment is updated/replaced
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions