refactor(slack): reuse shared action adapter
This commit is contained in:
parent
45510084cd
commit
54419a826b
@ -28,6 +28,7 @@ import {
|
||||
type ChannelPlugin,
|
||||
type OpenClawConfig,
|
||||
} from "openclaw/plugin-sdk/slack";
|
||||
import { createSlackActions } from "../../../src/channels/plugins/slack.actions.js";
|
||||
import { buildPassiveProbedChannelStatusSummary } from "../../shared/channel-status-summary.js";
|
||||
import {
|
||||
listEnabledSlackAccounts,
|
||||
@ -38,8 +39,6 @@ import {
|
||||
import { parseSlackBlocksInput } from "./blocks-input.js";
|
||||
import { createSlackWebClient } from "./client.js";
|
||||
import { isSlackInteractiveRepliesEnabled } from "./interactive-replies.js";
|
||||
import { handleSlackMessageAction } from "./message-action-dispatch.js";
|
||||
import { extractSlackToolSend, listSlackMessageActions } from "./message-actions.js";
|
||||
import { normalizeAllowListLower } from "./monitor/allow-list.js";
|
||||
import type { SlackProbe } from "./probe.js";
|
||||
import { resolveSlackUserAllowlist } from "./resolve-users.js";
|
||||
@ -488,28 +487,10 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount> = {
|
||||
return resolved.map((entry) => toResolvedTarget(entry, entry.note));
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
listActions: ({ cfg }) => listSlackMessageActions(cfg),
|
||||
getCapabilities: ({ cfg }) => {
|
||||
const capabilities = new Set<"interactive" | "blocks">();
|
||||
if (listSlackMessageActions(cfg).includes("send")) {
|
||||
capabilities.add("blocks");
|
||||
}
|
||||
if (isSlackInteractiveRepliesEnabled({ cfg })) {
|
||||
capabilities.add("interactive");
|
||||
}
|
||||
return Array.from(capabilities);
|
||||
},
|
||||
extractToolSend: ({ args }) => extractSlackToolSend(args),
|
||||
handleAction: async (ctx) =>
|
||||
await handleSlackMessageAction({
|
||||
providerId: SLACK_CHANNEL,
|
||||
ctx,
|
||||
includeReadThreadId: true,
|
||||
invoke: async (action, cfg, toolContext) =>
|
||||
await getSlackRuntime().channel.slack.handleSlackAction(action, cfg, toolContext),
|
||||
}),
|
||||
},
|
||||
actions: createSlackActions(SLACK_CHANNEL, {
|
||||
invoke: async (action, cfg, toolContext) =>
|
||||
await getSlackRuntime().channel.slack.handleSlackAction(action, cfg, toolContext),
|
||||
}),
|
||||
setup: slackSetupAdapter,
|
||||
outbound: {
|
||||
deliveryMode: "direct",
|
||||
|
||||
@ -8,7 +8,16 @@ import {
|
||||
} from "../../plugin-sdk/slack.js";
|
||||
import type { ChannelMessageActionAdapter } from "./types.js";
|
||||
|
||||
export function createSlackActions(providerId: string): ChannelMessageActionAdapter {
|
||||
type SlackActionInvoke = (
|
||||
action: Record<string, unknown>,
|
||||
cfg: unknown,
|
||||
toolContext: unknown,
|
||||
) => Promise<unknown>;
|
||||
|
||||
export function createSlackActions(
|
||||
providerId: string,
|
||||
options?: { invoke?: SlackActionInvoke },
|
||||
): ChannelMessageActionAdapter {
|
||||
return {
|
||||
listActions: ({ cfg }) => listSlackMessageActions(cfg),
|
||||
getCapabilities: ({ cfg }) => {
|
||||
@ -29,10 +38,12 @@ export function createSlackActions(providerId: string): ChannelMessageActionAdap
|
||||
normalizeChannelId: resolveSlackChannelId,
|
||||
includeReadThreadId: true,
|
||||
invoke: async (action, cfg, toolContext) =>
|
||||
await handleSlackAction(action, cfg, {
|
||||
...(toolContext as SlackActionContext | undefined),
|
||||
mediaLocalRoots: ctx.mediaLocalRoots,
|
||||
}),
|
||||
await (options?.invoke
|
||||
? options.invoke(action, cfg, toolContext)
|
||||
: handleSlackAction(action, cfg, {
|
||||
...(toolContext as SlackActionContext | undefined),
|
||||
mediaLocalRoots: ctx.mediaLocalRoots,
|
||||
})),
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user