From 53932cf532b31cc43b20a5a0029e480ab070fd9a Mon Sep 17 00:00:00 2001 From: viettranx Date: Mon, 30 Mar 2026 21:24:39 +0700 Subject: [PATCH] fix(channels): include display name in [From:] annotation for Telegram and WhatsApp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Telegram: senderLabel now includes full name alongside username, e.g. [From: @nguyennlt (Nguyễn Trần)] instead of just [From: @nguyennlt]. Also uses FirstName + LastName when no username is set. WhatsApp: add missing [From:] annotation — was the only channel not annotating sender identity for the LLM. --- internal/channels/telegram/handlers.go | 9 +++++++-- internal/channels/whatsapp/whatsapp.go | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/channels/telegram/handlers.go b/internal/channels/telegram/handlers.go index 6dca1d90..62373b69 100644 --- a/internal/channels/telegram/handlers.go +++ b/internal/channels/telegram/handlers.go @@ -226,9 +226,14 @@ func (c *Channel) handleMessage(ctx context.Context, update telego.Update) { } // Compute sender label for group context (used in history + current message annotation) - senderLabel := user.FirstName + displayName := strings.TrimSpace(user.FirstName + " " + user.LastName) + senderLabel := displayName if user.Username != "" { - senderLabel = "@" + user.Username + if displayName != "" { + senderLabel = "@" + user.Username + " (" + displayName + ")" + } else { + senderLabel = "@" + user.Username + } } // --- Group mention gating (matching TS mentionGate logic) --- diff --git a/internal/channels/whatsapp/whatsapp.go b/internal/channels/whatsapp/whatsapp.go index 7429c8b8..8ead7afe 100644 --- a/internal/channels/whatsapp/whatsapp.go +++ b/internal/channels/whatsapp/whatsapp.go @@ -274,6 +274,11 @@ func (c *Channel) handleIncomingMessage(msg map[string]any) { cc.EnsureContact(ctx, c.Type(), c.Name(), senderID, senderID, metadata["user_name"], "", peerKind, "user") } + // Annotate with sender identity so the agent knows who is messaging. + if senderName := metadata["user_name"]; senderName != "" { + content = fmt.Sprintf("[From: %s]\n%s", senderName, content) + } + c.HandleMessage(senderID, chatID, content, media, metadata, peerKind) }