Skip to main content
Gain granular control over user actions with pre-hook events that allow you to intercept, validate, and modify user interactions before they’re processed. Perfect for implementing custom moderation rules, content filtering, and access control policies.

Real-time Interception

Intercept user actions in real-time before they’re processed

Custom Rules

Build custom validation and moderation logic tailored to your needs

Webhook Integration

Receive events via webhooks and respond with custom actions

Event Catalog

Complete list of interceptable events and their data

Overview

Pre-hook events enable you to create sophisticated moderation and control systems by intercepting user actions before they’re executed. This allows for:
  • Content Filtering: Analyze and modify content before publication
  • User Behavior Control: Restrict access based on custom criteria
  • Real-time Validation: Validate data against business rules
  • Automated Responses: Implement graduated response systems
  • Spam Prevention: Block suspicious posting patterns
  • Content Enhancement: Auto-correct or enrich user content
  • Access Control: Implement channel-specific permission systems
  • Analytics Injection: Add tracking data to user actions
Enterprise Feature: Pre-hook events are available for customers on the Max plan. Contact our sales team to upgrade your plan.

How It Works

Pre-hook events create a validation layer between user actions and their execution:

Response Types

Your webhook endpoint must respond with one of these actions:
{ "action": "allow" }
Allow the action to proceed without modification.
{
  "action": "allow",
  "data": {
    "modified_field": "new_value"
  }
}
Allow the action but modify the data before processing.
{
  "action": "deny",
  "message": "Action denied: Custom reason"
}
Block the action and return an error message to the user.

Getting Started

1

Enable Pre-Hook Events

Configure pre-hook events through the Network Settings API.
2

Set Up Webhook Endpoint

Create an HTTPS endpoint to receive and process pre-hook events.
3

Configure Event Types

Specify which events you want to intercept and process.
4

Test & Monitor

Test your webhook with sample events and monitor response times.

Configuration

PUT /api/v3/network/settings/prehook

{
  "enabled": true,
  "callbackUrl": "https://your-app.com/webhooks/prehook",
  "defaultAction": "allow",
  "events": [
    "message.shouldCreate",
    "message.shouldUpdate",
    "post.shouldCreate"
  ]
}

Supported Events

EventTriggered WhenAvailable Data
message.shouldCreateUser sends a messageMessage content, channel ID, sender
message.shouldUpdateUser edits a messageUpdated content, original message
message.shouldFlagUser flags a messageMessage data, flag reason
message.shouldUnflagUser removes flagMessage data, flag count
Example Payload:
{
  "eventName": "message.shouldCreate",
  "data": {
    "text": "Hello world!",
    "channelId": "ch_123",
    "attachments": [],
    "metadata": {}
  },
  "actor": {
    "_id": "user_456",
    "userId": "user_456"
  }
}
EventTriggered WhenAvailable Data
channel.shouldCreateUser creates channelChannel data, creator
channel.shouldJoinUser joins channelChannel ID, user data
channel.shouldLeaveUser leaves channelChannel ID, user data
channel.shouldUpdateChannel is updatedUpdated channel data
Example Payload:
{
  "eventName": "channel.shouldJoin",
  "data": {
    "channelId": "ch_123",
    "channelType": "live",
    "metadata": {}
  },
  "actor": {
    "_id": "user_456",
    "userId": "user_456"
  }
}
EventTriggered WhenAvailable Data
post.shouldCreateUser creates postPost content, community
post.shouldUpdateUser edits postUpdated content
post.shouldDeleteUser deletes postPost ID, deletion reason
post.shouldFlagUser flags postPost data, flag details
Example Payload:
{
  "eventName": "post.shouldCreate",
  "data": {
    "text": "Check out this amazing feature!",
    "communityId": "comm_789",
    "attachments": [
      {
        "type": "image",
        "url": "https://example.com/image.jpg"
      }
    ]
  },
  "actor": {
    "_id": "user_456",
    "userId": "user_456"
  }
}

Best Practices

  • Fast Response Times: Keep webhook processing under 2 seconds
  • Fail-Safe Design: Default to “allow” on errors to prevent user disruption
  • Async Processing: For complex logic, respond quickly and process asynchronously
  • Monitoring: Track webhook response times and error rates
  • Retry Logic: Implement exponential backoff for external service calls
  • Signature Verification: Always verify webhook signatures
  • HTTPS Only: Use secure HTTPS endpoints for webhook URLs
  • Input Validation: Validate all incoming event data
  • Rate Limiting: Implement rate limiting on your webhook endpoint
  • Logging: Log all events for debugging and audit purposes
  • Clear Error Messages: Provide helpful feedback when denying actions
  • Consistent Policies: Apply rules consistently across all users
  • Graceful Degradation: Handle service outages gracefully
  • Documentation: Document your custom rules for transparency
  • Appeal Process: Provide ways for users to appeal automated decisions

Troubleshooting

Timeout Errors
  • Ensure webhook responds within 3 seconds
  • Implement async processing for complex operations
  • Use caching for frequently accessed data
Invalid Signatures
  • Verify webhook URL configuration
  • Check secret key configuration
  • Ensure payload is parsed correctly
Unexpected Behavior
  • Check default action configuration
  • Verify event type filtering
  • Review webhook response format
Local Testing
# Use ngrok for local webhook testing
ngrok http 3000

# Update webhook URL in console
curl -X PUT "https://api.social.plus/api/v3/network/settings/prehook" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"callbackUrl": "https://your-ngrok-url.ngrok.io/webhook"}'
Monitoring Tools
  • Set up alerts for webhook failures
  • Monitor response time metrics
  • Track action distribution (allow/deny/modify)
  • Use structured logging for better debugging
Production Considerations: Always test pre-hook events thoroughly in a staging environment before deploying to production. Failed or slow webhook responses can impact user experience.