feat: unify message cli and tools
This commit is contained in:
@@ -4,7 +4,6 @@ import { createBrowserTool } from "./tools/browser-tool.js";
|
||||
import { createCanvasTool } from "./tools/canvas-tool.js";
|
||||
import type { AnyAgentTool } from "./tools/common.js";
|
||||
import { createCronTool } from "./tools/cron-tool.js";
|
||||
import { createDiscordTool } from "./tools/discord-tool.js";
|
||||
import { createGatewayTool } from "./tools/gateway-tool.js";
|
||||
import { createImageTool } from "./tools/image-tool.js";
|
||||
import { createMessageTool } from "./tools/message-tool.js";
|
||||
@@ -13,9 +12,6 @@ import { createSessionsHistoryTool } from "./tools/sessions-history-tool.js";
|
||||
import { createSessionsListTool } from "./tools/sessions-list-tool.js";
|
||||
import { createSessionsSendTool } from "./tools/sessions-send-tool.js";
|
||||
import { createSessionsSpawnTool } from "./tools/sessions-spawn-tool.js";
|
||||
import { createSlackTool } from "./tools/slack-tool.js";
|
||||
import { createTelegramTool } from "./tools/telegram-tool.js";
|
||||
import { createWhatsAppTool } from "./tools/whatsapp-tool.js";
|
||||
|
||||
export function createClawdbotTools(options?: {
|
||||
browserControlUrl?: string;
|
||||
@@ -35,14 +31,10 @@ export function createClawdbotTools(options?: {
|
||||
createCanvasTool(),
|
||||
createNodesTool(),
|
||||
createCronTool(),
|
||||
createDiscordTool(),
|
||||
createMessageTool(),
|
||||
createSlackTool({
|
||||
createMessageTool({
|
||||
agentAccountId: options?.agentAccountId,
|
||||
config: options?.config,
|
||||
}),
|
||||
createTelegramTool(),
|
||||
createWhatsAppTool(),
|
||||
createGatewayTool({
|
||||
agentSessionKey: options?.agentSessionKey,
|
||||
config: options?.config,
|
||||
|
||||
@@ -141,36 +141,13 @@ describe("createClawdbotCodingTools", () => {
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it("scopes discord tool to discord provider", () => {
|
||||
const other = createClawdbotCodingTools({ messageProvider: "whatsapp" });
|
||||
expect(other.some((tool) => tool.name === "discord")).toBe(false);
|
||||
|
||||
const discord = createClawdbotCodingTools({ messageProvider: "discord" });
|
||||
expect(discord.some((tool) => tool.name === "discord")).toBe(true);
|
||||
});
|
||||
|
||||
it("scopes slack tool to slack provider", () => {
|
||||
const other = createClawdbotCodingTools({ messageProvider: "whatsapp" });
|
||||
expect(other.some((tool) => tool.name === "slack")).toBe(false);
|
||||
|
||||
const slack = createClawdbotCodingTools({ messageProvider: "slack" });
|
||||
expect(slack.some((tool) => tool.name === "slack")).toBe(true);
|
||||
});
|
||||
|
||||
it("scopes telegram tool to telegram provider", () => {
|
||||
const other = createClawdbotCodingTools({ messageProvider: "whatsapp" });
|
||||
expect(other.some((tool) => tool.name === "telegram")).toBe(false);
|
||||
|
||||
const telegram = createClawdbotCodingTools({ messageProvider: "telegram" });
|
||||
expect(telegram.some((tool) => tool.name === "telegram")).toBe(true);
|
||||
});
|
||||
|
||||
it("scopes whatsapp tool to whatsapp provider", () => {
|
||||
const other = createClawdbotCodingTools({ messageProvider: "slack" });
|
||||
expect(other.some((tool) => tool.name === "whatsapp")).toBe(false);
|
||||
|
||||
const whatsapp = createClawdbotCodingTools({ messageProvider: "whatsapp" });
|
||||
expect(whatsapp.some((tool) => tool.name === "whatsapp")).toBe(true);
|
||||
it("does not expose provider-specific message tools", () => {
|
||||
const tools = createClawdbotCodingTools({ messageProvider: "discord" });
|
||||
const names = new Set(tools.map((tool) => tool.name));
|
||||
expect(names.has("discord")).toBe(false);
|
||||
expect(names.has("slack")).toBe(false);
|
||||
expect(names.has("telegram")).toBe(false);
|
||||
expect(names.has("whatsapp")).toBe(false);
|
||||
});
|
||||
|
||||
it("filters session tools for sub-agent sessions by default", () => {
|
||||
|
||||
@@ -613,37 +613,6 @@ function createClawdbotReadTool(base: AnyAgentTool): AnyAgentTool {
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeMessageProvider(
|
||||
messageProvider?: string,
|
||||
): string | undefined {
|
||||
const trimmed = messageProvider?.trim().toLowerCase();
|
||||
return trimmed ? trimmed : undefined;
|
||||
}
|
||||
|
||||
function shouldIncludeDiscordTool(messageProvider?: string): boolean {
|
||||
const normalized = normalizeMessageProvider(messageProvider);
|
||||
if (!normalized) return false;
|
||||
return normalized === "discord" || normalized.startsWith("discord:");
|
||||
}
|
||||
|
||||
function shouldIncludeSlackTool(messageProvider?: string): boolean {
|
||||
const normalized = normalizeMessageProvider(messageProvider);
|
||||
if (!normalized) return false;
|
||||
return normalized === "slack" || normalized.startsWith("slack:");
|
||||
}
|
||||
|
||||
function shouldIncludeTelegramTool(messageProvider?: string): boolean {
|
||||
const normalized = normalizeMessageProvider(messageProvider);
|
||||
if (!normalized) return false;
|
||||
return normalized === "telegram" || normalized.startsWith("telegram:");
|
||||
}
|
||||
|
||||
function shouldIncludeWhatsAppTool(messageProvider?: string): boolean {
|
||||
const normalized = normalizeMessageProvider(messageProvider);
|
||||
if (!normalized) return false;
|
||||
return normalized === "whatsapp" || normalized.startsWith("whatsapp:");
|
||||
}
|
||||
|
||||
export function createClawdbotCodingTools(options?: {
|
||||
bash?: BashToolDefaults & ProcessToolDefaults;
|
||||
messageProvider?: string;
|
||||
@@ -724,20 +693,9 @@ export function createClawdbotCodingTools(options?: {
|
||||
config: options?.config,
|
||||
}),
|
||||
];
|
||||
const allowDiscord = shouldIncludeDiscordTool(options?.messageProvider);
|
||||
const allowSlack = shouldIncludeSlackTool(options?.messageProvider);
|
||||
const allowTelegram = shouldIncludeTelegramTool(options?.messageProvider);
|
||||
const allowWhatsApp = shouldIncludeWhatsAppTool(options?.messageProvider);
|
||||
const filtered = tools.filter((tool) => {
|
||||
if (tool.name === "discord") return allowDiscord;
|
||||
if (tool.name === "slack") return allowSlack;
|
||||
if (tool.name === "telegram") return allowTelegram;
|
||||
if (tool.name === "whatsapp") return allowWhatsApp;
|
||||
return true;
|
||||
});
|
||||
const toolsFiltered = effectiveToolsPolicy
|
||||
? filterToolsByPolicy(filtered, effectiveToolsPolicy)
|
||||
: filtered;
|
||||
? filterToolsByPolicy(tools, effectiveToolsPolicy)
|
||||
: tools;
|
||||
const sandboxed = sandbox
|
||||
? filterToolsByPolicy(toolsFiltered, sandbox.tools)
|
||||
: toolsFiltered;
|
||||
|
||||
@@ -154,8 +154,37 @@
|
||||
"emoji": "✉️",
|
||||
"title": "Message",
|
||||
"actions": {
|
||||
"send": { "label": "send", "detailKeys": ["to", "provider", "mediaUrl"] },
|
||||
"poll": { "label": "poll", "detailKeys": ["to", "provider", "question"] }
|
||||
"send": { "label": "send", "detailKeys": ["provider", "to", "media", "replyTo", "threadId"] },
|
||||
"poll": { "label": "poll", "detailKeys": ["provider", "to", "pollQuestion"] },
|
||||
"react": { "label": "react", "detailKeys": ["provider", "to", "messageId", "emoji", "remove"] },
|
||||
"reactions": { "label": "reactions", "detailKeys": ["provider", "to", "messageId", "limit"] },
|
||||
"read": { "label": "read", "detailKeys": ["provider", "to", "limit"] },
|
||||
"edit": { "label": "edit", "detailKeys": ["provider", "to", "messageId"] },
|
||||
"delete": { "label": "delete", "detailKeys": ["provider", "to", "messageId"] },
|
||||
"pin": { "label": "pin", "detailKeys": ["provider", "to", "messageId"] },
|
||||
"unpin": { "label": "unpin", "detailKeys": ["provider", "to", "messageId"] },
|
||||
"list-pins": { "label": "list pins", "detailKeys": ["provider", "to"] },
|
||||
"permissions": { "label": "permissions", "detailKeys": ["provider", "channelId", "to"] },
|
||||
"thread-create": { "label": "thread create", "detailKeys": ["provider", "channelId", "threadName"] },
|
||||
"thread-list": { "label": "thread list", "detailKeys": ["provider", "guildId", "channelId"] },
|
||||
"thread-reply": { "label": "thread reply", "detailKeys": ["provider", "channelId", "messageId"] },
|
||||
"search": { "label": "search", "detailKeys": ["provider", "guildId", "query"] },
|
||||
"sticker": { "label": "sticker", "detailKeys": ["provider", "to", "stickerId"] },
|
||||
"member-info": { "label": "member", "detailKeys": ["provider", "guildId", "userId"] },
|
||||
"role-info": { "label": "roles", "detailKeys": ["provider", "guildId"] },
|
||||
"emoji-list": { "label": "emoji list", "detailKeys": ["provider", "guildId"] },
|
||||
"emoji-upload": { "label": "emoji upload", "detailKeys": ["provider", "guildId", "emojiName"] },
|
||||
"sticker-upload": { "label": "sticker upload", "detailKeys": ["provider", "guildId", "stickerName"] },
|
||||
"role-add": { "label": "role add", "detailKeys": ["provider", "guildId", "userId", "roleId"] },
|
||||
"role-remove": { "label": "role remove", "detailKeys": ["provider", "guildId", "userId", "roleId"] },
|
||||
"channel-info": { "label": "channel", "detailKeys": ["provider", "channelId"] },
|
||||
"channel-list": { "label": "channels", "detailKeys": ["provider", "guildId"] },
|
||||
"voice-status": { "label": "voice", "detailKeys": ["provider", "guildId", "userId"] },
|
||||
"event-list": { "label": "events", "detailKeys": ["provider", "guildId"] },
|
||||
"event-create": { "label": "event create", "detailKeys": ["provider", "guildId", "eventName"] },
|
||||
"timeout": { "label": "timeout", "detailKeys": ["provider", "guildId", "userId"] },
|
||||
"kick": { "label": "kick", "detailKeys": ["provider", "guildId", "userId"] },
|
||||
"ban": { "label": "ban", "detailKeys": ["provider", "guildId", "userId"] }
|
||||
}
|
||||
},
|
||||
"agents_list": {
|
||||
@@ -190,77 +219,6 @@
|
||||
"start": { "label": "start" },
|
||||
"wait": { "label": "wait" }
|
||||
}
|
||||
},
|
||||
"discord": {
|
||||
"emoji": "💬",
|
||||
"title": "Discord",
|
||||
"actions": {
|
||||
"react": { "label": "react", "detailKeys": ["channelId", "messageId", "emoji", "remove"] },
|
||||
"reactions": { "label": "reactions", "detailKeys": ["channelId", "messageId"] },
|
||||
"sticker": { "label": "sticker", "detailKeys": ["to", "stickerIds"] },
|
||||
"poll": { "label": "poll", "detailKeys": ["question", "to"] },
|
||||
"permissions": { "label": "permissions", "detailKeys": ["channelId"] },
|
||||
"readMessages": { "label": "read messages", "detailKeys": ["channelId", "limit"] },
|
||||
"sendMessage": { "label": "send", "detailKeys": ["to", "content"] },
|
||||
"editMessage": { "label": "edit", "detailKeys": ["channelId", "messageId"] },
|
||||
"deleteMessage": { "label": "delete", "detailKeys": ["channelId", "messageId"] },
|
||||
"threadCreate": { "label": "thread create", "detailKeys": ["channelId", "name"] },
|
||||
"threadList": { "label": "thread list", "detailKeys": ["guildId", "channelId"] },
|
||||
"threadReply": { "label": "thread reply", "detailKeys": ["channelId", "content"] },
|
||||
"pinMessage": { "label": "pin", "detailKeys": ["channelId", "messageId"] },
|
||||
"unpinMessage": { "label": "unpin", "detailKeys": ["channelId", "messageId"] },
|
||||
"listPins": { "label": "list pins", "detailKeys": ["channelId"] },
|
||||
"searchMessages": { "label": "search", "detailKeys": ["guildId", "content"] },
|
||||
"memberInfo": { "label": "member", "detailKeys": ["guildId", "userId"] },
|
||||
"roleInfo": { "label": "roles", "detailKeys": ["guildId"] },
|
||||
"emojiList": { "label": "emoji list", "detailKeys": ["guildId"] },
|
||||
"emojiUpload": { "label": "emoji upload", "detailKeys": ["guildId", "name"] },
|
||||
"stickerUpload": { "label": "sticker upload", "detailKeys": ["guildId", "name"] },
|
||||
"roleAdd": { "label": "role add", "detailKeys": ["guildId", "userId", "roleId"] },
|
||||
"roleRemove": { "label": "role remove", "detailKeys": ["guildId", "userId", "roleId"] },
|
||||
"channelInfo": { "label": "channel", "detailKeys": ["channelId"] },
|
||||
"channelList": { "label": "channels", "detailKeys": ["guildId"] },
|
||||
"voiceStatus": { "label": "voice", "detailKeys": ["guildId", "userId"] },
|
||||
"eventList": { "label": "events", "detailKeys": ["guildId"] },
|
||||
"eventCreate": { "label": "event create", "detailKeys": ["guildId", "name"] },
|
||||
"timeout": { "label": "timeout", "detailKeys": ["guildId", "userId"] },
|
||||
"kick": { "label": "kick", "detailKeys": ["guildId", "userId"] },
|
||||
"ban": { "label": "ban", "detailKeys": ["guildId", "userId"] }
|
||||
}
|
||||
},
|
||||
"slack": {
|
||||
"emoji": "💬",
|
||||
"title": "Slack",
|
||||
"actions": {
|
||||
"react": { "label": "react", "detailKeys": ["channelId", "messageId", "emoji", "remove"] },
|
||||
"reactions": { "label": "reactions", "detailKeys": ["channelId", "messageId"] },
|
||||
"sendMessage": { "label": "send", "detailKeys": ["to", "content"] },
|
||||
"editMessage": { "label": "edit", "detailKeys": ["channelId", "messageId"] },
|
||||
"deleteMessage": { "label": "delete", "detailKeys": ["channelId", "messageId"] },
|
||||
"readMessages": { "label": "read messages", "detailKeys": ["channelId", "limit"] },
|
||||
"pinMessage": { "label": "pin", "detailKeys": ["channelId", "messageId"] },
|
||||
"unpinMessage": { "label": "unpin", "detailKeys": ["channelId", "messageId"] },
|
||||
"listPins": { "label": "list pins", "detailKeys": ["channelId"] },
|
||||
"memberInfo": { "label": "member", "detailKeys": ["userId"] },
|
||||
"emojiList": { "label": "emoji list" }
|
||||
}
|
||||
},
|
||||
"telegram": {
|
||||
"emoji": "✈️",
|
||||
"title": "Telegram",
|
||||
"actions": {
|
||||
"react": { "label": "react", "detailKeys": ["chatId", "messageId", "emoji", "remove"] }
|
||||
}
|
||||
},
|
||||
"whatsapp": {
|
||||
"emoji": "💬",
|
||||
"title": "WhatsApp",
|
||||
"actions": {
|
||||
"react": {
|
||||
"label": "react",
|
||||
"detailKeys": ["chatJid", "messageId", "emoji", "remove", "participant", "accountId", "fromMe"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
|
||||
import type { ClawdbotConfig } from "../../config/config.js";
|
||||
import { loadConfig } from "../../config/config.js";
|
||||
import {
|
||||
type MessagePollResult,
|
||||
type MessageSendResult,
|
||||
sendMessage,
|
||||
sendPoll,
|
||||
} from "../../infra/outbound/message.js";
|
||||
import { resolveMessageProviderSelection } from "../../infra/outbound/provider-selection.js";
|
||||
import { normalizeAccountId } from "../../routing/session-key.js";
|
||||
import type { AnyAgentTool } from "./common.js";
|
||||
import {
|
||||
jsonResult,
|
||||
@@ -13,36 +17,131 @@ import {
|
||||
readStringArrayParam,
|
||||
readStringParam,
|
||||
} from "./common.js";
|
||||
import { handleDiscordAction } from "./discord-actions.js";
|
||||
import { handleSlackAction } from "./slack-actions.js";
|
||||
import { handleTelegramAction } from "./telegram-actions.js";
|
||||
import { handleWhatsAppAction } from "./whatsapp-actions.js";
|
||||
|
||||
const MessageActionSchema = Type.Union([
|
||||
Type.Literal("send"),
|
||||
Type.Literal("poll"),
|
||||
Type.Literal("react"),
|
||||
Type.Literal("reactions"),
|
||||
Type.Literal("read"),
|
||||
Type.Literal("edit"),
|
||||
Type.Literal("delete"),
|
||||
Type.Literal("pin"),
|
||||
Type.Literal("unpin"),
|
||||
Type.Literal("list-pins"),
|
||||
Type.Literal("permissions"),
|
||||
Type.Literal("thread-create"),
|
||||
Type.Literal("thread-list"),
|
||||
Type.Literal("thread-reply"),
|
||||
Type.Literal("search"),
|
||||
Type.Literal("sticker"),
|
||||
Type.Literal("member-info"),
|
||||
Type.Literal("role-info"),
|
||||
Type.Literal("emoji-list"),
|
||||
Type.Literal("emoji-upload"),
|
||||
Type.Literal("sticker-upload"),
|
||||
Type.Literal("role-add"),
|
||||
Type.Literal("role-remove"),
|
||||
Type.Literal("channel-info"),
|
||||
Type.Literal("channel-list"),
|
||||
Type.Literal("voice-status"),
|
||||
Type.Literal("event-list"),
|
||||
Type.Literal("event-create"),
|
||||
Type.Literal("timeout"),
|
||||
Type.Literal("kick"),
|
||||
Type.Literal("ban"),
|
||||
]);
|
||||
|
||||
const MessageToolSchema = Type.Object({
|
||||
action: Type.Union([Type.Literal("send"), Type.Literal("poll")]),
|
||||
to: Type.Optional(Type.String()),
|
||||
content: Type.Optional(Type.String()),
|
||||
mediaUrl: Type.Optional(Type.String()),
|
||||
gifPlayback: Type.Optional(Type.Boolean()),
|
||||
action: MessageActionSchema,
|
||||
provider: Type.Optional(Type.String()),
|
||||
to: Type.Optional(Type.String()),
|
||||
message: Type.Optional(Type.String()),
|
||||
media: Type.Optional(Type.String()),
|
||||
messageId: Type.Optional(Type.String()),
|
||||
replyTo: Type.Optional(Type.String()),
|
||||
threadId: Type.Optional(Type.String()),
|
||||
accountId: Type.Optional(Type.String()),
|
||||
dryRun: Type.Optional(Type.Boolean()),
|
||||
bestEffort: Type.Optional(Type.Boolean()),
|
||||
question: Type.Optional(Type.String()),
|
||||
options: Type.Optional(Type.Array(Type.String())),
|
||||
maxSelections: Type.Optional(Type.Number()),
|
||||
durationHours: Type.Optional(Type.Number()),
|
||||
gifPlayback: Type.Optional(Type.Boolean()),
|
||||
emoji: Type.Optional(Type.String()),
|
||||
remove: Type.Optional(Type.Boolean()),
|
||||
limit: Type.Optional(Type.Number()),
|
||||
before: Type.Optional(Type.String()),
|
||||
after: Type.Optional(Type.String()),
|
||||
around: Type.Optional(Type.String()),
|
||||
pollQuestion: Type.Optional(Type.String()),
|
||||
pollOption: Type.Optional(Type.Array(Type.String())),
|
||||
pollDurationHours: Type.Optional(Type.Number()),
|
||||
pollMulti: Type.Optional(Type.Boolean()),
|
||||
channelId: Type.Optional(Type.String()),
|
||||
channelIds: Type.Optional(Type.Array(Type.String())),
|
||||
guildId: Type.Optional(Type.String()),
|
||||
userId: Type.Optional(Type.String()),
|
||||
authorId: Type.Optional(Type.String()),
|
||||
authorIds: Type.Optional(Type.Array(Type.String())),
|
||||
roleId: Type.Optional(Type.String()),
|
||||
roleIds: Type.Optional(Type.Array(Type.String())),
|
||||
emojiName: Type.Optional(Type.String()),
|
||||
stickerId: Type.Optional(Type.Array(Type.String())),
|
||||
stickerName: Type.Optional(Type.String()),
|
||||
stickerDesc: Type.Optional(Type.String()),
|
||||
stickerTags: Type.Optional(Type.String()),
|
||||
threadName: Type.Optional(Type.String()),
|
||||
autoArchiveMin: Type.Optional(Type.Number()),
|
||||
query: Type.Optional(Type.String()),
|
||||
eventName: Type.Optional(Type.String()),
|
||||
eventType: Type.Optional(Type.String()),
|
||||
startTime: Type.Optional(Type.String()),
|
||||
endTime: Type.Optional(Type.String()),
|
||||
desc: Type.Optional(Type.String()),
|
||||
location: Type.Optional(Type.String()),
|
||||
durationMin: Type.Optional(Type.Number()),
|
||||
until: Type.Optional(Type.String()),
|
||||
reason: Type.Optional(Type.String()),
|
||||
deleteDays: Type.Optional(Type.Number()),
|
||||
includeArchived: Type.Optional(Type.Boolean()),
|
||||
participant: Type.Optional(Type.String()),
|
||||
fromMe: Type.Optional(Type.Boolean()),
|
||||
gatewayUrl: Type.Optional(Type.String()),
|
||||
gatewayToken: Type.Optional(Type.String()),
|
||||
timeoutMs: Type.Optional(Type.Number()),
|
||||
});
|
||||
|
||||
export function createMessageTool(): AnyAgentTool {
|
||||
type MessageToolOptions = {
|
||||
agentAccountId?: string;
|
||||
config?: ClawdbotConfig;
|
||||
};
|
||||
|
||||
function resolveAgentAccountId(value?: string): string | undefined {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed) return undefined;
|
||||
return normalizeAccountId(trimmed);
|
||||
}
|
||||
|
||||
export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
const agentAccountId = resolveAgentAccountId(options?.agentAccountId);
|
||||
return {
|
||||
label: "Message",
|
||||
name: "message",
|
||||
description:
|
||||
"Send messages and polls across providers (send/poll). Prefer this for general outbound messaging.",
|
||||
"Send messages and provider-specific actions (Discord/Slack/Telegram/WhatsApp/Signal/iMessage).",
|
||||
parameters: MessageToolSchema,
|
||||
execute: async (_toolCallId, args) => {
|
||||
const params = args as Record<string, unknown>;
|
||||
const cfg = options?.config ?? loadConfig();
|
||||
const action = readStringParam(params, "action", { required: true });
|
||||
const providerSelection = await resolveMessageProviderSelection({
|
||||
cfg,
|
||||
provider: readStringParam(params, "provider"),
|
||||
});
|
||||
const provider = providerSelection.provider;
|
||||
const accountId = readStringParam(params, "accountId") ?? agentAccountId;
|
||||
const gateway = {
|
||||
url: readStringParam(params, "gatewayUrl", { trim: false }),
|
||||
token: readStringParam(params, "gatewayToken", { trim: false }),
|
||||
@@ -54,13 +153,13 @@ export function createMessageTool(): AnyAgentTool {
|
||||
|
||||
if (action === "send") {
|
||||
const to = readStringParam(params, "to", { required: true });
|
||||
const content = readStringParam(params, "content", {
|
||||
const message = readStringParam(params, "message", {
|
||||
required: true,
|
||||
allowEmpty: true,
|
||||
});
|
||||
const mediaUrl = readStringParam(params, "mediaUrl", { trim: false });
|
||||
const provider = readStringParam(params, "provider");
|
||||
const accountId = readStringParam(params, "accountId");
|
||||
const mediaUrl = readStringParam(params, "media", { trim: false });
|
||||
const replyTo = readStringParam(params, "replyTo");
|
||||
const threadId = readStringParam(params, "threadId");
|
||||
const gifPlayback =
|
||||
typeof params.gifPlayback === "boolean" ? params.gifPlayback : false;
|
||||
const bestEffort =
|
||||
@@ -68,12 +167,66 @@ export function createMessageTool(): AnyAgentTool {
|
||||
? params.bestEffort
|
||||
: undefined;
|
||||
|
||||
if (dryRun) {
|
||||
const result: MessageSendResult = await sendMessage({
|
||||
to,
|
||||
content: message,
|
||||
mediaUrl: mediaUrl || undefined,
|
||||
provider: provider || undefined,
|
||||
accountId: accountId ?? undefined,
|
||||
gifPlayback,
|
||||
dryRun,
|
||||
bestEffort,
|
||||
gateway,
|
||||
});
|
||||
return jsonResult(result);
|
||||
}
|
||||
|
||||
if (provider === "discord") {
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "sendMessage",
|
||||
to,
|
||||
content: message,
|
||||
mediaUrl: mediaUrl ?? undefined,
|
||||
replyTo: replyTo ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{
|
||||
action: "sendMessage",
|
||||
to,
|
||||
content: message,
|
||||
mediaUrl: mediaUrl ?? undefined,
|
||||
accountId: accountId ?? undefined,
|
||||
threadTs: threadId ?? replyTo ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "telegram") {
|
||||
return await handleTelegramAction(
|
||||
{
|
||||
action: "sendMessage",
|
||||
to,
|
||||
content: message,
|
||||
mediaUrl: mediaUrl ?? undefined,
|
||||
replyToMessageId: replyTo ?? undefined,
|
||||
messageThreadId: threadId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
const result: MessageSendResult = await sendMessage({
|
||||
to,
|
||||
content,
|
||||
content: message,
|
||||
mediaUrl: mediaUrl || undefined,
|
||||
provider: provider || undefined,
|
||||
accountId: accountId || undefined,
|
||||
accountId: accountId ?? undefined,
|
||||
gifPlayback,
|
||||
dryRun,
|
||||
bestEffort,
|
||||
@@ -84,32 +237,679 @@ export function createMessageTool(): AnyAgentTool {
|
||||
|
||||
if (action === "poll") {
|
||||
const to = readStringParam(params, "to", { required: true });
|
||||
const question = readStringParam(params, "question", {
|
||||
const question = readStringParam(params, "pollQuestion", {
|
||||
required: true,
|
||||
});
|
||||
const options =
|
||||
readStringArrayParam(params, "options", { required: true }) ?? [];
|
||||
const maxSelections = readNumberParam(params, "maxSelections", {
|
||||
readStringArrayParam(params, "pollOption", { required: true }) ?? [];
|
||||
const allowMultiselect =
|
||||
typeof params.pollMulti === "boolean" ? params.pollMulti : undefined;
|
||||
const durationHours = readNumberParam(params, "pollDurationHours", {
|
||||
integer: true,
|
||||
});
|
||||
const durationHours = readNumberParam(params, "durationHours", {
|
||||
integer: true,
|
||||
});
|
||||
const provider = readStringParam(params, "provider");
|
||||
|
||||
if (dryRun) {
|
||||
const maxSelections = allowMultiselect
|
||||
? Math.max(2, options.length)
|
||||
: 1;
|
||||
const result: MessagePollResult = await sendPoll({
|
||||
to,
|
||||
question,
|
||||
options,
|
||||
maxSelections,
|
||||
durationHours: durationHours ?? undefined,
|
||||
provider,
|
||||
dryRun,
|
||||
gateway,
|
||||
});
|
||||
return jsonResult(result);
|
||||
}
|
||||
|
||||
if (provider === "discord") {
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "poll",
|
||||
to,
|
||||
question,
|
||||
answers: options,
|
||||
allowMultiselect,
|
||||
durationHours: durationHours ?? undefined,
|
||||
content: readStringParam(params, "message"),
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
const maxSelections = allowMultiselect
|
||||
? Math.max(2, options.length)
|
||||
: 1;
|
||||
const result: MessagePollResult = await sendPoll({
|
||||
to,
|
||||
question,
|
||||
options,
|
||||
maxSelections,
|
||||
durationHours,
|
||||
provider: provider || undefined,
|
||||
durationHours: durationHours ?? undefined,
|
||||
provider,
|
||||
dryRun,
|
||||
gateway,
|
||||
});
|
||||
return jsonResult(result);
|
||||
}
|
||||
|
||||
const resolveChannelId = (label: string) =>
|
||||
readStringParam(params, label) ??
|
||||
readStringParam(params, "to", { required: true });
|
||||
|
||||
const resolveChatId = (label: string) =>
|
||||
readStringParam(params, label) ??
|
||||
readStringParam(params, "to", { required: true });
|
||||
|
||||
if (action === "react") {
|
||||
const messageId = readStringParam(params, "messageId", {
|
||||
required: true,
|
||||
});
|
||||
const emoji = readStringParam(params, "emoji", { allowEmpty: true });
|
||||
const remove =
|
||||
typeof params.remove === "boolean" ? params.remove : undefined;
|
||||
if (provider === "discord") {
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "react",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
emoji,
|
||||
remove,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{
|
||||
action: "react",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
emoji,
|
||||
remove,
|
||||
accountId: accountId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "telegram") {
|
||||
return await handleTelegramAction(
|
||||
{
|
||||
action: "react",
|
||||
chatId: resolveChatId("chatId"),
|
||||
messageId,
|
||||
emoji,
|
||||
remove,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "whatsapp") {
|
||||
return await handleWhatsAppAction(
|
||||
{
|
||||
action: "react",
|
||||
chatJid: resolveChatId("chatJid"),
|
||||
messageId,
|
||||
emoji,
|
||||
remove,
|
||||
participant: readStringParam(params, "participant"),
|
||||
accountId: accountId ?? undefined,
|
||||
fromMe:
|
||||
typeof params.fromMe === "boolean" ? params.fromMe : undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(`React is not supported for provider ${provider}.`);
|
||||
}
|
||||
|
||||
if (action === "reactions") {
|
||||
const messageId = readStringParam(params, "messageId", {
|
||||
required: true,
|
||||
});
|
||||
const limit = readNumberParam(params, "limit", { integer: true });
|
||||
if (provider === "discord") {
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "reactions",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
limit,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{
|
||||
action: "reactions",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
limit,
|
||||
accountId: accountId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Reactions are not supported for provider ${provider}.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "read") {
|
||||
const limit = readNumberParam(params, "limit", { integer: true });
|
||||
const before = readStringParam(params, "before");
|
||||
const after = readStringParam(params, "after");
|
||||
const around = readStringParam(params, "around");
|
||||
if (provider === "discord") {
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "readMessages",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
limit,
|
||||
before,
|
||||
after,
|
||||
around,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{
|
||||
action: "readMessages",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
limit,
|
||||
before,
|
||||
after,
|
||||
accountId: accountId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(`Read is not supported for provider ${provider}.`);
|
||||
}
|
||||
|
||||
if (action === "edit") {
|
||||
const messageId = readStringParam(params, "messageId", {
|
||||
required: true,
|
||||
});
|
||||
const message = readStringParam(params, "message", { required: true });
|
||||
if (provider === "discord") {
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "editMessage",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
content: message,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{
|
||||
action: "editMessage",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
content: message,
|
||||
accountId: accountId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(`Edit is not supported for provider ${provider}.`);
|
||||
}
|
||||
|
||||
if (action === "delete") {
|
||||
const messageId = readStringParam(params, "messageId", {
|
||||
required: true,
|
||||
});
|
||||
if (provider === "discord") {
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "deleteMessage",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{
|
||||
action: "deleteMessage",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
messageId,
|
||||
accountId: accountId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(`Delete is not supported for provider ${provider}.`);
|
||||
}
|
||||
|
||||
if (action === "pin" || action === "unpin" || action === "list-pins") {
|
||||
const messageId =
|
||||
action === "list-pins"
|
||||
? undefined
|
||||
: readStringParam(params, "messageId", { required: true });
|
||||
const channelId = resolveChannelId("channelId");
|
||||
if (provider === "discord") {
|
||||
const discordAction =
|
||||
action === "pin"
|
||||
? "pinMessage"
|
||||
: action === "unpin"
|
||||
? "unpinMessage"
|
||||
: "listPins";
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: discordAction,
|
||||
channelId,
|
||||
messageId,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
const slackAction =
|
||||
action === "pin"
|
||||
? "pinMessage"
|
||||
: action === "unpin"
|
||||
? "unpinMessage"
|
||||
: "listPins";
|
||||
return await handleSlackAction(
|
||||
{
|
||||
action: slackAction,
|
||||
channelId,
|
||||
messageId,
|
||||
accountId: accountId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(`Pins are not supported for provider ${provider}.`);
|
||||
}
|
||||
|
||||
if (action === "permissions") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Permissions are only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "permissions",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "thread-create") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Thread create is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const name = readStringParam(params, "threadName", { required: true });
|
||||
const messageId = readStringParam(params, "messageId");
|
||||
const autoArchiveMinutes = readNumberParam(params, "autoArchiveMin", {
|
||||
integer: true,
|
||||
});
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "threadCreate",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
name,
|
||||
messageId,
|
||||
autoArchiveMinutes,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "thread-list") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Thread list is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const channelId = readStringParam(params, "channelId");
|
||||
const includeArchived =
|
||||
typeof params.includeArchived === "boolean"
|
||||
? params.includeArchived
|
||||
: undefined;
|
||||
const before = readStringParam(params, "before");
|
||||
const limit = readNumberParam(params, "limit", { integer: true });
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "threadList",
|
||||
guildId,
|
||||
channelId,
|
||||
includeArchived,
|
||||
before,
|
||||
limit,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "thread-reply") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Thread reply is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const content = readStringParam(params, "message", { required: true });
|
||||
const mediaUrl = readStringParam(params, "media", { trim: false });
|
||||
const replyTo = readStringParam(params, "replyTo");
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "threadReply",
|
||||
channelId: resolveChannelId("channelId"),
|
||||
content,
|
||||
mediaUrl: mediaUrl ?? undefined,
|
||||
replyTo: replyTo ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "search") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Search is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const query = readStringParam(params, "query", { required: true });
|
||||
const channelId = readStringParam(params, "channelId");
|
||||
const channelIds = readStringArrayParam(params, "channelIds");
|
||||
const authorId = readStringParam(params, "authorId");
|
||||
const authorIds = readStringArrayParam(params, "authorIds");
|
||||
const limit = readNumberParam(params, "limit", { integer: true });
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "searchMessages",
|
||||
guildId,
|
||||
content: query,
|
||||
channelId,
|
||||
channelIds,
|
||||
authorId,
|
||||
authorIds,
|
||||
limit,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "sticker") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Sticker send is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const stickerIds =
|
||||
readStringArrayParam(params, "stickerId", {
|
||||
required: true,
|
||||
label: "sticker-id",
|
||||
}) ?? [];
|
||||
const content = readStringParam(params, "message");
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "sticker",
|
||||
to: readStringParam(params, "to", { required: true }),
|
||||
stickerIds,
|
||||
content,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "member-info") {
|
||||
const userId = readStringParam(params, "userId", { required: true });
|
||||
if (provider === "discord") {
|
||||
const guildId = readStringParam(params, "guildId", {
|
||||
required: true,
|
||||
});
|
||||
return await handleDiscordAction(
|
||||
{ action: "memberInfo", guildId, userId },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{ action: "memberInfo", userId, accountId: accountId ?? undefined },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Member info is not supported for provider ${provider}.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "role-info") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Role info is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
return await handleDiscordAction({ action: "roleInfo", guildId }, cfg);
|
||||
}
|
||||
|
||||
if (action === "emoji-list") {
|
||||
if (provider === "discord") {
|
||||
const guildId = readStringParam(params, "guildId", {
|
||||
required: true,
|
||||
});
|
||||
return await handleDiscordAction(
|
||||
{ action: "emojiList", guildId },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
if (provider === "slack") {
|
||||
return await handleSlackAction(
|
||||
{ action: "emojiList", accountId: accountId ?? undefined },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Emoji list is not supported for provider ${provider}.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "emoji-upload") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Emoji upload is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const name = readStringParam(params, "emojiName", { required: true });
|
||||
const mediaUrl = readStringParam(params, "media", {
|
||||
required: true,
|
||||
trim: false,
|
||||
});
|
||||
const roleIds = readStringArrayParam(params, "roleIds");
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "emojiUpload",
|
||||
guildId,
|
||||
name,
|
||||
mediaUrl,
|
||||
roleIds,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "sticker-upload") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Sticker upload is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const name = readStringParam(params, "stickerName", { required: true });
|
||||
const description = readStringParam(params, "stickerDesc", {
|
||||
required: true,
|
||||
});
|
||||
const tags = readStringParam(params, "stickerTags", { required: true });
|
||||
const mediaUrl = readStringParam(params, "media", {
|
||||
required: true,
|
||||
trim: false,
|
||||
});
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "stickerUpload",
|
||||
guildId,
|
||||
name,
|
||||
description,
|
||||
tags,
|
||||
mediaUrl,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "role-add" || action === "role-remove") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Role changes are only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const userId = readStringParam(params, "userId", { required: true });
|
||||
const roleId = readStringParam(params, "roleId", { required: true });
|
||||
const discordAction = action === "role-add" ? "roleAdd" : "roleRemove";
|
||||
return await handleDiscordAction(
|
||||
{ action: discordAction, guildId, userId, roleId },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "channel-info") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Channel info is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const channelId = readStringParam(params, "channelId", {
|
||||
required: true,
|
||||
});
|
||||
return await handleDiscordAction(
|
||||
{ action: "channelInfo", channelId },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "channel-list") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Channel list is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
return await handleDiscordAction(
|
||||
{ action: "channelList", guildId },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "voice-status") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Voice status is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const userId = readStringParam(params, "userId", { required: true });
|
||||
return await handleDiscordAction(
|
||||
{ action: "voiceStatus", guildId, userId },
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "event-list") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Event list is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
return await handleDiscordAction({ action: "eventList", guildId }, cfg);
|
||||
}
|
||||
|
||||
if (action === "event-create") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Event create is only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const name = readStringParam(params, "eventName", { required: true });
|
||||
const startTime = readStringParam(params, "startTime", {
|
||||
required: true,
|
||||
});
|
||||
const endTime = readStringParam(params, "endTime");
|
||||
const description = readStringParam(params, "desc");
|
||||
const channelId = readStringParam(params, "channelId");
|
||||
const location = readStringParam(params, "location");
|
||||
const entityType = readStringParam(params, "eventType");
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "eventCreate",
|
||||
guildId,
|
||||
name,
|
||||
startTime,
|
||||
endTime,
|
||||
description,
|
||||
channelId,
|
||||
location,
|
||||
entityType,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "timeout" || action === "kick" || action === "ban") {
|
||||
if (provider !== "discord") {
|
||||
throw new Error(
|
||||
`Moderation actions are only supported for Discord (provider=${provider}).`,
|
||||
);
|
||||
}
|
||||
const guildId = readStringParam(params, "guildId", { required: true });
|
||||
const userId = readStringParam(params, "userId", { required: true });
|
||||
const durationMinutes = readNumberParam(params, "durationMin", {
|
||||
integer: true,
|
||||
});
|
||||
const until = readStringParam(params, "until");
|
||||
const reason = readStringParam(params, "reason");
|
||||
const deleteMessageDays = readNumberParam(params, "deleteDays", {
|
||||
integer: true,
|
||||
});
|
||||
const discordAction = action as "timeout" | "kick" | "ban";
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: discordAction,
|
||||
guildId,
|
||||
userId,
|
||||
durationMinutes,
|
||||
until,
|
||||
reason,
|
||||
deleteMessageDays,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(`Unknown action: ${action}`);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -91,9 +91,11 @@ export async function handleSlackAction(
|
||||
const to = readStringParam(params, "to", { required: true });
|
||||
const content = readStringParam(params, "content", { required: true });
|
||||
const mediaUrl = readStringParam(params, "mediaUrl");
|
||||
const threadTs = readStringParam(params, "threadTs");
|
||||
const result = await sendSlackMessage(to, content, {
|
||||
accountId: accountId ?? undefined,
|
||||
mediaUrl: mediaUrl ?? undefined,
|
||||
threadTs: threadTs ?? undefined,
|
||||
});
|
||||
return jsonResult({ ok: true, result });
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ export const SlackToolSchema = Type.Union([
|
||||
to: Type.String(),
|
||||
content: Type.String(),
|
||||
mediaUrl: Type.Optional(Type.String()),
|
||||
threadTs: Type.Optional(Type.String()),
|
||||
accountId: Type.Optional(Type.String()),
|
||||
}),
|
||||
Type.Object({
|
||||
|
||||
Reference in New Issue
Block a user