Skip to content

Show name and avatar for bot messages#77

Merged
gammons merged 2 commits into
gammons:mainfrom
Frodotus:fix/bot-avatars
Jun 11, 2026
Merged

Show name and avatar for bot messages#77
gammons merged 2 commits into
gammons:mainfrom
Frodotus:fix/bot-avatars

Conversation

@Frodotus

@Frodotus Frodotus commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Closes #76.

Problem

Bot/app messages (bot_message) carry no user — only bot_id, username, and sometimes icons. The conversion read only m.User, so bot messages got UserID == "": the avatar lookup missed and the author name was dropped. This hit every bot, since even apps with a bot user post as bot_message with an empty user.

Fix

  • Identity: key bot messages on bot_id and use the message's username, in all three fetch paths (new messageAuthor helper) and the live WebSocket path (OnMessage now receives bot_id/username, threaded through the event struct + dispatch).
  • Avatar: a new userResolver.RequestBot resolves the icon via bots.info once per bot (deduped, persisted) and preloads it via avatars.Preload(bot_id, …); AvatarURLs[bot_id] is then populated on the resolve/connect path — mirroring the users.info path for humans. Added GetBotInfo to the client.
  • Cached rows: messages cached with UserID == "" before this change are re-keyed by parsing bot_id/username out of raw_json in enrichCachedRow, so existing cached bot messages render without a cache wipe.

Testing

go test ./... passes. Added TestMessageAuthorBotIdentity (fetch-path identity) and extended TestDispatchWebSocketBotMessageEvent to assert bot_id/username flow through the WS dispatch.

@gammons

gammons commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Reviewed in a worktree — build passes, go vet clean, all tests green (including the two new bot-identity tests). Approve with minor nits.

Well-targeted fix: correct root cause (bot_message has empty user, only bot_id/username), consistently applied across all three fetch paths, the live WS path, and the cached-row backfill. RequestBot faithfully mirrors Request and the avatar pipeline wires through unchanged since cache + MessageItem are keyed on the same bot_id. The enrichCachedRow re-keying for pre-fix rows (avoiding a cache wipe) is a nice touch. Tests are meaningful, not signature-padding.

Nits (non-blocking):

  • bestBotIcon comment says "largest reasonable icon," but the fallback order (72, 48, 132, 36, 230) deliberately prefers 72 over the larger sizes. The ordering is fine; the comment should reflect the actual intent.
  • ShouldNotify uses the original userID (empty for bots) rather than authorID — almost certainly intentional (a bot cant be you), but worth a one-line comment so it is not "fixed" later.
  • PR description says the avatar is stored into AvatarURLs[bot_id]; precisely, RequestBot calls avatars.Preload(botID, ...) and AvatarURLs is populated on the UserResolvedMsg/connect path. Functionally correct, just imprecise wording.

@Frodotus

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed the nits in f387eb9 (non-functional, comments + wording only):

  • bestBotIcon comment — rewritten to match the actual intent: prefer the 72px icon (sharp enough, almost always present) and fall back through the other sizes by availability, not strictly by pixel size.
  • ShouldNotify userID — added a one-line comment at the call site noting the empty userID for bots is intentional: the self-message suppression keys on the human sender, and a bot (userID == "", authorID == botID) can never be "you".
  • PR description — corrected the avatar wording: RequestBot calls avatars.Preload(bot_id, …), and AvatarURLs[bot_id] is populated on the resolve/connect path (not stored directly by RequestBot).

@gammons gammons merged commit 34599d5 into gammons:main Jun 11, 2026
3 checks passed
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.

Bot messages show no name or avatar

2 participants