Skip to content

Comments

feat: add message:received and message:sent internal hook events#2307

Closed
AhmedTheGeek wants to merge 1 commit intoopenclaw:mainfrom
AhmedTheGeek:feat/message-hooks
Closed

feat: add message:received and message:sent internal hook events#2307
AhmedTheGeek wants to merge 1 commit intoopenclaw:mainfrom
AhmedTheGeek:feat/message-hooks

Conversation

@AhmedTheGeek
Copy link

Adds message:received and message:sent events to the internal hook system, enabling HOOK.md-based hooks to subscribe to message lifecycle events.

Changes

  • Added "message" to InternalHookEventType
  • Fire message:received internal hook in dispatch-from-config alongside existing plugin hook
  • Added onDelivered callback to ReplyDispatcherOptions for post-delivery hooks
  • Fire message:sent internal hook after successful reply delivery
  • Wired the existing (but previously unused) plugin message_sent hook
  • Updated docs and tests

Motivation

These events were listed as "Future Events" in the hooks documentation. They enable audit trail tools and other integrations that need to observe the full message lifecycle.

Details

message:received (dispatch-from-config.ts)

Hoisted the hook context variables (content, channelId, conversationId, timestamp, messageId) out of the plugin-only if block so both the plugin message_received hook and the new internal message:received hook share them. The internal hook fires unconditionally (fire-and-forget via void).

message:sent (dispatch.ts + reply-dispatcher.ts)

Added an onDelivered callback to ReplyDispatcherOptions that fires after each successful deliver() call. In dispatch.ts, both dispatchInboundMessageWithBufferedDispatcher and dispatchInboundMessageWithDispatcher wrap this callback to fire both the internal message:sent hook and the plugin message_sent hook. Extracted a shared createMessageSentHook() helper to avoid duplication.

Tests

Added 4 new test cases covering:

  • message:received handler triggering
  • message:sent handler triggering
  • General message handler catching both events
  • Event isolation (sent handler doesn't fire for received events)

Add message:received and message:sent events to the internal hook system,
enabling HOOK.md-based hooks to subscribe to message lifecycle events.

Changes:
- Add "message" to InternalHookEventType union
- Fire message:received internal hook in dispatch-from-config alongside
  existing plugin hook (hoisted shared variables for both hook systems)
- Add onDelivered callback to ReplyDispatcherOptions for post-delivery hooks
- Fire message:sent internal hook + plugin hook after successful delivery
- Wire the existing (but previously unused) plugin message_sent hook
- Update docs: move message events from Future to documented event types
- Add tests for message:received and message:sent event handling
@openclaw-barnacle openclaw-barnacle bot added the docs Improvements or additions to documentation label Jan 26, 2026
@sebslight
Copy link
Member

Closing due to merge conflicts. Please rebase on main and reopen if you'd like to continue with this contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants