diff --git a/pkg/channels/telegram.go b/pkg/channels/telegram.go index 8e4afc64a..780c94b98 100644 --- a/pkg/channels/telegram.go +++ b/pkg/channels/telegram.go @@ -475,8 +475,10 @@ func (c *TelegramChannel) handleQuickCommand(ctx context.Context, message telego "peer_id": peerID, } - // No "Thinking..." placeholder — send directly via message bus - c.HandleMessage(fmt.Sprintf("%d", user.ID), fmt.Sprintf("%d", chatID), content, nil, metadata) + // Use a message-scoped chatID so this response never matches the ongoing + // LLM task's placeholder or stopThinking entry for this chat. + chatIDStr := fmt.Sprintf("%d#%d", chatID, message.MessageID) + c.HandleMessage(fmt.Sprintf("%d", user.ID), chatIDStr, content, nil, metadata) return nil } @@ -520,6 +522,11 @@ func (c *TelegramChannel) downloadFile(ctx context.Context, fileID, ext string) } func parseChatID(chatIDStr string) (int64, error) { + // Strip message-scoped suffix used by quick-command responses. + // e.g. "123456789#42" → parse as "123456789" + if idx := strings.IndexByte(chatIDStr, '#'); idx >= 0 { + chatIDStr = chatIDStr[:idx] + } var id int64 _, err := fmt.Sscanf(chatIDStr, "%d", &id) return id, err diff --git a/pkg/channels/telegram_test.go b/pkg/channels/telegram_test.go index 6afcc1ff9..34cf84650 100644 --- a/pkg/channels/telegram_test.go +++ b/pkg/channels/telegram_test.go @@ -86,3 +86,25 @@ func TestDisplayWidth_EmojiIsThree(t *testing.T) { t.Fatalf("displayWidth(stars) = %d, want 15", got) } } + +func TestParseChatID_Plain(t *testing.T) { + id, err := parseChatID("123456789") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if id != 123456789 { + t.Errorf("expected 123456789, got %d", id) + } +} + +func TestParseChatID_MessageScopedSuffix(t *testing.T) { + // Quick-command responses use "chatID#messageID" to ensure uniqueness. + // parseChatID must strip the suffix so delivery still works. + id, err := parseChatID("123456789#42") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if id != 123456789 { + t.Errorf("expected 123456789, got %d", id) + } +}