Flarum Webhook
import-ai/flarum-webhook
Trigger webhooks when users create new posts
- Downloads
- 17
- Version control
- github.com/import-ai/flarum-webhook
Flarum Webhook
This file provides guidance to developers when working with code in this repository.
Overview
This is a Flarum extension (import-ai/flarum-webhook) that triggers HTTP webhooks for various forum events including post creation, editing, deletion, and discussion changes. It sends POST requests with JSON payloads containing full model data.
Development Commands
Frontend (JavaScript)
cd js
npm install # Install dependencies
npm run dev # Watch mode for development
npm run build # Production build
Architecture
Backend (PHP)
- Namespace:
ImportAI\Webhook - Entry point:
extend.php- Registers extenders for admin frontend, locales, event listeners, and settings - Event listeners:
src/Listener/PostCreatedListener.php- Listens toFlarum\Post\Event\Postedfor new postssrc/Listener/PostRevisedListener.php- Listens toFlarum\Post\Event\Revisedfor post editssrc/Listener/PostHiddenListener.php- Listens toFlarum\Post\Event\Hiddenfor soft-deleted (hidden) postssrc/Listener/PostDeletedListener.php- Listens toFlarum\Post\Event\Deletedfor hard-deleted postssrc/Listener/DiscussionRenamedListener.php- Listens toFlarum\Discussion\Event\Renamedfor title changessrc/Listener/DiscussionHiddenListener.php- Listens toFlarum\Discussion\Event\Hiddenfor soft-deleted (hidden) discussionssrc/Listener/DiscussionDeletedListener.php- Listens toFlarum\Discussion\Event\Deletedfor hard-deleted discussions
Frontend (JavaScript)
- Admin panel:
js/src/admin/index.js- Registers a settings field for the webhook URL
Settings
import-ai-webhook.webhook_url- The target URL for webhook POST requests
Webhook Payload
The webhook sends a JSON payload with full model data. The payload structure varies by event type:
Post Events (post.created, post.revised, post.hidden, post.deleted):
{
"event": "post.created | post.revised | post.hidden | post.deleted",
"user": { /* full user model attributes */ },
"post": { /* full post model attributes */ },
"discussion": { /* full discussion model attributes */ },
"actor": { /* full actor model attributes (user who triggered the event) */ }
}
Discussion Renamed Event (discussion.renamed):
{
"event": "discussion.renamed",
"discussion": { /* full discussion model attributes */ },
"old_title": "Previous discussion title",
"actor": { /* full actor model attributes */ }
}
Discussion Deleted Event (discussion.hidden, discussion.deleted):
{
"event": "discussion.hidden | discussion.deleted",
"discussion": { /* full discussion model attributes */ },
"actor": { /* full actor model attributes */ }
}
Event Types:
post.created- Triggered when a new post is createdpost.revised- Triggered when an existing post is editedpost.hidden- Triggered when a post is soft-deleted (hidden) via the UIpost.deleted- Triggered when a post is permanently (hard) deleteddiscussion.renamed- Triggered when a discussion title is changeddiscussion.hidden- Triggered when a discussion is soft-deleted (hidden) via the UIdiscussion.deleted- Triggered when a discussion is permanently (hard) deleted
Identifying Discussion Creation
Flarum Webhook does not have a separate discussion.created event. When a new discussion is created, it triggers a post.created event for the first post. To identify if a post.created event represents a new discussion:
{
"event": "post.created",
"post": {
"number": 1, // First post has number = 1
"id": 9,
// ...
},
"discussion": {
"first_post_id": null, // null for newly created discussions (or equals post.id)
"comment_count": 1, // Only one comment in the discussion
"last_post_id": 9, // Equals post.id
// ...
}
}
Check conditions:
post.number === 1- The post is the first in sequencediscussion.comment_count === 1- Only one comment existsdiscussion.first_post_id === nullORdiscussion.first_post_id === post.id- For newly created discussions
Localization
locale/en.yml- English translationslocale/zh-Hans.yml- Simplified Chinese translations
Git Commit Guidelines
Format: type(scope): Description
Types:
feat- New featuresfix- Bug fixesdocs- Documentation changesstyle- Styling changesrefactor- Code refactoringperf- Performance improvementstest- Test additions or changeschore- Maintenance tasksrevert- Revert previous commitsbuild- Build system changes
Rules:
- Scope is required (e.g.,
sidebar,tasks,auth) - Description in sentence case with capital first letter
- Use present tense action verbs (Add, Fix, Support, Update, Replace, Optimize)
- No period at the end
- Keep it concise and focused
Examples:
feat(apple): Support apple signin
fix(sidebar): Change the abnormal scrolling
chore(children): Optimize children api
refactor(tasks): Add timeout status
Do NOT include:
- "Generated with Claude Code" or similar attribution
- "Co-Authored-By: Claude" or any Claude co-author tags
Versions
-
Works with Flarum v1.8.9.
-
Unlikely to work with Flarum v2.0.0-beta.6.
-
Last version v0.1.2 tagged.
-
3 more versions.
-
Extension created.