Skip to content

feat(telegram): streaming output support (Edit + Draft modes)#276

Open
Youhai020616 wants to merge 1 commit intoRightNow-AI:mainfrom
Youhai020616:feat/telegram-streaming
Open

feat(telegram): streaming output support (Edit + Draft modes)#276
Youhai020616 wants to merge 1 commit intoRightNow-AI:mainfrom
Youhai020616:feat/telegram-streaming

Conversation

@Youhai020616
Copy link

@Youhai020616 Youhai020616 commented Mar 3, 2026

Summary

  • Add progressive streaming output for the Telegram adapter so AI responses display incrementally ("typing effect") instead of waiting for the full response
  • Implement two streaming strategies: Edit mode (sendMessage + editMessageText, works in groups and DMs) and Draft mode (sendMessageDraft Bot API 9.5, DM only, experimental)
  • Auto mode (default) selects the best strategy; stream_mode: off preserves existing behavior with zero impact

Changes

File What
openfang-types/config.rs TelegramStreamMode enum, TelegramStreamConfig struct, new fields on TelegramConfig
openfang-channels/types.rs ChannelStreamEvent enum, StreamSink trait, supports_streaming() / begin_stream() on ChannelAdapter
openfang-channels/formatter.rs escape_html_entities(), find_split_point() helpers
openfang-channels/telegram.rs TelegramStreamSink implementing StreamSink, Edit/Draft modes, rate-limit backoff, message splitting, cursor indicator
openfang-channels/bridge.rs send_message_streaming() on ChannelBridgeHandle, dispatch_streaming(), streaming fallback in dispatch
openfang-api/channel_bridge.rs send_message_streaming() impl with StreamEvent → ChannelStreamEvent conversion

+819 lines, -19 lines across 7 files (including Cargo.lock)

Key Features

  • Dual-threshold buffering: flushes when both time (500ms) AND character count (40 chars) thresholds are met
  • Cursor indicator shown during streaming, removed on finalize
  • 429 rate-limit adaptive backoff: doubles flush interval after 3 consecutive rate limits
  • Auto message splitting at 3900 chars with smart break points (paragraph > line > sentence > word)
  • Draft → Edit fallback: if Draft mode fails, automatically degrades to Edit
  • Full backward compatibility: all trait changes use default implementations

Config Example

[channels.telegram]
stream_mode = "auto"  # off | edit | draft | auto

[channels.telegram.stream_config]
flush_interval_ms = 500
min_chars_per_flush = 40
max_message_chars = 3900
cursor_indicator = ""

🤖 Generated with Claude Code

Add progressive message display for Telegram so AI responses appear
like typing instead of waiting for the full response. Implements two
strategies: Edit mode (sendMessage + editMessageText, works everywhere)
and Draft mode (sendMessageDraft, DM only, experimental). Auto mode
selects the best strategy. Includes rate-limit adaptive backoff,
cursor indicator, message splitting for long responses, and full
backward compatibility via default trait implementations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
egargale pushed a commit to egargale/openfang that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant