- Add ReDoS protection using safe-regex validation for contentPattern
- Add token bucket rate limiting (10/min per handler) to prevent cost explosions
- Require at least one match condition in Zod schema (reject empty match)
- Change error logging from logVerbose to logWarn for visibility
Includes tests for rate limiter and ReDoS protection.
Add `hooks.internal.messageHandlers` config array for triggering agent
execution when inbound messages match specified conditions. This solves
the problem of important messages (like bug reports) being queued and
potentially missed when cron jobs wake the agent.
Features:
- Match conditions: channelId, conversationId, from, contentPattern (regex),
contentContains (keywords)
- Priority modes: "immediate" (bypass queue) or "queue" (normal flow)
- Execution modes: "exclusive" (handler only) or "parallel" (handler + normal)
- Message transformation: prefix, suffix, or full template with placeholders
- Configurable model and thinking level per handler
Implementation:
- src/config/types.hooks.ts: MessageHandlerConfig and MessageHandlerMatch types
- src/config/zod-schema.hooks.ts: Zod validation schemas
- src/hooks/message-handler-match.ts: Condition matching logic
- src/hooks/message-handler-run.ts: Handler executor using runCronIsolatedAgentTurn
- src/auto-reply/reply/dispatch-from-config.ts: Integration point
- docs/hooks.md: Full documentation with examples
- 28 unit tests for matcher logic
- Add MessageReceivedHookContext type with full message metadata
- Add isMessageReceivedEvent() type guard for type-safe handling
- Trigger hook in dispatchReplyFromConfig() after plugin hooks
- Fire-and-forget execution to avoid blocking message processing
- Works across all 12 channels (whatsapp, telegram, discord, etc.)
- Add comprehensive tests for type guard and hook triggering
- Document message events, context fields, and filtering examples