#10706: feat(hooks): add message:received internal hook for Telegram
channel: telegram
size: S
## Summary
Add a `message:received` internal hook that fires when a Telegram message is processed. This enables automation use cases like auto-processing files sent to the bot, logging, or triggering external workflows on incoming messages.
lobster-biscuit
## Use Cases
- Auto-process media files sent to the bot (e.g., document OCR, image analysis)
- External logging/analytics for incoming messages
- Trigger custom workflows on message receipt (e.g., forward to a queue)
## Behavior Changes
- New `InternalHookEventType`: `"message"` (extends existing `"command" | "session" | "agent" | "gateway"`)
- New `MessageReceivedContext` interface with fields: `channel`, `messageId`, `from`, `to`, `isGroup`, `chatId`, `senderId`, `hasMedia`, `mediaCount`, `timestamp`, `ctxPayload`
- New `MessageReceivedHookEvent` type and `isMessageReceivedEvent` type guard
- `createTelegramMessageProcessor` now triggers `message:received` hook after context is built, before dispatch
- No change to existing behavior when no hooks are registered
## Existing Functionality Check
- [x] Searched `src/hooks/internal-hooks.ts` — existing event types are `command`, `session`, `agent`, `gateway`. `message` is new.
- [x] Searched GitHub issues for "message hook" / "incoming hook" — no prior implementation or request found.
## Tests
2/2 tests pass in `bot-message.test.ts`:
```
✓ dispatches when context is available (verifies triggerInternalHook called)
✓ skips dispatch when no context is produced
```
## Evidence
Hook event shape:
```ts
{
type: "message",
action: "received",
sessionKey: "agent:main:telegram:group:-1001234567890",
context: {
channel: "telegram",
messageId: "456",
from: "telegram:123",
to: "telegram:123",
isGroup: false,
chatId: "123",
hasMedia: true,
mediaCount: 1,
timestamp: 1700000000000,
ctxPayload: { /* full inbound context */ }
}
}
```
**Sign-Off**
- Models used: Claude Opus 4.6
- Submitter effort: implemented and tested locally
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
- Adds a new internal hook event type `message:received` and corresponding context/type guard in `src/hooks/internal-hooks.ts`.
- Updates the Telegram message processor to trigger the new hook after message context is built and before dispatch.
- Extends Telegram message processor tests to verify the internal hook is invoked when context exists.
<h3>Confidence Score: 3/5</h3>
- This PR is close to mergeable but introduces a runtime failure mode in Telegram message processing when hook handlers error.
- Main change is straightforward, but awaiting the hook call means any failing hook handler can prevent message dispatch, which is a concrete behavior change in normal operation when hooks are enabled.
- src/telegram/bot-message.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
---
## Validation
- [x] `pnpm build` — passes
- [x] `pnpm check` — passes
- [x] `pnpm test` — 2/2 tests pass in bot-message.test.ts
## Contribution checklist
- [x] **Focused scope**: New message:received internal hook for Telegram
- [x] **What + why**: described above
- [x] **AI-assisted**: Yes, Claude Code was used for implementation. Testing level: fully tested (2 tests)
Most Similar PRs
#11597: feat(hooks): implement message:received hook
by gnufoo · 2026-02-08
86.9%
#7545: feat(hooks): add message:received hook for pre-turn automation
by wangtian24 · 2026-02-02
84.9%
#7580: feat: add message:received internal hook with prompt injection
by rodrigoschott · 2026-02-03
84.9%
#19922: feat(hooks): add message:received and message:sent hook events
by NOVA-Openclaw · 2026-02-18
82.9%
#22293: Hooks: add message-filter bundled hook with inbound message pre-filter
by MegaPhoenix92 · 2026-02-21
78.9%
#16618: feat: bridge message lifecycle hooks to workspace hook system
by DarlingtonDeveloper · 2026-02-14
77.8%
#10109: feat(plugins): invoke message_received and message_sent hooks
by nezovskii · 2026-02-06
77.2%
#19565: feat: add agent lifecycle hook events (session, message, error)
by tag-assistant · 2026-02-17
76.6%
#23240: feat(telegram): Process inbound edited_message events
by GonzFC · 2026-02-22
75.8%
#15577: feat(hooks): add message:preprocessed hook event
by heybeaux · 2026-02-13
75.6%