Pre-Hook Events

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.

Overview

Pre-hook events enable you to create sophisticated moderation and control systems by intercepting user actions before they’re executed. This allows for:
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:

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"
  ]
}

Implementation Guide

Event Processing Workflow

app.post('/webhooks/prehook', (req, res) => {
  const { eventName, data, actor } = req.body;
  
  try {
    switch (eventName) {
      case 'message.shouldCreate':
        return handleMessageCreate(data, actor, res);
      case 'post.shouldCreate':
        return handlePostCreate(data, actor, res);
      default:
        return res.json({ action: 'allow' });
    }
  } catch (error) {
    console.error('Pre-hook error:', error);
    return res.json({ action: 'allow' }); // Fail open
  }
});

function handleMessageCreate(data, actor, res) {
  // Custom validation logic
  if (containsSpam(data.text)) {
    return res.json({
      action: 'deny',
      message: 'Message contains spam content'
    });
  }
  
  // Allow with content modification
  return res.json({
    action: 'allow',
    data: {
      ...data,
      text: moderateContent(data.text)
    }
  });
}

Supported Events

Best Practices

Troubleshooting

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.