Skip to content

Resolve DMs with external users by username; prefer 1:1 DM over group DM - #5

Merged
odfalik merged 1 commit into
mainfrom
oded/dm-resolve-external-users
Jul 30, 2026
Merged

odfalik merged 1 commit into
mainfrom
oded/dm-resolve-external-users

Conversation

@odfalik

@odfalik odfalik commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Problem

read_history(channel: "yufan") resolved to the group DM #mpdm-oded--peter--yufan.liu-1 instead of the 1:1 DM with Yufan.

Root cause

Yufan is an external / Slack Connect user (different team id). For such users Slack returns an empty display_name and empty real_name. _resolve_user only tried display_name -> real_name -> raw ID, so his DM rendered as a bare @U0A8QJCNUNM and carried no "yufan" text to match on. The only conversation whose terms contained "yufan" was the group DM's Slack name mpdm-oded--peter--yufan.liu-1, so the resolver landed there.

Fix

  • _resolve_user: fall back to the username (name, e.g. yufan.liu) before the raw ID, so external-user DMs resolve to @yufan.liu. Also un-breaks other bare-ID DMs in the list.
  • _resolve_channel_ref: when a query matches several conversations but exactly one is a 1:1 DM, prefer it — typing a person's name means their DM, not a group that happens to include them.

Test

Adds test_prefers_direct_dm_over_group_dm_for_external_user and updates the fake client to model empty display/real names. All 6 tests pass.

_resolve_user only tried display_name -> real_name -> raw ID. External /
Slack Connect users (e.g. HKU collaborators) often have both names empty, so
their DM rendered as a bare @U... ID and carried no name to match on. A query
like "yufan" then fell through to the only conversation containing the
substring -- the group DM whose Slack name is mpdm-oded--peter--yufan.liu-1.

- _resolve_user: fall back to the username ("name") before the raw ID.
- _resolve_channel_ref: when a query matches several conversations but exactly
  one is a 1:1 DM, prefer it -- a person's name means their DM, not a group
  that happens to include them.

Add a regression test covering an external-user DM alongside a same-named
group DM.
@odfalik
odfalik merged commit f921fa3 into main Jul 30, 2026
1 of 4 checks passed
@odfalik
odfalik deleted the oded/dm-resolve-external-users branch July 30, 2026 19:57
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.

1 participant