openclaw/src/slack/monitor/context.test.ts
Dale Yarborough a95a0be133
feat(slack): add typingReaction config for DM typing indicator fallback (#19816)
* feat(slack): add typingReaction config for DM typing indicator fallback

Adds a reaction-based typing indicator for Slack DMs that works without
assistant mode. When `channels.slack.typingReaction` is set (e.g.
"hourglass_flowing_sand"), the emoji is added to the user's message when
processing starts and removed when the reply is sent.

Addresses #19809

* test(slack): add typingReaction to createSlackMonitorContext test callers

* test(slack): add typingReaction to test context callers

* test(slack): add typingReaction to context fixture

* docs(changelog): credit Slack typingReaction feature

* test(slack): align existing-thread history expectation

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
2026-03-03 21:07:17 -08:00

84 lines
2.2 KiB
TypeScript

import type { App } from "@slack/bolt";
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import type { RuntimeEnv } from "../../runtime.js";
import { createSlackMonitorContext } from "./context.js";
function createTestContext() {
return createSlackMonitorContext({
cfg: {
channels: { slack: { enabled: true } },
session: { dmScope: "main" },
} as OpenClawConfig,
accountId: "default",
botToken: "xoxb-test",
app: { client: {} } as App,
runtime: {} as RuntimeEnv,
botUserId: "U_BOT",
teamId: "T_EXPECTED",
apiAppId: "A_EXPECTED",
historyLimit: 0,
sessionScope: "per-sender",
mainKey: "main",
dmEnabled: true,
dmPolicy: "open",
allowFrom: [],
allowNameMatching: false,
groupDmEnabled: false,
groupDmChannels: [],
defaultRequireMention: true,
groupPolicy: "allowlist",
useAccessGroups: true,
reactionMode: "off",
reactionAllowlist: [],
replyToMode: "off",
threadHistoryScope: "thread",
threadInheritParent: false,
slashCommand: {
enabled: true,
name: "openclaw",
ephemeral: true,
sessionPrefix: "slack:slash",
},
textLimit: 4000,
typingReaction: "",
ackReactionScope: "group-mentions",
mediaMaxBytes: 20 * 1024 * 1024,
removeAckAfterReply: false,
});
}
describe("createSlackMonitorContext shouldDropMismatchedSlackEvent", () => {
it("drops mismatched top-level app/team identifiers", () => {
const ctx = createTestContext();
expect(
ctx.shouldDropMismatchedSlackEvent({
api_app_id: "A_WRONG",
team_id: "T_EXPECTED",
}),
).toBe(true);
expect(
ctx.shouldDropMismatchedSlackEvent({
api_app_id: "A_EXPECTED",
team_id: "T_WRONG",
}),
).toBe(true);
});
it("drops mismatched nested team.id payloads used by interaction bodies", () => {
const ctx = createTestContext();
expect(
ctx.shouldDropMismatchedSlackEvent({
api_app_id: "A_EXPECTED",
team: { id: "T_WRONG" },
}),
).toBe(true);
expect(
ctx.shouldDropMismatchedSlackEvent({
api_app_id: "A_EXPECTED",
team: { id: "T_EXPECTED" },
}),
).toBe(false);
});
});