Commands: add dynamic arg menus
This commit is contained in:
committed by
Peter Steinberger
parent
7e1e7ba2d8
commit
74bc5bfd7c
66
src/auto-reply/commands-args.ts
Normal file
66
src/auto-reply/commands-args.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import type { CommandArgValues } from "./commands-registry.types.js";
|
||||
|
||||
export type CommandArgsFormatter = (values: CommandArgValues) => string | undefined;
|
||||
|
||||
function normalizeArgValue(value: unknown): string | undefined {
|
||||
if (value == null) return undefined;
|
||||
const text = typeof value === "string" ? value.trim() : String(value).trim();
|
||||
return text ? text : undefined;
|
||||
}
|
||||
|
||||
const formatConfigArgs: CommandArgsFormatter = (values) => {
|
||||
const action = normalizeArgValue(values.action)?.toLowerCase();
|
||||
const path = normalizeArgValue(values.path);
|
||||
const value = normalizeArgValue(values.value);
|
||||
if (!action) return undefined;
|
||||
if (action === "show" || action === "get") {
|
||||
return path ? `${action} ${path}` : action;
|
||||
}
|
||||
if (action === "unset") {
|
||||
return path ? `${action} ${path}` : action;
|
||||
}
|
||||
if (action === "set") {
|
||||
if (!path) return action;
|
||||
if (!value) return `${action} ${path}`;
|
||||
return `${action} ${path}=${value}`;
|
||||
}
|
||||
return action;
|
||||
};
|
||||
|
||||
const formatDebugArgs: CommandArgsFormatter = (values) => {
|
||||
const action = normalizeArgValue(values.action)?.toLowerCase();
|
||||
const path = normalizeArgValue(values.path);
|
||||
const value = normalizeArgValue(values.value);
|
||||
if (!action) return undefined;
|
||||
if (action === "show" || action === "reset") {
|
||||
return action;
|
||||
}
|
||||
if (action === "unset") {
|
||||
return path ? `${action} ${path}` : action;
|
||||
}
|
||||
if (action === "set") {
|
||||
if (!path) return action;
|
||||
if (!value) return `${action} ${path}`;
|
||||
return `${action} ${path}=${value}`;
|
||||
}
|
||||
return action;
|
||||
};
|
||||
|
||||
const formatQueueArgs: CommandArgsFormatter = (values) => {
|
||||
const mode = normalizeArgValue(values.mode);
|
||||
const debounce = normalizeArgValue(values.debounce);
|
||||
const cap = normalizeArgValue(values.cap);
|
||||
const drop = normalizeArgValue(values.drop);
|
||||
const parts: string[] = [];
|
||||
if (mode) parts.push(mode);
|
||||
if (debounce) parts.push(`debounce:${debounce}`);
|
||||
if (cap) parts.push(`cap:${cap}`);
|
||||
if (drop) parts.push(`drop:${drop}`);
|
||||
return parts.length > 0 ? parts.join(" ") : undefined;
|
||||
};
|
||||
|
||||
export const COMMAND_ARG_FORMATTERS: Record<string, CommandArgsFormatter> = {
|
||||
config: formatConfigArgs,
|
||||
debug: formatDebugArgs,
|
||||
queue: formatQueueArgs,
|
||||
};
|
||||
@@ -1,10 +1,16 @@
|
||||
import { listChannelDocks } from "../channels/dock.js";
|
||||
import { listThinkingLevels } from "./thinking.js";
|
||||
import { COMMAND_ARG_FORMATTERS } from "./commands-args.js";
|
||||
import type { ChatCommandDefinition, CommandScope } from "./commands-registry.types.js";
|
||||
|
||||
type DefineChatCommandInput = {
|
||||
key: string;
|
||||
nativeName?: string;
|
||||
description: string;
|
||||
args?: ChatCommandDefinition["args"];
|
||||
argsParsing?: ChatCommandDefinition["argsParsing"];
|
||||
formatArgs?: ChatCommandDefinition["formatArgs"];
|
||||
argsMenu?: ChatCommandDefinition["argsMenu"];
|
||||
acceptsArgs?: boolean;
|
||||
textAlias?: string;
|
||||
textAliases?: string[];
|
||||
@@ -17,11 +23,17 @@ function defineChatCommand(command: DefineChatCommandInput): ChatCommandDefiniti
|
||||
.filter(Boolean);
|
||||
const scope =
|
||||
command.scope ?? (command.nativeName ? (aliases.length ? "both" : "native") : "text");
|
||||
const acceptsArgs = command.acceptsArgs ?? Boolean(command.args?.length);
|
||||
const argsParsing = command.argsParsing ?? (command.args?.length ? "positional" : "none");
|
||||
return {
|
||||
key: command.key,
|
||||
nativeName: command.nativeName,
|
||||
description: command.description,
|
||||
acceptsArgs: command.acceptsArgs,
|
||||
acceptsArgs,
|
||||
args: command.args,
|
||||
argsParsing,
|
||||
formatArgs: command.formatArgs,
|
||||
argsMenu: command.argsMenu,
|
||||
textAliases: aliases,
|
||||
scope,
|
||||
};
|
||||
@@ -35,7 +47,6 @@ function defineDockCommand(dock: ChannelDock): ChatCommandDefinition {
|
||||
nativeName: `dock_${dock.id}`,
|
||||
description: `Switch to ${dock.id} for replies.`,
|
||||
textAliases: [`/dock-${dock.id}`, `/dock_${dock.id}`],
|
||||
acceptsArgs: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -138,21 +149,69 @@ export const CHAT_COMMANDS: ChatCommandDefinition[] = (() => {
|
||||
nativeName: "config",
|
||||
description: "Show or set config values.",
|
||||
textAlias: "/config",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "action",
|
||||
description: "show | get | set | unset",
|
||||
type: "string",
|
||||
choices: ["show", "get", "set", "unset"],
|
||||
},
|
||||
{
|
||||
name: "path",
|
||||
description: "Config path",
|
||||
type: "string",
|
||||
},
|
||||
{
|
||||
name: "value",
|
||||
description: "Value for set",
|
||||
type: "string",
|
||||
captureRemaining: true,
|
||||
},
|
||||
],
|
||||
argsParsing: "none",
|
||||
formatArgs: COMMAND_ARG_FORMATTERS.config,
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "debug",
|
||||
nativeName: "debug",
|
||||
description: "Set runtime debug overrides.",
|
||||
textAlias: "/debug",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "action",
|
||||
description: "show | reset | set | unset",
|
||||
type: "string",
|
||||
choices: ["show", "reset", "set", "unset"],
|
||||
},
|
||||
{
|
||||
name: "path",
|
||||
description: "Debug path",
|
||||
type: "string",
|
||||
},
|
||||
{
|
||||
name: "value",
|
||||
description: "Value for set",
|
||||
type: "string",
|
||||
captureRemaining: true,
|
||||
},
|
||||
],
|
||||
argsParsing: "none",
|
||||
formatArgs: COMMAND_ARG_FORMATTERS.debug,
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "cost",
|
||||
nativeName: "cost",
|
||||
description: "Toggle per-response usage line.",
|
||||
textAlias: "/cost",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "mode",
|
||||
description: "on or off",
|
||||
type: "string",
|
||||
choices: ["on", "off"],
|
||||
},
|
||||
],
|
||||
argsMenu: "auto",
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "stop",
|
||||
@@ -171,14 +230,30 @@ export const CHAT_COMMANDS: ChatCommandDefinition[] = (() => {
|
||||
nativeName: "activation",
|
||||
description: "Set group activation mode.",
|
||||
textAlias: "/activation",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "mode",
|
||||
description: "mention or always",
|
||||
type: "string",
|
||||
choices: ["mention", "always"],
|
||||
},
|
||||
],
|
||||
argsMenu: "auto",
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "send",
|
||||
nativeName: "send",
|
||||
description: "Set send policy.",
|
||||
textAlias: "/send",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "mode",
|
||||
description: "on, off, or inherit",
|
||||
type: "string",
|
||||
choices: ["on", "off", "inherit"],
|
||||
},
|
||||
],
|
||||
argsMenu: "auto",
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "reset",
|
||||
@@ -197,56 +272,133 @@ export const CHAT_COMMANDS: ChatCommandDefinition[] = (() => {
|
||||
description: "Compact the session context.",
|
||||
textAlias: "/compact",
|
||||
scope: "text",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "instructions",
|
||||
description: "Extra compaction instructions",
|
||||
type: "string",
|
||||
captureRemaining: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "think",
|
||||
nativeName: "think",
|
||||
description: "Set thinking level.",
|
||||
textAlias: "/think",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "level",
|
||||
description: "off, minimal, low, medium, high, xhigh",
|
||||
type: "string",
|
||||
choices: ({ provider, model }) => listThinkingLevels(provider, model),
|
||||
},
|
||||
],
|
||||
argsMenu: "auto",
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "verbose",
|
||||
nativeName: "verbose",
|
||||
description: "Toggle verbose mode.",
|
||||
textAlias: "/verbose",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "mode",
|
||||
description: "on or off",
|
||||
type: "string",
|
||||
choices: ["on", "off"],
|
||||
},
|
||||
],
|
||||
argsMenu: "auto",
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "reasoning",
|
||||
nativeName: "reasoning",
|
||||
description: "Toggle reasoning visibility.",
|
||||
textAlias: "/reasoning",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "mode",
|
||||
description: "on, off, or stream",
|
||||
type: "string",
|
||||
choices: ["on", "off", "stream"],
|
||||
},
|
||||
],
|
||||
argsMenu: "auto",
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "elevated",
|
||||
nativeName: "elevated",
|
||||
description: "Toggle elevated mode.",
|
||||
textAlias: "/elevated",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "mode",
|
||||
description: "on or off",
|
||||
type: "string",
|
||||
choices: ["on", "off"],
|
||||
},
|
||||
],
|
||||
argsMenu: "auto",
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "model",
|
||||
nativeName: "model",
|
||||
description: "Show or set the model.",
|
||||
textAlias: "/model",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "model",
|
||||
description: "Model id (provider/model or id)",
|
||||
type: "string",
|
||||
},
|
||||
],
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "queue",
|
||||
nativeName: "queue",
|
||||
description: "Adjust queue settings.",
|
||||
textAlias: "/queue",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "mode",
|
||||
description: "queue mode",
|
||||
type: "string",
|
||||
choices: ["steer", "interrupt", "followup", "collect", "steer-backlog"],
|
||||
},
|
||||
{
|
||||
name: "debounce",
|
||||
description: "debounce duration (e.g. 500ms, 2s)",
|
||||
type: "string",
|
||||
},
|
||||
{
|
||||
name: "cap",
|
||||
description: "queue cap",
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
name: "drop",
|
||||
description: "drop policy",
|
||||
type: "string",
|
||||
choices: ["old", "new", "summarize"],
|
||||
},
|
||||
],
|
||||
argsParsing: "none",
|
||||
formatArgs: COMMAND_ARG_FORMATTERS.queue,
|
||||
}),
|
||||
defineChatCommand({
|
||||
key: "bash",
|
||||
description: "Run host shell commands (host-only).",
|
||||
textAlias: "/bash",
|
||||
scope: "text",
|
||||
acceptsArgs: true,
|
||||
args: [
|
||||
{
|
||||
name: "command",
|
||||
description: "Shell command",
|
||||
type: "string",
|
||||
captureRemaining: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
...listChannelDocks()
|
||||
.filter((dock) => dock.capabilities.nativeCommands)
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import type { ClawdbotConfig } from "../config/types.js";
|
||||
import { CHAT_COMMANDS, getNativeCommandSurfaces } from "./commands-registry.data.js";
|
||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
|
||||
import { resolveConfiguredModelRef } from "../agents/model-selection.js";
|
||||
import type {
|
||||
ChatCommandDefinition,
|
||||
CommandArgChoiceContext,
|
||||
CommandArgDefinition,
|
||||
CommandArgMenuSpec,
|
||||
CommandArgValues,
|
||||
CommandArgs,
|
||||
CommandDetection,
|
||||
CommandNormalizeOptions,
|
||||
NativeCommandSpec,
|
||||
@@ -11,6 +18,11 @@ import type {
|
||||
export { CHAT_COMMANDS } from "./commands-registry.data.js";
|
||||
export type {
|
||||
ChatCommandDefinition,
|
||||
CommandArgChoiceContext,
|
||||
CommandArgDefinition,
|
||||
CommandArgMenuSpec,
|
||||
CommandArgValues,
|
||||
CommandArgs,
|
||||
CommandDetection,
|
||||
CommandNormalizeOptions,
|
||||
CommandScope,
|
||||
@@ -70,6 +82,7 @@ export function listNativeCommandSpecs(): NativeCommandSpec[] {
|
||||
name: command.nativeName ?? command.key,
|
||||
description: command.description,
|
||||
acceptsArgs: Boolean(command.acceptsArgs),
|
||||
args: command.args,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -81,6 +94,7 @@ export function listNativeCommandSpecsForConfig(cfg: ClawdbotConfig): NativeComm
|
||||
name: command.nativeName ?? command.key,
|
||||
description: command.description,
|
||||
acceptsArgs: Boolean(command.acceptsArgs),
|
||||
args: command.args,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -96,6 +110,137 @@ export function buildCommandText(commandName: string, args?: string): string {
|
||||
return trimmedArgs ? `/${commandName} ${trimmedArgs}` : `/${commandName}`;
|
||||
}
|
||||
|
||||
function parsePositionalArgs(definitions: CommandArgDefinition[], raw: string): CommandArgValues {
|
||||
const values: CommandArgValues = {};
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) return values;
|
||||
const tokens = trimmed.split(/\s+/).filter(Boolean);
|
||||
let index = 0;
|
||||
for (const definition of definitions) {
|
||||
if (index >= tokens.length) break;
|
||||
if (definition.captureRemaining) {
|
||||
values[definition.name] = tokens.slice(index).join(" ");
|
||||
index = tokens.length;
|
||||
break;
|
||||
}
|
||||
values[definition.name] = tokens[index];
|
||||
index += 1;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
function formatPositionalArgs(
|
||||
definitions: CommandArgDefinition[],
|
||||
values: CommandArgValues,
|
||||
): string | undefined {
|
||||
const parts: string[] = [];
|
||||
for (const definition of definitions) {
|
||||
const value = values[definition.name];
|
||||
if (value == null) continue;
|
||||
const rendered = typeof value === "string" ? value.trim() : String(value);
|
||||
if (!rendered) continue;
|
||||
parts.push(rendered);
|
||||
if (definition.captureRemaining) break;
|
||||
}
|
||||
return parts.length > 0 ? parts.join(" ") : undefined;
|
||||
}
|
||||
|
||||
export function parseCommandArgs(
|
||||
command: ChatCommandDefinition,
|
||||
raw?: string,
|
||||
): CommandArgs | undefined {
|
||||
const trimmed = raw?.trim();
|
||||
if (!trimmed) return undefined;
|
||||
if (!command.args || command.argsParsing === "none") {
|
||||
return { raw: trimmed };
|
||||
}
|
||||
return {
|
||||
raw: trimmed,
|
||||
values: parsePositionalArgs(command.args, trimmed),
|
||||
};
|
||||
}
|
||||
|
||||
export function serializeCommandArgs(
|
||||
command: ChatCommandDefinition,
|
||||
args?: CommandArgs,
|
||||
): string | undefined {
|
||||
if (!args) return undefined;
|
||||
const raw = args.raw?.trim();
|
||||
if (raw) return raw;
|
||||
if (!args.values || !command.args) return undefined;
|
||||
if (command.formatArgs) return command.formatArgs(args.values);
|
||||
return formatPositionalArgs(command.args, args.values);
|
||||
}
|
||||
|
||||
export function buildCommandTextFromArgs(
|
||||
command: ChatCommandDefinition,
|
||||
args?: CommandArgs,
|
||||
): string {
|
||||
const commandName = command.nativeName ?? command.key;
|
||||
return buildCommandText(commandName, serializeCommandArgs(command, args));
|
||||
}
|
||||
|
||||
function resolveDefaultCommandContext(cfg?: ClawdbotConfig): {
|
||||
provider: string;
|
||||
model: string;
|
||||
} {
|
||||
const resolved = resolveConfiguredModelRef({
|
||||
cfg: cfg ?? ({} as ClawdbotConfig),
|
||||
defaultProvider: DEFAULT_PROVIDER,
|
||||
defaultModel: DEFAULT_MODEL,
|
||||
});
|
||||
return {
|
||||
provider: resolved.provider ?? DEFAULT_PROVIDER,
|
||||
model: resolved.model ?? DEFAULT_MODEL,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveCommandArgChoices(params: {
|
||||
command: ChatCommandDefinition;
|
||||
arg: CommandArgDefinition;
|
||||
cfg?: ClawdbotConfig;
|
||||
provider?: string;
|
||||
model?: string;
|
||||
}): string[] {
|
||||
const { command, arg, cfg } = params;
|
||||
if (!arg.choices) return [];
|
||||
const provided = arg.choices;
|
||||
if (Array.isArray(provided)) return provided;
|
||||
const defaults = resolveDefaultCommandContext(cfg);
|
||||
const context: CommandArgChoiceContext = {
|
||||
cfg,
|
||||
provider: params.provider ?? defaults.provider,
|
||||
model: params.model ?? defaults.model,
|
||||
command,
|
||||
arg,
|
||||
};
|
||||
return provided(context);
|
||||
}
|
||||
|
||||
export function resolveCommandArgMenu(params: {
|
||||
command: ChatCommandDefinition;
|
||||
args?: CommandArgs;
|
||||
cfg?: ClawdbotConfig;
|
||||
}): { arg: CommandArgDefinition; choices: string[]; title?: string } | null {
|
||||
const { command, args, cfg } = params;
|
||||
if (!command.args || !command.argsMenu) return null;
|
||||
if (command.argsParsing === "none") return null;
|
||||
const argSpec = command.argsMenu;
|
||||
const argName =
|
||||
argSpec === "auto"
|
||||
? command.args.find((arg) => resolveCommandArgChoices({ command, arg, cfg }).length > 0)?.name
|
||||
: argSpec.arg;
|
||||
if (!argName) return null;
|
||||
if (args?.values && args.values[argName] != null) return null;
|
||||
if (args?.raw && !args.values) return null;
|
||||
const arg = command.args.find((entry) => entry.name === argName);
|
||||
if (!arg) return null;
|
||||
const choices = resolveCommandArgChoices({ command, arg, cfg });
|
||||
if (choices.length === 0) return null;
|
||||
const title = argSpec !== "auto" ? argSpec.title : undefined;
|
||||
return { arg, choices, title };
|
||||
}
|
||||
|
||||
export function normalizeCommandBody(raw: string, options?: CommandNormalizeOptions): string {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed.startsWith("/")) return trimmed;
|
||||
|
||||
@@ -2,12 +2,51 @@ import type { ClawdbotConfig } from "../config/types.js";
|
||||
|
||||
export type CommandScope = "text" | "native" | "both";
|
||||
|
||||
export type CommandArgType = "string" | "number" | "boolean";
|
||||
|
||||
export type CommandArgChoiceContext = {
|
||||
cfg?: ClawdbotConfig;
|
||||
provider?: string;
|
||||
model?: string;
|
||||
command: ChatCommandDefinition;
|
||||
arg: CommandArgDefinition;
|
||||
};
|
||||
|
||||
export type CommandArgChoicesProvider = (context: CommandArgChoiceContext) => string[];
|
||||
|
||||
export type CommandArgDefinition = {
|
||||
name: string;
|
||||
description: string;
|
||||
type: CommandArgType;
|
||||
required?: boolean;
|
||||
choices?: string[] | CommandArgChoicesProvider;
|
||||
captureRemaining?: boolean;
|
||||
};
|
||||
|
||||
export type CommandArgMenuSpec = {
|
||||
arg: string;
|
||||
title?: string;
|
||||
};
|
||||
|
||||
export type CommandArgValues = Record<string, unknown>;
|
||||
|
||||
export type CommandArgs = {
|
||||
raw?: string;
|
||||
values?: CommandArgValues;
|
||||
};
|
||||
|
||||
export type CommandArgsParsing = "none" | "positional";
|
||||
|
||||
export type ChatCommandDefinition = {
|
||||
key: string;
|
||||
nativeName?: string;
|
||||
description: string;
|
||||
textAliases: string[];
|
||||
acceptsArgs?: boolean;
|
||||
args?: CommandArgDefinition[];
|
||||
argsParsing?: CommandArgsParsing;
|
||||
formatArgs?: (values: CommandArgValues) => string | undefined;
|
||||
argsMenu?: CommandArgMenuSpec | "auto";
|
||||
scope: CommandScope;
|
||||
};
|
||||
|
||||
@@ -15,6 +54,7 @@ export type NativeCommandSpec = {
|
||||
name: string;
|
||||
description: string;
|
||||
acceptsArgs: boolean;
|
||||
args?: CommandArgDefinition[];
|
||||
};
|
||||
|
||||
export type CommandNormalizeOptions = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import type { InternalMessageChannel } from "../utils/message-channel.js";
|
||||
import type { CommandArgs } from "./commands-registry.types.js";
|
||||
|
||||
/** Valid message channels for routing. */
|
||||
export type OriginatingChannelType = ChannelId | InternalMessageChannel;
|
||||
@@ -15,6 +16,7 @@ export type MsgContext = {
|
||||
* Prefer for command detection; RawBody is treated as legacy alias.
|
||||
*/
|
||||
CommandBody?: string;
|
||||
CommandArgs?: CommandArgs;
|
||||
From?: string;
|
||||
To?: string;
|
||||
SessionKey?: string;
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
import { ChannelType, Command, type CommandInteraction, type CommandOptions } from "@buape/carbon";
|
||||
import { ApplicationCommandOptionType } from "discord-api-types/v10";
|
||||
import {
|
||||
Button,
|
||||
ChannelType,
|
||||
Command,
|
||||
Row,
|
||||
type AutocompleteInteraction,
|
||||
type ButtonInteraction,
|
||||
type CommandInteraction,
|
||||
type CommandOptions,
|
||||
type ComponentData,
|
||||
} from "@buape/carbon";
|
||||
import { ApplicationCommandOptionType, ButtonStyle } from "discord-api-types/v10";
|
||||
|
||||
import { resolveEffectiveMessagesConfig, resolveHumanDelayConfig } from "../../agents/identity.js";
|
||||
import { resolveTextChunkLimit } from "../../auto-reply/chunk.js";
|
||||
import { buildCommandText } from "../../auto-reply/commands-registry.js";
|
||||
import {
|
||||
buildCommandTextFromArgs,
|
||||
findCommandByNativeName,
|
||||
listChatCommands,
|
||||
parseCommandArgs,
|
||||
resolveCommandArgChoices,
|
||||
resolveCommandArgMenu,
|
||||
serializeCommandArgs,
|
||||
} from "../../auto-reply/commands-registry.js";
|
||||
import type {
|
||||
ChatCommandDefinition,
|
||||
CommandArgDefinition,
|
||||
CommandArgValues,
|
||||
CommandArgs,
|
||||
NativeCommandSpec,
|
||||
} from "../../auto-reply/commands-registry.js";
|
||||
import { dispatchReplyWithDispatcher } from "../../auto-reply/reply/provider-dispatcher.js";
|
||||
import type { ReplyPayload } from "../../auto-reply/types.js";
|
||||
import type { ClawdbotConfig, loadConfig } from "../../config/config.js";
|
||||
@@ -28,12 +53,261 @@ import { formatDiscordUserTag } from "./format.js";
|
||||
|
||||
type DiscordConfig = NonNullable<ClawdbotConfig["channels"]>["discord"];
|
||||
|
||||
export function createDiscordNativeCommand(params: {
|
||||
command: {
|
||||
name: string;
|
||||
description: string;
|
||||
acceptsArgs: boolean;
|
||||
function buildDiscordCommandOptions(params: {
|
||||
command: ChatCommandDefinition;
|
||||
cfg: ReturnType<typeof loadConfig>;
|
||||
}): CommandOptions | undefined {
|
||||
const { command, cfg } = params;
|
||||
const args = command.args;
|
||||
if (!args || args.length === 0) return undefined;
|
||||
return args.map((arg) => {
|
||||
const required = arg.required ?? false;
|
||||
if (arg.type === "number") {
|
||||
return {
|
||||
name: arg.name,
|
||||
description: arg.description,
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required,
|
||||
};
|
||||
}
|
||||
if (arg.type === "boolean") {
|
||||
return {
|
||||
name: arg.name,
|
||||
description: arg.description,
|
||||
type: ApplicationCommandOptionType.Boolean,
|
||||
required,
|
||||
};
|
||||
}
|
||||
const resolvedChoices = resolveCommandArgChoices({ command, arg, cfg });
|
||||
const shouldAutocomplete =
|
||||
resolvedChoices.length > 0 &&
|
||||
(typeof arg.choices === "function" || resolvedChoices.length > 25);
|
||||
const autocomplete = shouldAutocomplete
|
||||
? async (interaction: AutocompleteInteraction) => {
|
||||
const focused = interaction.options.getFocused();
|
||||
const focusValue =
|
||||
typeof focused?.value === "string" ? focused.value.trim().toLowerCase() : "";
|
||||
const choices = resolveCommandArgChoices({ command, arg, cfg });
|
||||
const filtered = focusValue
|
||||
? choices.filter((choice) => choice.toLowerCase().includes(focusValue))
|
||||
: choices;
|
||||
await interaction.respond(
|
||||
filtered.slice(0, 25).map((choice) => ({ name: choice, value: choice })),
|
||||
);
|
||||
}
|
||||
: undefined;
|
||||
const choices =
|
||||
resolvedChoices.length > 0 && !autocomplete
|
||||
? resolvedChoices.slice(0, 25).map((choice) => ({ name: choice, value: choice }))
|
||||
: undefined;
|
||||
return {
|
||||
name: arg.name,
|
||||
description: arg.description,
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required,
|
||||
choices,
|
||||
autocomplete,
|
||||
};
|
||||
}) satisfies CommandOptions;
|
||||
}
|
||||
|
||||
function readDiscordCommandArgs(
|
||||
interaction: CommandInteraction,
|
||||
definitions?: CommandArgDefinition[],
|
||||
): CommandArgs | undefined {
|
||||
if (!definitions || definitions.length === 0) return undefined;
|
||||
const values: CommandArgValues = {};
|
||||
for (const definition of definitions) {
|
||||
let value: unknown;
|
||||
if (definition.type === "number") {
|
||||
value = interaction.options.getNumber(definition.name);
|
||||
} else if (definition.type === "boolean") {
|
||||
value = interaction.options.getBoolean(definition.name);
|
||||
} else {
|
||||
value = interaction.options.getString(definition.name);
|
||||
}
|
||||
if (value != null) {
|
||||
values[definition.name] = value;
|
||||
}
|
||||
}
|
||||
return Object.keys(values).length > 0 ? { values } : undefined;
|
||||
}
|
||||
|
||||
function chunkItems<T>(items: T[], size: number): T[][] {
|
||||
if (size <= 0) return [items];
|
||||
const rows: T[][] = [];
|
||||
for (let i = 0; i < items.length; i += size) {
|
||||
rows.push(items.slice(i, i + size));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
const DISCORD_COMMAND_ARG_CUSTOM_ID_KEY = "cmdarg";
|
||||
|
||||
function createCommandArgsWithValue(params: { argName: string; value: string }): CommandArgs {
|
||||
const values: CommandArgValues = { [params.argName]: params.value };
|
||||
return { values };
|
||||
}
|
||||
|
||||
function encodeDiscordCommandArgValue(value: string): string {
|
||||
return encodeURIComponent(value);
|
||||
}
|
||||
|
||||
function decodeDiscordCommandArgValue(value: string): string {
|
||||
try {
|
||||
return decodeURIComponent(value);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
function buildDiscordCommandArgCustomId(params: {
|
||||
command: string;
|
||||
arg: string;
|
||||
value: string;
|
||||
userId: string;
|
||||
}): string {
|
||||
return [
|
||||
`${DISCORD_COMMAND_ARG_CUSTOM_ID_KEY}:command=${encodeDiscordCommandArgValue(params.command)}`,
|
||||
`arg=${encodeDiscordCommandArgValue(params.arg)}`,
|
||||
`value=${encodeDiscordCommandArgValue(params.value)}`,
|
||||
`user=${encodeDiscordCommandArgValue(params.userId)}`,
|
||||
].join(";");
|
||||
}
|
||||
|
||||
function parseDiscordCommandArgData(
|
||||
data: ComponentData,
|
||||
): { command: string; arg: string; value: string; userId: string } | null {
|
||||
if (!data || typeof data !== "object") return null;
|
||||
const coerce = (value: unknown) =>
|
||||
typeof value === "string" || typeof value === "number" ? String(value) : "";
|
||||
const rawCommand = coerce(data.command);
|
||||
const rawArg = coerce(data.arg);
|
||||
const rawValue = coerce(data.value);
|
||||
const rawUser = coerce(data.user);
|
||||
if (!rawCommand || !rawArg || !rawValue || !rawUser) return null;
|
||||
return {
|
||||
command: decodeDiscordCommandArgValue(rawCommand),
|
||||
arg: decodeDiscordCommandArgValue(rawArg),
|
||||
value: decodeDiscordCommandArgValue(rawValue),
|
||||
userId: decodeDiscordCommandArgValue(rawUser),
|
||||
};
|
||||
}
|
||||
|
||||
class DiscordCommandArgButton extends Button {
|
||||
label: string;
|
||||
customId: string;
|
||||
style = ButtonStyle.Secondary;
|
||||
private cfg: ReturnType<typeof loadConfig>;
|
||||
private discordConfig: DiscordConfig;
|
||||
private accountId: string;
|
||||
private sessionPrefix: string;
|
||||
|
||||
constructor(params: {
|
||||
label: string;
|
||||
customId: string;
|
||||
cfg: ReturnType<typeof loadConfig>;
|
||||
discordConfig: DiscordConfig;
|
||||
accountId: string;
|
||||
sessionPrefix: string;
|
||||
}) {
|
||||
super();
|
||||
this.label = params.label;
|
||||
this.customId = params.customId;
|
||||
this.cfg = params.cfg;
|
||||
this.discordConfig = params.discordConfig;
|
||||
this.accountId = params.accountId;
|
||||
this.sessionPrefix = params.sessionPrefix;
|
||||
}
|
||||
|
||||
async run(interaction: ButtonInteraction, data: ComponentData) {
|
||||
const parsed = parseDiscordCommandArgData(data);
|
||||
if (!parsed) {
|
||||
await interaction.update({
|
||||
content: "Sorry, that selection is no longer available.",
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (interaction.user?.id && interaction.user.id !== parsed.userId) {
|
||||
await interaction.acknowledge();
|
||||
return;
|
||||
}
|
||||
const commandDefinition =
|
||||
findCommandByNativeName(parsed.command) ??
|
||||
listChatCommands().find((entry) => entry.key === parsed.command);
|
||||
if (!commandDefinition) {
|
||||
await interaction.update({
|
||||
content: "Sorry, that command is no longer available.",
|
||||
components: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
await interaction.update({
|
||||
content: `✅ Selected ${parsed.value}.`,
|
||||
components: [],
|
||||
});
|
||||
const commandArgs = createCommandArgsWithValue({
|
||||
argName: parsed.arg,
|
||||
value: parsed.value,
|
||||
});
|
||||
const commandArgsWithRaw: CommandArgs = {
|
||||
...commandArgs,
|
||||
raw: serializeCommandArgs(commandDefinition, commandArgs),
|
||||
};
|
||||
const prompt = buildCommandTextFromArgs(commandDefinition, commandArgsWithRaw);
|
||||
await dispatchDiscordCommandInteraction({
|
||||
interaction,
|
||||
prompt,
|
||||
command: commandDefinition,
|
||||
commandArgs: commandArgsWithRaw,
|
||||
cfg: this.cfg,
|
||||
discordConfig: this.discordConfig,
|
||||
accountId: this.accountId,
|
||||
sessionPrefix: this.sessionPrefix,
|
||||
preferFollowUp: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function buildDiscordCommandArgMenu(params: {
|
||||
command: ChatCommandDefinition;
|
||||
menu: { arg: CommandArgDefinition; choices: string[]; title?: string };
|
||||
interaction: CommandInteraction;
|
||||
cfg: ReturnType<typeof loadConfig>;
|
||||
discordConfig: DiscordConfig;
|
||||
accountId: string;
|
||||
sessionPrefix: string;
|
||||
}): { content: string; components: Row<Button>[] } {
|
||||
const { command, menu, interaction } = params;
|
||||
const commandLabel = command.nativeName ?? command.key;
|
||||
const userId = interaction.user?.id ?? "";
|
||||
const rows = chunkItems(menu.choices, 4).map((choices) => {
|
||||
const buttons = choices.map(
|
||||
(choice) =>
|
||||
new DiscordCommandArgButton({
|
||||
label: choice,
|
||||
customId: buildDiscordCommandArgCustomId({
|
||||
command: commandLabel,
|
||||
arg: menu.arg.name,
|
||||
value: choice,
|
||||
userId,
|
||||
}),
|
||||
cfg: params.cfg,
|
||||
discordConfig: params.discordConfig,
|
||||
accountId: params.accountId,
|
||||
sessionPrefix: params.sessionPrefix,
|
||||
}),
|
||||
);
|
||||
return new Row(buttons);
|
||||
});
|
||||
const content =
|
||||
menu.title ?? `Choose ${menu.arg.description || menu.arg.name} for /${commandLabel}.`;
|
||||
return { content, components: rows };
|
||||
}
|
||||
|
||||
export function createDiscordNativeCommand(params: {
|
||||
command: NativeCommandSpec;
|
||||
cfg: ReturnType<typeof loadConfig>;
|
||||
discordConfig: DiscordConfig;
|
||||
accountId: string;
|
||||
@@ -41,12 +315,26 @@ export function createDiscordNativeCommand(params: {
|
||||
ephemeralDefault: boolean;
|
||||
}) {
|
||||
const { command, cfg, discordConfig, accountId, sessionPrefix, ephemeralDefault } = params;
|
||||
return new (class extends Command {
|
||||
name = command.name;
|
||||
description = command.description;
|
||||
defer = true;
|
||||
ephemeral = ephemeralDefault;
|
||||
options = command.acceptsArgs
|
||||
const commandDefinition =
|
||||
findCommandByNativeName(command.name) ??
|
||||
({
|
||||
key: command.name,
|
||||
nativeName: command.name,
|
||||
description: command.description,
|
||||
textAliases: [],
|
||||
acceptsArgs: command.acceptsArgs,
|
||||
args: command.args,
|
||||
argsParsing: "none",
|
||||
scope: "native",
|
||||
} satisfies ChatCommandDefinition);
|
||||
const argDefinitions = commandDefinition.args ?? command.args;
|
||||
const commandOptions = buildDiscordCommandOptions({
|
||||
command: commandDefinition,
|
||||
cfg,
|
||||
});
|
||||
const options = commandOptions
|
||||
? (commandOptions satisfies CommandOptions)
|
||||
: command.acceptsArgs
|
||||
? ([
|
||||
{
|
||||
name: "input",
|
||||
@@ -56,219 +344,301 @@ export function createDiscordNativeCommand(params: {
|
||||
},
|
||||
] satisfies CommandOptions)
|
||||
: undefined;
|
||||
return new (class extends Command {
|
||||
name = command.name;
|
||||
description = command.description;
|
||||
defer = true;
|
||||
ephemeral = ephemeralDefault;
|
||||
options = options;
|
||||
|
||||
async run(interaction: CommandInteraction) {
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
const user = interaction.user;
|
||||
if (!user) return;
|
||||
const channel = interaction.channel;
|
||||
const channelType = channel?.type;
|
||||
const isDirectMessage = channelType === ChannelType.DM;
|
||||
const isGroupDm = channelType === ChannelType.GroupDM;
|
||||
const channelName = channel && "name" in channel ? (channel.name as string) : undefined;
|
||||
const channelSlug = channelName ? normalizeDiscordSlug(channelName) : "";
|
||||
const prompt = buildCommandText(
|
||||
this.name,
|
||||
command.acceptsArgs ? interaction.options.getString("input") : undefined,
|
||||
);
|
||||
const guildInfo = resolveDiscordGuildEntry({
|
||||
guild: interaction.guild ?? undefined,
|
||||
guildEntries: discordConfig?.guilds,
|
||||
});
|
||||
const channelConfig = interaction.guild
|
||||
? resolveDiscordChannelConfig({
|
||||
guildInfo,
|
||||
channelId: channel?.id ?? "",
|
||||
channelName,
|
||||
channelSlug,
|
||||
})
|
||||
: null;
|
||||
if (channelConfig?.enabled === false) {
|
||||
await interaction.reply({
|
||||
content: "This channel is disabled.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (interaction.guild && channelConfig?.allowed === false) {
|
||||
await interaction.reply({
|
||||
content: "This channel is not allowed.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (useAccessGroups && interaction.guild) {
|
||||
const channelAllowlistConfigured =
|
||||
Boolean(guildInfo?.channels) && Object.keys(guildInfo?.channels ?? {}).length > 0;
|
||||
const channelAllowed = channelConfig?.allowed !== false;
|
||||
const allowByPolicy = isDiscordGroupAllowedByPolicy({
|
||||
groupPolicy: discordConfig?.groupPolicy ?? "open",
|
||||
channelAllowlistConfigured,
|
||||
channelAllowed,
|
||||
});
|
||||
if (!allowByPolicy) {
|
||||
await interaction.reply({
|
||||
content: "This channel is not allowed.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
const dmEnabled = discordConfig?.dm?.enabled ?? true;
|
||||
const dmPolicy = discordConfig?.dm?.policy ?? "pairing";
|
||||
let commandAuthorized = true;
|
||||
if (isDirectMessage) {
|
||||
if (!dmEnabled || dmPolicy === "disabled") {
|
||||
await interaction.reply({ content: "Discord DMs are disabled." });
|
||||
return;
|
||||
}
|
||||
if (dmPolicy !== "open") {
|
||||
const storeAllowFrom = await readChannelAllowFromStore("discord").catch(() => []);
|
||||
const effectiveAllowFrom = [...(discordConfig?.dm?.allowFrom ?? []), ...storeAllowFrom];
|
||||
const allowList = normalizeDiscordAllowList(effectiveAllowFrom, ["discord:", "user:"]);
|
||||
const permitted = allowList
|
||||
? allowListMatches(allowList, {
|
||||
id: user.id,
|
||||
name: user.username,
|
||||
tag: formatDiscordUserTag(user),
|
||||
})
|
||||
: false;
|
||||
if (!permitted) {
|
||||
commandAuthorized = false;
|
||||
if (dmPolicy === "pairing") {
|
||||
const { code, created } = await upsertChannelPairingRequest({
|
||||
channel: "discord",
|
||||
id: user.id,
|
||||
meta: {
|
||||
tag: formatDiscordUserTag(user),
|
||||
name: user.username ?? undefined,
|
||||
},
|
||||
});
|
||||
if (created) {
|
||||
await interaction.reply({
|
||||
content: buildPairingReply({
|
||||
channel: "discord",
|
||||
idLine: `Your Discord user id: ${user.id}`,
|
||||
code,
|
||||
}),
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await interaction.reply({
|
||||
content: "You are not authorized to use this command.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
commandAuthorized = true;
|
||||
}
|
||||
}
|
||||
if (!isDirectMessage) {
|
||||
const channelUsers = channelConfig?.users ?? guildInfo?.users;
|
||||
if (Array.isArray(channelUsers) && channelUsers.length > 0) {
|
||||
const userOk = resolveDiscordUserAllowed({
|
||||
allowList: channelUsers,
|
||||
userId: user.id,
|
||||
userName: user.username,
|
||||
userTag: formatDiscordUserTag(user),
|
||||
});
|
||||
if (!userOk) {
|
||||
await interaction.reply({
|
||||
content: "You are not authorized to use this command.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isGroupDm && discordConfig?.dm?.groupEnabled === false) {
|
||||
await interaction.reply({ content: "Discord group DMs are disabled." });
|
||||
return;
|
||||
}
|
||||
|
||||
const isGuild = Boolean(interaction.guild);
|
||||
const channelId = channel?.id ?? "unknown";
|
||||
const interactionId = interaction.rawData.id;
|
||||
const route = resolveAgentRoute({
|
||||
const commandArgs = argDefinitions?.length
|
||||
? readDiscordCommandArgs(interaction, argDefinitions)
|
||||
: command.acceptsArgs
|
||||
? parseCommandArgs(commandDefinition, interaction.options.getString("input") ?? "")
|
||||
: undefined;
|
||||
const commandArgsWithRaw = commandArgs
|
||||
? ({
|
||||
...commandArgs,
|
||||
raw: serializeCommandArgs(commandDefinition, commandArgs) ?? commandArgs.raw,
|
||||
} satisfies CommandArgs)
|
||||
: undefined;
|
||||
const prompt = buildCommandTextFromArgs(commandDefinition, commandArgsWithRaw);
|
||||
await dispatchDiscordCommandInteraction({
|
||||
interaction,
|
||||
prompt,
|
||||
command: commandDefinition,
|
||||
commandArgs: commandArgsWithRaw,
|
||||
cfg,
|
||||
channel: "discord",
|
||||
discordConfig,
|
||||
accountId,
|
||||
guildId: interaction.guild?.id ?? undefined,
|
||||
peer: {
|
||||
kind: isDirectMessage ? "dm" : isGroupDm ? "group" : "channel",
|
||||
id: isDirectMessage ? user.id : channelId,
|
||||
},
|
||||
});
|
||||
const ctxPayload = {
|
||||
Body: prompt,
|
||||
CommandBody: prompt,
|
||||
From: isDirectMessage ? `discord:${user.id}` : `group:${channelId}`,
|
||||
To: `slash:${user.id}`,
|
||||
SessionKey: `agent:${route.agentId}:${sessionPrefix}:${user.id}`,
|
||||
CommandTargetSessionKey: route.sessionKey,
|
||||
AccountId: route.accountId,
|
||||
ChatType: isDirectMessage ? "direct" : "group",
|
||||
GroupSubject: isGuild ? interaction.guild?.name : undefined,
|
||||
GroupSystemPrompt: isGuild
|
||||
? (() => {
|
||||
const channelTopic =
|
||||
channel && "topic" in channel ? (channel.topic ?? undefined) : undefined;
|
||||
const channelDescription = channelTopic?.trim();
|
||||
const systemPromptParts = [
|
||||
channelDescription ? `Channel topic: ${channelDescription}` : null,
|
||||
channelConfig?.systemPrompt?.trim() || null,
|
||||
].filter((entry): entry is string => Boolean(entry));
|
||||
return systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : undefined;
|
||||
})()
|
||||
: undefined,
|
||||
SenderName: user.globalName ?? user.username,
|
||||
SenderId: user.id,
|
||||
SenderUsername: user.username,
|
||||
SenderTag: formatDiscordUserTag(user),
|
||||
Provider: "discord" as const,
|
||||
Surface: "discord" as const,
|
||||
WasMentioned: true,
|
||||
MessageSid: interactionId,
|
||||
Timestamp: Date.now(),
|
||||
CommandAuthorized: commandAuthorized,
|
||||
CommandSource: "native" as const,
|
||||
};
|
||||
|
||||
let didReply = false;
|
||||
await dispatchReplyWithDispatcher({
|
||||
ctx: ctxPayload,
|
||||
cfg,
|
||||
dispatcherOptions: {
|
||||
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId).responsePrefix,
|
||||
humanDelay: resolveHumanDelayConfig(cfg, route.agentId),
|
||||
deliver: async (payload) => {
|
||||
await deliverDiscordInteractionReply({
|
||||
interaction,
|
||||
payload,
|
||||
textLimit: resolveTextChunkLimit(cfg, "discord", accountId, {
|
||||
fallbackLimit: 2000,
|
||||
}),
|
||||
maxLinesPerMessage: discordConfig?.maxLinesPerMessage,
|
||||
preferFollowUp: didReply,
|
||||
});
|
||||
didReply = true;
|
||||
},
|
||||
onError: (err, info) => {
|
||||
console.error(`discord slash ${info.kind} reply failed`, err);
|
||||
},
|
||||
},
|
||||
replyOptions: {
|
||||
skillFilter: channelConfig?.skills,
|
||||
disableBlockStreaming:
|
||||
typeof discordConfig?.blockStreaming === "boolean"
|
||||
? !discordConfig.blockStreaming
|
||||
: undefined,
|
||||
},
|
||||
sessionPrefix,
|
||||
preferFollowUp: false,
|
||||
});
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
async function dispatchDiscordCommandInteraction(params: {
|
||||
interaction: CommandInteraction | ButtonInteraction;
|
||||
prompt: string;
|
||||
command: ChatCommandDefinition;
|
||||
commandArgs?: CommandArgs;
|
||||
cfg: ReturnType<typeof loadConfig>;
|
||||
discordConfig: DiscordConfig;
|
||||
accountId: string;
|
||||
sessionPrefix: string;
|
||||
preferFollowUp: boolean;
|
||||
}) {
|
||||
const {
|
||||
interaction,
|
||||
prompt,
|
||||
command,
|
||||
commandArgs,
|
||||
cfg,
|
||||
discordConfig,
|
||||
accountId,
|
||||
sessionPrefix,
|
||||
preferFollowUp,
|
||||
} = params;
|
||||
const respond = async (content: string, options?: { ephemeral?: boolean }) => {
|
||||
const payload = {
|
||||
content,
|
||||
...(options?.ephemeral !== undefined ? { ephemeral: options.ephemeral } : {}),
|
||||
};
|
||||
if (preferFollowUp) {
|
||||
await interaction.followUp(payload);
|
||||
return;
|
||||
}
|
||||
await interaction.reply(payload);
|
||||
};
|
||||
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
const user = interaction.user;
|
||||
if (!user) return;
|
||||
const channel = interaction.channel;
|
||||
const channelType = channel?.type;
|
||||
const isDirectMessage = channelType === ChannelType.DM;
|
||||
const isGroupDm = channelType === ChannelType.GroupDM;
|
||||
const channelName = channel && "name" in channel ? (channel.name as string) : undefined;
|
||||
const channelSlug = channelName ? normalizeDiscordSlug(channelName) : "";
|
||||
const guildInfo = resolveDiscordGuildEntry({
|
||||
guild: interaction.guild ?? undefined,
|
||||
guildEntries: discordConfig?.guilds,
|
||||
});
|
||||
const channelConfig = interaction.guild
|
||||
? resolveDiscordChannelConfig({
|
||||
guildInfo,
|
||||
channelId: channel?.id ?? "",
|
||||
channelName,
|
||||
channelSlug,
|
||||
})
|
||||
: null;
|
||||
if (channelConfig?.enabled === false) {
|
||||
await respond("This channel is disabled.");
|
||||
return;
|
||||
}
|
||||
if (interaction.guild && channelConfig?.allowed === false) {
|
||||
await respond("This channel is not allowed.");
|
||||
return;
|
||||
}
|
||||
if (useAccessGroups && interaction.guild) {
|
||||
const channelAllowlistConfigured =
|
||||
Boolean(guildInfo?.channels) && Object.keys(guildInfo?.channels ?? {}).length > 0;
|
||||
const channelAllowed = channelConfig?.allowed !== false;
|
||||
const allowByPolicy = isDiscordGroupAllowedByPolicy({
|
||||
groupPolicy: discordConfig?.groupPolicy ?? "open",
|
||||
channelAllowlistConfigured,
|
||||
channelAllowed,
|
||||
});
|
||||
if (!allowByPolicy) {
|
||||
await respond("This channel is not allowed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const dmEnabled = discordConfig?.dm?.enabled ?? true;
|
||||
const dmPolicy = discordConfig?.dm?.policy ?? "pairing";
|
||||
let commandAuthorized = true;
|
||||
if (isDirectMessage) {
|
||||
if (!dmEnabled || dmPolicy === "disabled") {
|
||||
await respond("Discord DMs are disabled.");
|
||||
return;
|
||||
}
|
||||
if (dmPolicy !== "open") {
|
||||
const storeAllowFrom = await readChannelAllowFromStore("discord").catch(() => []);
|
||||
const effectiveAllowFrom = [...(discordConfig?.dm?.allowFrom ?? []), ...storeAllowFrom];
|
||||
const allowList = normalizeDiscordAllowList(effectiveAllowFrom, ["discord:", "user:"]);
|
||||
const permitted = allowList
|
||||
? allowListMatches(allowList, {
|
||||
id: user.id,
|
||||
name: user.username,
|
||||
tag: formatDiscordUserTag(user),
|
||||
})
|
||||
: false;
|
||||
if (!permitted) {
|
||||
commandAuthorized = false;
|
||||
if (dmPolicy === "pairing") {
|
||||
const { code, created } = await upsertChannelPairingRequest({
|
||||
channel: "discord",
|
||||
id: user.id,
|
||||
meta: {
|
||||
tag: formatDiscordUserTag(user),
|
||||
name: user.username ?? undefined,
|
||||
},
|
||||
});
|
||||
if (created) {
|
||||
await respond(
|
||||
buildPairingReply({
|
||||
channel: "discord",
|
||||
idLine: `Your Discord user id: ${user.id}`,
|
||||
code,
|
||||
}),
|
||||
{ ephemeral: true },
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await respond("You are not authorized to use this command.", { ephemeral: true });
|
||||
}
|
||||
return;
|
||||
}
|
||||
commandAuthorized = true;
|
||||
}
|
||||
}
|
||||
if (!isDirectMessage) {
|
||||
const channelUsers = channelConfig?.users ?? guildInfo?.users;
|
||||
if (Array.isArray(channelUsers) && channelUsers.length > 0) {
|
||||
const userOk = resolveDiscordUserAllowed({
|
||||
allowList: channelUsers,
|
||||
userId: user.id,
|
||||
userName: user.username,
|
||||
userTag: formatDiscordUserTag(user),
|
||||
});
|
||||
if (!userOk) {
|
||||
await respond("You are not authorized to use this command.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isGroupDm && discordConfig?.dm?.groupEnabled === false) {
|
||||
await respond("Discord group DMs are disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
const menu = resolveCommandArgMenu({
|
||||
command,
|
||||
args: commandArgs,
|
||||
cfg,
|
||||
});
|
||||
if (menu) {
|
||||
const menuPayload = buildDiscordCommandArgMenu({
|
||||
command,
|
||||
menu,
|
||||
interaction: interaction as CommandInteraction,
|
||||
cfg,
|
||||
discordConfig,
|
||||
accountId,
|
||||
sessionPrefix,
|
||||
});
|
||||
if (preferFollowUp) {
|
||||
await interaction.followUp({
|
||||
content: menuPayload.content,
|
||||
components: menuPayload.components,
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
await interaction.reply({
|
||||
content: menuPayload.content,
|
||||
components: menuPayload.components,
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const isGuild = Boolean(interaction.guild);
|
||||
const channelId = channel?.id ?? "unknown";
|
||||
const interactionId = interaction.rawData.id;
|
||||
const route = resolveAgentRoute({
|
||||
cfg,
|
||||
channel: "discord",
|
||||
accountId,
|
||||
guildId: interaction.guild?.id ?? undefined,
|
||||
peer: {
|
||||
kind: isDirectMessage ? "dm" : isGroupDm ? "group" : "channel",
|
||||
id: isDirectMessage ? user.id : channelId,
|
||||
},
|
||||
});
|
||||
const ctxPayload = {
|
||||
Body: prompt,
|
||||
CommandBody: prompt,
|
||||
CommandArgs: commandArgs,
|
||||
From: isDirectMessage ? `discord:${user.id}` : `group:${channelId}`,
|
||||
To: `slash:${user.id}`,
|
||||
SessionKey: `agent:${route.agentId}:${sessionPrefix}:${user.id}`,
|
||||
CommandTargetSessionKey: route.sessionKey,
|
||||
AccountId: route.accountId,
|
||||
ChatType: isDirectMessage ? "direct" : "group",
|
||||
GroupSubject: isGuild ? interaction.guild?.name : undefined,
|
||||
GroupSystemPrompt: isGuild
|
||||
? (() => {
|
||||
const channelTopic =
|
||||
channel && "topic" in channel ? (channel.topic ?? undefined) : undefined;
|
||||
const channelDescription = channelTopic?.trim();
|
||||
const systemPromptParts = [
|
||||
channelDescription ? `Channel topic: ${channelDescription}` : null,
|
||||
channelConfig?.systemPrompt?.trim() || null,
|
||||
].filter((entry): entry is string => Boolean(entry));
|
||||
return systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : undefined;
|
||||
})()
|
||||
: undefined,
|
||||
SenderName: user.globalName ?? user.username,
|
||||
SenderId: user.id,
|
||||
SenderUsername: user.username,
|
||||
SenderTag: formatDiscordUserTag(user),
|
||||
Provider: "discord" as const,
|
||||
Surface: "discord" as const,
|
||||
WasMentioned: true,
|
||||
MessageSid: interactionId,
|
||||
Timestamp: Date.now(),
|
||||
CommandAuthorized: commandAuthorized,
|
||||
CommandSource: "native" as const,
|
||||
};
|
||||
|
||||
let didReply = false;
|
||||
await dispatchReplyWithDispatcher({
|
||||
ctx: ctxPayload,
|
||||
cfg,
|
||||
dispatcherOptions: {
|
||||
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId).responsePrefix,
|
||||
humanDelay: resolveHumanDelayConfig(cfg, route.agentId),
|
||||
deliver: async (payload) => {
|
||||
await deliverDiscordInteractionReply({
|
||||
interaction,
|
||||
payload,
|
||||
textLimit: resolveTextChunkLimit(cfg, "discord", accountId, {
|
||||
fallbackLimit: 2000,
|
||||
}),
|
||||
maxLinesPerMessage: discordConfig?.maxLinesPerMessage,
|
||||
preferFollowUp: preferFollowUp || didReply,
|
||||
});
|
||||
didReply = true;
|
||||
},
|
||||
onError: (err, info) => {
|
||||
console.error(`discord slash ${info.kind} reply failed`, err);
|
||||
},
|
||||
},
|
||||
replyOptions: {
|
||||
skillFilter: channelConfig?.skills,
|
||||
disableBlockStreaming:
|
||||
typeof discordConfig?.blockStreaming === "boolean"
|
||||
? !discordConfig.blockStreaming
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function deliverDiscordInteractionReply(params: {
|
||||
interaction: CommandInteraction;
|
||||
interaction: CommandInteraction | ButtonInteraction;
|
||||
payload: ReplyPayload;
|
||||
textLimit: number;
|
||||
maxLinesPerMessage?: number;
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import type { SlackCommandMiddlewareArgs } from "@slack/bolt";
|
||||
import type { SlackActionMiddlewareArgs, SlackCommandMiddlewareArgs } from "@slack/bolt";
|
||||
import type { Block, KnownBlock } from "@slack/types";
|
||||
import type { ChatCommandDefinition, CommandArgs } from "../../auto-reply/commands-registry.js";
|
||||
import { resolveEffectiveMessagesConfig } from "../../agents/identity.js";
|
||||
import {
|
||||
buildCommandText,
|
||||
buildCommandTextFromArgs,
|
||||
findCommandByNativeName,
|
||||
listNativeCommandSpecsForConfig,
|
||||
parseCommandArgs,
|
||||
resolveCommandArgMenu,
|
||||
} from "../../auto-reply/commands-registry.js";
|
||||
import { dispatchReplyWithDispatcher } from "../../auto-reply/reply/provider-dispatcher.js";
|
||||
import { resolveNativeCommandsEnabled } from "../../config/commands.js";
|
||||
@@ -28,6 +33,82 @@ import type { SlackMonitorContext } from "./context.js";
|
||||
import { isSlackRoomAllowedByPolicy } from "./policy.js";
|
||||
import { deliverSlackSlashReplies } from "./replies.js";
|
||||
|
||||
const SLACK_COMMAND_ARG_ACTION_ID = "clawdbot_cmdarg";
|
||||
const SLACK_COMMAND_ARG_VALUE_PREFIX = "cmdarg";
|
||||
|
||||
function chunkItems<T>(items: T[], size: number): T[][] {
|
||||
if (size <= 0) return [items];
|
||||
const rows: T[][] = [];
|
||||
for (let i = 0; i < items.length; i += size) {
|
||||
rows.push(items.slice(i, i + size));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
function encodeSlackCommandArgValue(parts: {
|
||||
command: string;
|
||||
arg: string;
|
||||
value: string;
|
||||
userId: string;
|
||||
}) {
|
||||
return [
|
||||
SLACK_COMMAND_ARG_VALUE_PREFIX,
|
||||
encodeURIComponent(parts.command),
|
||||
encodeURIComponent(parts.arg),
|
||||
encodeURIComponent(parts.value),
|
||||
encodeURIComponent(parts.userId),
|
||||
].join("|");
|
||||
}
|
||||
|
||||
function parseSlackCommandArgValue(raw?: string | null): {
|
||||
command: string;
|
||||
arg: string;
|
||||
value: string;
|
||||
userId: string;
|
||||
} | null {
|
||||
if (!raw) return null;
|
||||
const parts = raw.split("|");
|
||||
if (parts.length < 5 || parts[0] !== SLACK_COMMAND_ARG_VALUE_PREFIX) return null;
|
||||
const [, command, arg, value, userId] = parts;
|
||||
if (!command || !arg || !value || !userId) return null;
|
||||
return {
|
||||
command: decodeURIComponent(command),
|
||||
arg: decodeURIComponent(arg),
|
||||
value: decodeURIComponent(value),
|
||||
userId: decodeURIComponent(userId),
|
||||
};
|
||||
}
|
||||
|
||||
function buildSlackCommandArgMenuBlocks(params: {
|
||||
title: string;
|
||||
command: string;
|
||||
arg: string;
|
||||
choices: string[];
|
||||
userId: string;
|
||||
}) {
|
||||
const rows = chunkItems(params.choices, 5).map((choices) => ({
|
||||
type: "actions",
|
||||
elements: choices.map((choice) => ({
|
||||
type: "button",
|
||||
action_id: SLACK_COMMAND_ARG_ACTION_ID,
|
||||
text: { type: "plain_text", text: choice },
|
||||
value: encodeSlackCommandArgValue({
|
||||
command: params.command,
|
||||
arg: params.arg,
|
||||
value: choice,
|
||||
userId: params.userId,
|
||||
}),
|
||||
})),
|
||||
}));
|
||||
return [
|
||||
{
|
||||
type: "section",
|
||||
text: { type: "mrkdwn", text: params.title },
|
||||
},
|
||||
...rows,
|
||||
];
|
||||
}
|
||||
|
||||
export function registerSlackMonitorSlashCommands(params: {
|
||||
ctx: SlackMonitorContext;
|
||||
account: ResolvedSlackAccount;
|
||||
@@ -45,8 +126,10 @@ export function registerSlackMonitorSlashCommands(params: {
|
||||
ack: SlackCommandMiddlewareArgs["ack"];
|
||||
respond: SlackCommandMiddlewareArgs["respond"];
|
||||
prompt: string;
|
||||
commandArgs?: CommandArgs;
|
||||
commandDefinition?: ChatCommandDefinition;
|
||||
}) => {
|
||||
const { command, ack, respond, prompt } = p;
|
||||
const { command, ack, respond, prompt, commandArgs, commandDefinition } = p;
|
||||
try {
|
||||
if (!prompt.trim()) {
|
||||
await ack({
|
||||
@@ -183,6 +266,32 @@ export function registerSlackMonitorSlashCommands(params: {
|
||||
return;
|
||||
}
|
||||
|
||||
if (commandDefinition) {
|
||||
const menu = resolveCommandArgMenu({
|
||||
command: commandDefinition,
|
||||
args: commandArgs,
|
||||
cfg,
|
||||
});
|
||||
if (menu) {
|
||||
const commandLabel = commandDefinition.nativeName ?? commandDefinition.key;
|
||||
const title =
|
||||
menu.title ?? `Choose ${menu.arg.description || menu.arg.name} for /${commandLabel}.`;
|
||||
const blocks = buildSlackCommandArgMenuBlocks({
|
||||
title,
|
||||
command: commandLabel,
|
||||
arg: menu.arg.name,
|
||||
choices: menu.choices,
|
||||
userId: command.user_id,
|
||||
});
|
||||
await respond({
|
||||
text: title,
|
||||
blocks,
|
||||
response_type: "ephemeral",
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const channelName = channelInfo?.name;
|
||||
const roomLabel = channelName ? `#${channelName}` : `#${command.channel_id}`;
|
||||
const isRoomish = isRoom || isGroupDm;
|
||||
@@ -211,6 +320,7 @@ export function registerSlackMonitorSlashCommands(params: {
|
||||
|
||||
const ctxPayload = {
|
||||
Body: prompt,
|
||||
CommandArgs: commandArgs,
|
||||
From: isDirectMessage
|
||||
? `slack:${command.user_id}`
|
||||
: isRoom
|
||||
@@ -283,8 +393,26 @@ export function registerSlackMonitorSlashCommands(params: {
|
||||
ctx.app.command(
|
||||
`/${command.name}`,
|
||||
async ({ command: cmd, ack, respond }: SlackCommandMiddlewareArgs) => {
|
||||
const prompt = buildCommandText(command.name, cmd.text);
|
||||
await handleSlashCommand({ command: cmd, ack, respond, prompt });
|
||||
const commandDefinition = findCommandByNativeName(command.name);
|
||||
const rawText = cmd.text?.trim() ?? "";
|
||||
const commandArgs = commandDefinition
|
||||
? parseCommandArgs(commandDefinition, rawText)
|
||||
: rawText
|
||||
? ({ raw: rawText } satisfies CommandArgs)
|
||||
: undefined;
|
||||
const prompt = commandDefinition
|
||||
? buildCommandTextFromArgs(commandDefinition, commandArgs)
|
||||
: rawText
|
||||
? `/${command.name} ${rawText}`
|
||||
: `/${command.name}`;
|
||||
await handleSlashCommand({
|
||||
command: cmd,
|
||||
ack,
|
||||
respond,
|
||||
prompt,
|
||||
commandArgs,
|
||||
commandDefinition: commandDefinition ?? undefined,
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -303,4 +431,70 @@ export function registerSlackMonitorSlashCommands(params: {
|
||||
} else {
|
||||
logVerbose("slack: slash commands disabled");
|
||||
}
|
||||
|
||||
ctx.app.action(SLACK_COMMAND_ARG_ACTION_ID, async (args: SlackActionMiddlewareArgs) => {
|
||||
const { ack, body, respond } = args;
|
||||
const action = args.action as { value?: string };
|
||||
await ack();
|
||||
const respondFn =
|
||||
respond ??
|
||||
(async (payload: {
|
||||
text: string;
|
||||
blocks?: (Block | KnownBlock)[];
|
||||
response_type?: string;
|
||||
}) => {
|
||||
if (!body.channel?.id || !body.user?.id) return;
|
||||
await ctx.app.client.chat.postEphemeral({
|
||||
channel: body.channel.id,
|
||||
user: body.user.id,
|
||||
text: payload.text,
|
||||
blocks: payload.blocks,
|
||||
});
|
||||
});
|
||||
const parsed = parseSlackCommandArgValue(action?.value);
|
||||
if (!parsed) {
|
||||
await respondFn({
|
||||
text: "Sorry, that button is no longer valid.",
|
||||
response_type: "ephemeral",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (body.user?.id && parsed.userId !== body.user.id) {
|
||||
await respondFn({
|
||||
text: "That menu is for another user.",
|
||||
response_type: "ephemeral",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const commandDefinition = findCommandByNativeName(parsed.command);
|
||||
const commandArgs: CommandArgs = {
|
||||
values: { [parsed.arg]: parsed.value },
|
||||
};
|
||||
const prompt = commandDefinition
|
||||
? buildCommandTextFromArgs(commandDefinition, commandArgs)
|
||||
: `/${parsed.command} ${parsed.value}`;
|
||||
const user = body.user;
|
||||
const userName =
|
||||
user && "name" in user && user.name
|
||||
? user.name
|
||||
: user && "username" in user && user.username
|
||||
? user.username
|
||||
: (user?.id ?? "");
|
||||
const triggerId = "trigger_id" in body ? body.trigger_id : undefined;
|
||||
const commandPayload = {
|
||||
user_id: user?.id ?? "",
|
||||
user_name: userName,
|
||||
channel_id: body.channel?.id ?? "",
|
||||
channel_name: body.channel?.name ?? body.channel?.id ?? "",
|
||||
trigger_id: triggerId ?? String(Date.now()),
|
||||
} as SlackCommandMiddlewareArgs["command"];
|
||||
await handleSlashCommand({
|
||||
command: commandPayload,
|
||||
ack: async () => {},
|
||||
respond: respondFn as SlackCommandMiddlewareArgs["respond"],
|
||||
prompt,
|
||||
commandArgs,
|
||||
commandDefinition: commandDefinition ?? undefined,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
|
||||
import { resolveEffectiveMessagesConfig } from "../agents/identity.js";
|
||||
import {
|
||||
buildCommandText,
|
||||
buildCommandTextFromArgs,
|
||||
findCommandByNativeName,
|
||||
listNativeCommandSpecsForConfig,
|
||||
parseCommandArgs,
|
||||
resolveCommandArgMenu,
|
||||
} from "../auto-reply/commands-registry.js";
|
||||
import type { CommandArgs } from "../auto-reply/commands-registry.js";
|
||||
import { dispatchReplyWithBufferedBlockDispatcher } from "../auto-reply/reply/provider-dispatcher.js";
|
||||
import { danger, logVerbose } from "../globals.js";
|
||||
import { resolveAgentRoute } from "../routing/resolve-route.js";
|
||||
import { deliverReplies } from "./bot/delivery.js";
|
||||
import { buildInlineKeyboard } from "./send.js";
|
||||
import {
|
||||
buildSenderName,
|
||||
buildTelegramGroupFrom,
|
||||
@@ -159,7 +164,51 @@ export const registerTelegramNativeCommands = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const prompt = buildCommandText(command.name, ctx.match ?? "");
|
||||
const commandDefinition = findCommandByNativeName(command.name);
|
||||
const rawText = ctx.match?.trim() ?? "";
|
||||
const commandArgs = commandDefinition
|
||||
? parseCommandArgs(commandDefinition, rawText)
|
||||
: rawText
|
||||
? ({ raw: rawText } satisfies CommandArgs)
|
||||
: undefined;
|
||||
const prompt = commandDefinition
|
||||
? buildCommandTextFromArgs(commandDefinition, commandArgs)
|
||||
: rawText
|
||||
? `/${command.name} ${rawText}`
|
||||
: `/${command.name}`;
|
||||
const menu = commandDefinition
|
||||
? resolveCommandArgMenu({
|
||||
command: commandDefinition,
|
||||
args: commandArgs,
|
||||
cfg,
|
||||
})
|
||||
: null;
|
||||
if (menu) {
|
||||
const title =
|
||||
menu.title ??
|
||||
`Choose ${menu.arg.description || menu.arg.name} for /${commandDefinition.nativeName ?? commandDefinition.key}.`;
|
||||
const rows: Array<Array<{ text: string; callback_data: string }>> = [];
|
||||
for (let i = 0; i < menu.choices.length; i += 2) {
|
||||
const slice = menu.choices.slice(i, i + 2);
|
||||
rows.push(
|
||||
slice.map((choice) => {
|
||||
const args: CommandArgs = {
|
||||
values: { [menu.arg.name]: choice },
|
||||
};
|
||||
return {
|
||||
text: choice,
|
||||
callback_data: buildCommandTextFromArgs(commandDefinition, args),
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
const replyMarkup = buildInlineKeyboard(rows);
|
||||
await bot.api.sendMessage(chatId, title, {
|
||||
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
||||
...(resolvedThreadId != null ? { message_thread_id: resolvedThreadId } : {}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
const route = resolveAgentRoute({
|
||||
cfg,
|
||||
channel: "telegram",
|
||||
@@ -178,6 +227,7 @@ export const registerTelegramNativeCommands = ({
|
||||
systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : undefined;
|
||||
const ctxPayload = {
|
||||
Body: prompt,
|
||||
CommandArgs: commandArgs,
|
||||
From: isGroup ? buildTelegramGroupFrom(chatId, resolvedThreadId) : `telegram:${chatId}`,
|
||||
To: `slash:${senderId || chatId}`,
|
||||
ChatType: isGroup ? "group" : "direct",
|
||||
|
||||
Reference in New Issue
Block a user