Skip to content

[Feature Request] Telegram Bot Streaming / Pseudo-Streaming Support for TrustClawΒ #2812

@d-dev0101

Description

@d-dev0101

🎯 Feature Request

Problem

Currently, when using TrustClaw via Telegram bot interface, responses appear all at once after processing completes. This creates a poor user experience for longer responses, as users have no feedback that their message is being processed.

Solution

Implement pseudo-streaming for Telegram bot interface. Since Telegram API doesn't support true streaming, we can achieve a streaming effect by:

  1. Send initial "πŸ’­ thinking..." placeholder message
  2. Generate full response from AI
  3. Split response into sentences
  4. Progressively edit the message using editMessageText API
  5. Add small delays (0.2s) between updates to create typing effect

Implementation

I've already created a production-ready implementation with the following features:

βœ… Sentence-based splitting (respects punctuation)
βœ… Rate limiting protection (automatic retry with backoff on 429 errors)
βœ… Graceful degradation (falls back to full message on failures)
βœ… Configurable delay and chunk size
βœ… Minimal integration required (3 lines of code change)

Code Package

Download Link: https://backend.composio.dev/api/v3/sl/3719VB69l8

Files included:

  • telegram_streaming_complete.py - Complete streaming helper class
  • INTEGRATION_GUIDE.md - Step-by-step integration instructions

Integration Example

# Before (current)
bot.send_message(chat_id, response_text)

# After (with streaming)
from telegram_streaming_complete import TelegramStreamingHelper

streamer = TelegramStreamingHelper(bot_token)
streamer.send_streaming_response(
    chat_id=chat_id,
    full_text=response_text,
    method="sentence",
    delay=0.2
)

Technical Details

Architecture:

  • Uses TELEGRAM_SEND_MESSAGE + TELEGRAM_EDIT_MESSAGE APIs
  • Sentence regex: r'([^γ€‚οΌοΌŸ\n]+[γ€‚οΌοΌŸ\n]+)'
  • Rate limit: ~3 edits/second (Telegram API limit)
  • Automatic retry with increased delay on 429 errors

Integration points:

  1. Locate TrustClaw's Telegram adapter (e.g., adapters/telegram.py)
  2. Import TelegramStreamingHelper
  3. Replace bot.send_message() calls with streamer.send_streaming_response()

Benefits

  • ✨ Better UX: Users see progressive response instead of waiting
  • 🎯 Visual feedback: "Typing" effect shows AI is working
  • πŸš€ No backend changes: Works with existing TrustClaw infrastructure
  • πŸ›‘οΈ Production ready: Includes error handling and rate limit protection

Request

Could the TrustClaw team:

  1. Review the provided implementation
  2. Integrate it into the official Telegram adapter
  3. Make it available for all TrustClaw users

Related Context

  • Similar features exist in CountBot and LangBot (Chinese AI bot platforms)
  • Telegram's editMessageText API fully supports this approach
  • This is a client-side presentation enhancement, no LLM changes needed

Created by: TrustClaw user requesting streaming functionality
Code ready: Yes, production-ready implementation attached
Integration effort: Low (3-5 lines of code change)

@ComposioHQ Would you consider adding this feature? Happy to provide any additional details or help with integration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions