← Back to PRs

#10706: feat(hooks): add message:received internal hook for Telegram

by thebtf open 2026-02-06 21:37 View on GitHub →
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