-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
π― 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:
- Send initial "π thinking..." placeholder message
- Generate full response from AI
- Split response into sentences
- Progressively edit the message using
editMessageTextAPI - 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 classINTEGRATION_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_MESSAGEAPIs - Sentence regex:
r'([^γοΌοΌ\n]+[γοΌοΌ\n]+)' - Rate limit: ~3 edits/second (Telegram API limit)
- Automatic retry with increased delay on 429 errors
Integration points:
- Locate TrustClaw's Telegram adapter (e.g.,
adapters/telegram.py) - Import
TelegramStreamingHelper - Replace
bot.send_message()calls withstreamer.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:
- Review the provided implementation
- Integrate it into the official Telegram adapter
- Make it available for all TrustClaw users
Related Context
- Similar features exist in CountBot and LangBot (Chinese AI bot platforms)
- Telegram's
editMessageTextAPI 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!