Skip to content

feat: add conversation history for Telegram chat sessions#536

Open
buger wants to merge 1 commit intoprobelabs:mainfrom
buger:fix/telegram-conversation-history
Open

feat: add conversation history for Telegram chat sessions#536
buger wants to merge 1 commit intoprobelabs:mainfrom
buger:fix/telegram-conversation-history

Conversation

@buger
Copy link
Copy Markdown
Contributor

@buger buger commented Mar 15, 2026

Problem

The Telegram adapter's buildConversationContext() only includes the current message:

messages: [current],  // Only the current message, no history

This means every Telegram message is processed in isolation — the LLM has no context from previous messages in the conversation. The bot can't follow multi-turn conversations, reference earlier questions, or maintain context.

Compare with the Slack adapter, which maintains a ThreadCache and passes full thread history:

messages: cached.messages,  // Full thread history

Fix

1. TelegramAdapter — in-memory chat history cache

  • Maintains conversation history per chat thread ID (Map-based)
  • LRU eviction when at capacity (max 500 chats)
  • TTL expiry (2 hours of inactivity)
  • Per-chat message limit (50 messages, keeps most recent)
  • addToHistory(threadId, message) — public method for the runner to add bot responses
  • buildConversationContext() now returns full history in messages array

2. TelegramPollingRunner — captures bot responses

  • After engine execution, extracts the bot's response text from the result
  • Adds bot response to the adapter's chat history
  • Both user and bot messages are now tracked
  • Injects conversation into execution context (works with the git-check bypass from PR fix: skip git requirement for conversation/chat workflows #535)
  • Logs conversation history size for debugging

Test plan

  • Send multiple messages to the Telegram bot — verify it references previous messages
  • Start a new conversation after 2+ hours — verify fresh context (TTL expiry)
  • Verify group chat conversations maintain separate histories per thread
  • Existing Slack/email/Teams adapters unaffected

🤖 Generated with Claude Code

The Telegram adapter's buildConversationContext() only included the
current message in the messages array, causing every message to be
processed in isolation without any conversation context. This meant
the LLM couldn't reference previous messages in the chat.

Changes:
- Add in-memory chat history cache to TelegramAdapter (per thread ID)
  with LRU eviction (max 500 chats), TTL (2 hours), and per-chat
  message limit (50 messages)
- buildConversationContext() now returns the full conversation history
  in the messages array, matching the Slack adapter pattern
- Polling runner captures bot responses from engine results and adds
  them to the history, so the LLM sees both user and bot messages
- Inject conversation context into execution context so the engine
  can use it for the git-check bypass (PR probelabs#535)

This brings Telegram conversation handling in line with the Slack
adapter, which already maintains thread history via ThreadCache.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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