Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/slack-reaction-display-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@chat-adapter/slack": patch
---

fix(slack): resolve reaction user display names

Slack reaction events now resolve the reacting user's display name and real name
through the existing cached user lookup path. If lookup fails, the adapter falls
back to the Slack user ID.
68 changes: 65 additions & 3 deletions packages/adapter-slack/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,16 @@ describe("handleWebhook - event_callback", () => {
messages: [{ ts: replyTs, thread_ts: parentTs }],
})
);
mockClientMethod(
adapter,
"users.info",
vi.fn().mockResolvedValue({
ok: true,
user: { name: "user", profile: { display_name: "User" } },
})
);

const mockChat = {
processReaction: vi.fn(),
} as unknown as ChatInstance;
const mockChat = createMockChatInstance(createMockState());
(adapter as unknown as { chat: ChatInstance }).chat = mockChat;

const body = JSON.stringify({
Expand Down Expand Up @@ -683,6 +689,62 @@ describe("handleWebhook - event_callback", () => {
undefined
);
});

it("resolves reaction user display name", async () => {
mockClientMethod(
adapter,
"conversations.replies",
vi.fn().mockResolvedValue({
ok: true,
messages: [{ ts: "1234567890.123456" }],
})
);
const usersInfoMock = vi.fn().mockResolvedValue({
ok: true,
user: {
id: "U123",
name: "alice",
real_name: "Alice Example",
profile: { display_name: "Alice", real_name: "Alice Example" },
},
});
mockClientMethod(adapter, "users.info", usersInfoMock);

const mockChat = createMockChatInstance(createMockState());
(adapter as unknown as { chat: ChatInstance }).chat = mockChat;

const body = JSON.stringify({
type: "event_callback",
event: {
type: "reaction_added",
user: "U123",
reaction: "thumbsup",
item: {
type: "message",
channel: "C456",
ts: "1234567890.123456",
},
},
});
const request = createWebhookRequest(body, secret);

await adapter.handleWebhook(request);
await new Promise((r) => setTimeout(r, 50));

expect(usersInfoMock).toHaveBeenCalledWith(
expect.objectContaining({ user: "U123" })
);
expect(mockChat.processReaction).toHaveBeenCalledWith(
expect.objectContaining({
user: expect.objectContaining({
userId: "U123",
userName: "Alice",
fullName: "Alice Example",
}),
}),
undefined
);
});
});

// ============================================================================
Expand Down
10 changes: 7 additions & 3 deletions packages/adapter-slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2306,16 +2306,20 @@ export class SlackAdapter implements Adapter<SlackThreadId, unknown> {
(this._botUserId !== null && event.user === this._botUserId) ||
(this._botId !== null && event.user === this._botId);

const userInfo = await this.lookupUser(event.user);
const userName = userInfo?.displayName ?? event.user;
const fullName = userInfo?.realName ?? userName;

// Build reaction event
const reactionEvent: Omit<ReactionEvent, "adapter" | "thread"> = {
emoji: normalizedEmoji,
rawEmoji,
added: event.type === "reaction_added",
user: {
userId: event.user,
userName: event.user, // Will be resolved below if possible
fullName: event.user,
isBot: false, // Users add reactions, not bots typically
userName,
fullName,
isBot: userInfo?.isBot ?? false,
isMe,
},
messageId,
Expand Down