Skip to content

message:sent hook not emitted when Telegram streaming preview finalizes #50878

@HuskyDanny

Description

@HuskyDanny

Summary

message:sent internal hook events are never fired for Telegram DM replies when streaming preview mode is active (default). This means hooks registered for message:sent (like custom loggers) never trigger on normal DM conversations.

Root Cause

In extensions/telegram/src/lane-delivery-text-deliverer.ts, when the final answer fits within 4096 chars and streaming is active, the code takes the preview-finalize path:

  • tryMaterializeDraftPreviewForFinal (line ~500) or tryUpdatePreviewForLane (line ~510) edits the existing preview message in-place
  • Returns "preview-finalized" or "preview-retained"
  • Neither path calls sendPayloaddeliverReplies is never invoked → emitMessageSentHooks is never called → message:sent never fires

Expected Behavior

message:sent should fire whenever a message is delivered to a channel, regardless of whether delivery happened via sendPayload or preview finalization.

Affected Paths

  • DM replies with streaming enabled (default) — broken
  • Cron deliveries via deliverOutboundPayloads — works
  • Webhook deliveries via route-reply.tsdeliverOutboundPayloads — works
  • Replies where preview fails and falls through to sendPayload — works

Suggested Fix

Call emitMessageSentHooks (or equivalent callback) when returning "preview-finalized" or "preview-retained" in lane-delivery-text-deliverer.ts.

Workaround

Set blockStreaming: true in the Telegram channel config to force all replies through the normal sendPayloaddeliverReplies path.

Reproduction

  1. Register an internal hook for message:sent with a console.error at the top of the handler
  2. Send a DM to the bot via Telegram
  3. Observe that the hook handler is never called
  4. Set blockStreaming: true → hook fires correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions