From a4f2d02a807cc7c60aeabc1ed1333cda03ed42da Mon Sep 17 00:00:00 2001 From: Luan Vu Date: Tue, 10 Mar 2026 19:25:55 +0700 Subject: [PATCH] fix(channels): annotate DM messages with sender identity (#120) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(channels): annotate DM messages with sender identity Telegram and Zalo group messages already include [From: sender] prefix so the agent knows who is talking, but DM messages were sent without any sender context — the agent had no way to address the user by name. - Telegram DM: add [From: @username] (or FirstName if no username) - Zalo DM: add [From: displayName] when dName is present in payload * fix(tests): add missing EnsureUserProfile to test stubs AgentStore interface gained EnsureUserProfile in 4fce731 but the test stub implementations were not updated, breaking CI on main. --------- Co-authored-by: Luvu182 <208665161+Luvu182@users.noreply.github.com> --- internal/bootstrap/seed_store_test.go | 3 +++ internal/channels/telegram/handlers.go | 3 +++ internal/channels/zalo/personal/handlers.go | 7 +++++++ internal/gateway/methods/agents_create_owner_test.go | 3 +++ internal/tools/context_file_interceptor_test.go | 3 +++ 5 files changed, 19 insertions(+) diff --git a/internal/bootstrap/seed_store_test.go b/internal/bootstrap/seed_store_test.go index 0bb2af5c..9ba4a9f5 100644 --- a/internal/bootstrap/seed_store_test.go +++ b/internal/bootstrap/seed_store_test.go @@ -108,6 +108,9 @@ func (s *seedStubStore) ListUserInstances(_ context.Context, _ uuid.UUID) ([]sto func (s *seedStubStore) UpdateUserProfileMetadata(_ context.Context, _ uuid.UUID, _ string, _ map[string]string) error { return nil } +func (s *seedStubStore) EnsureUserProfile(_ context.Context, _ uuid.UUID, _ string) error { + return nil +} // ---- Tests ---- diff --git a/internal/channels/telegram/handlers.go b/internal/channels/telegram/handlers.go index 8bd512f8..28c15a65 100644 --- a/internal/channels/telegram/handlers.go +++ b/internal/channels/telegram/handlers.go @@ -358,6 +358,9 @@ func (c *Channel) handleMessage(ctx context.Context, update telego.Update) { } else { finalContent = annotated } + } else { + // DM: annotate with sender identity so the agent knows who is messaging. + finalContent = fmt.Sprintf("[From: %s]\n%s", senderLabel, content) } // Send typing indicator with keepalive + TTL safety net. diff --git a/internal/channels/zalo/personal/handlers.go b/internal/channels/zalo/personal/handlers.go index e9425626..c40f768d 100644 --- a/internal/channels/zalo/personal/handlers.go +++ b/internal/channels/zalo/personal/handlers.go @@ -43,8 +43,15 @@ func (c *Channel) handleDM(msg protocol.UserMessage) { return } + // Annotate with sender display name so the agent knows who is messaging. + senderName := msg.Data.DName + if senderName != "" { + content = fmt.Sprintf("[From: %s]\n%s", senderName, content) + } + slog.Debug("zalo_personal DM received", "sender", senderID, + "dname", senderName, "thread", threadID, "preview", channels.Truncate(content, 50), ) diff --git a/internal/gateway/methods/agents_create_owner_test.go b/internal/gateway/methods/agents_create_owner_test.go index 5cbefc60..78f0c87b 100644 --- a/internal/gateway/methods/agents_create_owner_test.go +++ b/internal/gateway/methods/agents_create_owner_test.go @@ -101,6 +101,9 @@ func (s *createCaptureStore) ListUserInstances(_ context.Context, _ uuid.UUID) ( func (s *createCaptureStore) UpdateUserProfileMetadata(_ context.Context, _ uuid.UUID, _ string, _ map[string]string) error { return nil } +func (s *createCaptureStore) EnsureUserProfile(_ context.Context, _ uuid.UUID, _ string) error { + return nil +} // ---- helpers ---- diff --git a/internal/tools/context_file_interceptor_test.go b/internal/tools/context_file_interceptor_test.go index f2ea9171..8af0fa74 100644 --- a/internal/tools/context_file_interceptor_test.go +++ b/internal/tools/context_file_interceptor_test.go @@ -90,6 +90,9 @@ func (s *stubAgentStore) ListUserInstances(_ context.Context, _ uuid.UUID) ([]st func (s *stubAgentStore) UpdateUserProfileMetadata(_ context.Context, _ uuid.UUID, _ string, _ map[string]string) error { return nil } +func (s *stubAgentStore) EnsureUserProfile(_ context.Context, _ uuid.UUID, _ string) error { + return nil +} // ---- Tests ----