Skip to content

Feature Request: Message interception hooks (message:received, message:sending) #13004

@mmartinovsky-png

Description

@mmartinovsky-png

Summary

Request for hooks that allow plugins to intercept and modify messages before they reach the AI model and after the AI responds but before delivery to the user.

Use Case: Privacy/PII Anonymization

Building a privacy layer plugin that needs to:

  1. On message_received: Anonymize names, identifiers, addresses, etc. before sending to the AI API
  2. On message_sending: De-anonymize placeholders in AI responses before displaying to user

This keeps sensitive PII out of API logs while maintaining a seamless user experience. Useful for any regulated industry or privacy-conscious deployment.

Current State

The hooks documentation lists these as "Future Events (Planned)":

  • message:sent: When a message is sent
  • message:received: When a message is received

The plugin API doesn't currently expose api.registerHook() for message events.

Proposed API

// In plugin register function
api.registerHook('message_received', (ctx) => {
  // ctx.message.text = anonymize(ctx.message.text);
});

api.registerHook('message_sending', (ctx) => {
  // ctx.message.text = deanonymize(ctx.message.text);
});

Implementation Notes

  • Hooks should be synchronous or support async with reasonable timeout
  • Should fire for all channels (Telegram, WhatsApp, etc.)
  • Should include context like channel, sender, session
  • Order of hook execution should be deterministic

Workarounds Considered

  • Pre-processing files before each task (partial solution, doesn't cover chat)
  • Modifying channel plugins directly (not maintainable)

Happy to help test once available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions