From 4f5fb0e6cf1c69af2953c469eb583586528e123a Mon Sep 17 00:00:00 2001 From: DBT Date: Thu, 26 Feb 2026 12:55:53 +0000 Subject: [PATCH] telegram streaming: finalize placeholder when response suppressed --- pkg/agent/loop.go | 3 +++ pkg/channels/telegram.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 96ff70f..1f355b6 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -324,6 +324,9 @@ func (al *AgentLoop) processInbound(ctx context.Context, msg bus.InboundMessage) suppressed = true } } + if msg.Channel == "telegram" && suppressed { + al.bus.PublishOutbound(bus.OutboundMessage{Channel: msg.Channel, ChatID: msg.ChatID, Action: "finalize"}) + } al.audit.Record(trigger, msg.Channel, msg.SessionKey, suppressed, err) } diff --git a/pkg/channels/telegram.go b/pkg/channels/telegram.go index 4b76e1b..abb0ae9 100644 --- a/pkg/channels/telegram.go +++ b/pkg/channels/telegram.go @@ -48,7 +48,7 @@ type TelegramChannel struct { func (c *TelegramChannel) SupportsAction(action string) bool { switch strings.ToLower(strings.TrimSpace(action)) { - case "", "send", "stream", "edit", "delete", "react": + case "", "send", "stream", "finalize", "edit", "delete", "react": return true default: return false @@ -268,6 +268,17 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err safeCloseSignal(stop) } } + if action == "finalize" { + if stop, ok := c.stopThinking.LoadAndDelete(msg.ChatID); ok { + safeCloseSignal(stop) + } + if pID, ok := c.placeholders.LoadAndDelete(msg.ChatID); ok { + delCtx, cancel := withTelegramAPITimeout(ctx) + _ = c.bot.DeleteMessage(delCtx, &telego.DeleteMessageParams{ChatID: chatID, MessageID: pID.(int)}) + cancel() + } + return nil + } if action != "send" && action != "stream" { return c.handleAction(ctx, chatIDInt, action, msg) }