Slack: send assistant thread status while typing

This commit is contained in:
Shadow
2026-01-06 11:58:28 -06:00
committed by Peter Steinberger
parent 792ae99ffc
commit 8ebc789d25
3 changed files with 117 additions and 1 deletions

View File

@@ -63,6 +63,11 @@ vi.mock("@slack/bolt", () => {
user: { profile: { display_name: "Ada" } },
}),
},
assistant: {
threads: {
setStatus: vi.fn().mockResolvedValue({ ok: true }),
},
},
reactions: {
add: (...args: unknown[]) => reactMock(...args),
},
@@ -149,6 +154,49 @@ describe("monitorSlackProvider tool results", () => {
expect(sendMock.mock.calls[1][1]).toBe("PFX final reply");
});
it("updates assistant thread status when replies start", async () => {
replyMock.mockImplementation(async (_ctx, opts) => {
await opts?.onReplyStart?.();
return { text: "final reply" };
});
const controller = new AbortController();
const run = monitorSlackProvider({
botToken: "bot-token",
appToken: "app-token",
abortSignal: controller.signal,
});
await waitForEvent("message");
const handler = getSlackHandlers()?.get("message");
if (!handler) throw new Error("Slack message handler not registered");
await handler({
event: {
type: "message",
user: "U1",
text: "hello",
ts: "123",
channel: "C1",
channel_type: "im",
},
});
await flush();
controller.abort();
await run;
const client = getSlackClient() as {
assistant?: { threads?: { setStatus?: ReturnType<typeof vi.fn> } };
};
expect(client.assistant?.threads?.setStatus).toHaveBeenCalledWith({
token: "bot-token",
channel_id: "C1",
thread_ts: "123",
status: "is typing...",
});
});
it("accepts channel messages when mentionPatterns match", async () => {
config = {
messages: { responsePrefix: "PFX" },