Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .changeset/pink-places-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@chat-adapter/slack": patch
"chat": patch
---

Added response_action "clear"
33 changes: 33 additions & 0 deletions packages/adapter-slack/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,39 @@ describe("handleWebhook - interactive payloads", () => {
expect(response.status).toBe(200);
});

it("returns response_action: clear when handler returns action: clear", async () => {
const clearAdapter = createSlackAdapter({
botToken: "xoxb-test-token",
signingSecret: secret,
logger: mockLogger,
});
const mockChat = {
processModalSubmit: vi.fn().mockResolvedValue({ action: "clear" }),
} as unknown as ChatInstance;
(clearAdapter as unknown as { chat: ChatInstance }).chat = mockChat;

const payload = JSON.stringify({
type: "view_submission",
trigger_id: "trigger123",
user: { id: "U123", username: "testuser", name: "Test User" },
view: {
id: "V123",
callback_id: "feedback_form",
private_metadata: "",
state: { values: {} },
},
});
const body = `payload=${encodeURIComponent(payload)}`;
const request = createWebhookRequest(body, secret, {
contentType: "application/x-www-form-urlencoded",
});

const response = await clearAdapter.handleWebhook(request);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe("application/json");
expect(await response.json()).toEqual({ response_action: "clear" });
});

it("handles view_closed payload", async () => {
const payload = JSON.stringify({
type: "view_closed",
Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,8 @@ export class SlackAdapter implements Adapter<SlackThreadId, unknown> {
switch (response.action) {
case "close":
return {};
case "clear":
return { response_action: "clear" };
case "errors":
return { response_action: "errors", errors: response.errors };
case "update": {
Expand Down
5 changes: 5 additions & 0 deletions packages/chat/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2076,8 +2076,13 @@ export interface ModalCloseResponse {
action: "close";
}

export interface ModalClearResponse {
action: "clear";
}

export type ModalResponse =
| ModalCloseResponse
| ModalClearResponse
| ModalErrorsResponse
| ModalUpdateResponse
| ModalPushResponse;
Expand Down