mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:34:31 +00:00
fix: use per-account action config for Discord and Telegram gating
listActions now unions gates across all enabled accounts (matching the Signal pattern), and handleDiscordAction/handleTelegramAction resolve through the per-account merged config instead of reading only the top-level channel actions object. This lets account-specific moderation/sticker/presence overrides take effect at both listing and execution time.
This commit is contained in:
committed by
Peter Steinberger
parent
1faf8e8e9d
commit
a03fec2a3f
@@ -1,5 +1,6 @@
|
|||||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||||
import type { OpenClawConfig } from "../../config/config.js";
|
import type { OpenClawConfig } from "../../config/config.js";
|
||||||
|
import { resolveDiscordAccount } from "../../discord/accounts.js";
|
||||||
import { createActionGate, readStringParam } from "./common.js";
|
import { createActionGate, readStringParam } from "./common.js";
|
||||||
import { handleDiscordGuildAction } from "./discord-actions-guild.js";
|
import { handleDiscordGuildAction } from "./discord-actions-guild.js";
|
||||||
import { handleDiscordMessagingAction } from "./discord-actions-messaging.js";
|
import { handleDiscordMessagingAction } from "./discord-actions-messaging.js";
|
||||||
@@ -59,7 +60,9 @@ export async function handleDiscordAction(
|
|||||||
cfg: OpenClawConfig,
|
cfg: OpenClawConfig,
|
||||||
): Promise<AgentToolResult<unknown>> {
|
): Promise<AgentToolResult<unknown>> {
|
||||||
const action = readStringParam(params, "action", { required: true });
|
const action = readStringParam(params, "action", { required: true });
|
||||||
const isActionEnabled = createActionGate(cfg.channels?.discord?.actions);
|
const accountId = readStringParam(params, "accountId");
|
||||||
|
const account = resolveDiscordAccount({ cfg, accountId });
|
||||||
|
const isActionEnabled = createActionGate(account.config.actions);
|
||||||
|
|
||||||
if (messagingActions.has(action)) {
|
if (messagingActions.has(action)) {
|
||||||
return await handleDiscordMessagingAction(action, params, isActionEnabled);
|
return await handleDiscordMessagingAction(action, params, isActionEnabled);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||||
import type { OpenClawConfig } from "../../config/config.js";
|
import type { OpenClawConfig } from "../../config/config.js";
|
||||||
|
import { resolveTelegramAccount } from "../../telegram/accounts.js";
|
||||||
import type { TelegramButtonStyle, TelegramInlineButtons } from "../../telegram/button-types.js";
|
import type { TelegramButtonStyle, TelegramInlineButtons } from "../../telegram/button-types.js";
|
||||||
import {
|
import {
|
||||||
resolveTelegramInlineButtonsScope,
|
resolveTelegramInlineButtonsScope,
|
||||||
@@ -87,7 +88,8 @@ export async function handleTelegramAction(
|
|||||||
): Promise<AgentToolResult<unknown>> {
|
): Promise<AgentToolResult<unknown>> {
|
||||||
const action = readStringParam(params, "action", { required: true });
|
const action = readStringParam(params, "action", { required: true });
|
||||||
const accountId = readStringParam(params, "accountId");
|
const accountId = readStringParam(params, "accountId");
|
||||||
const isActionEnabled = createActionGate(cfg.channels?.telegram?.actions);
|
const account = resolveTelegramAccount({ cfg, accountId });
|
||||||
|
const isActionEnabled = createActionGate(account.config.actions);
|
||||||
|
|
||||||
if (action === "react") {
|
if (action === "react") {
|
||||||
// Check reaction level first
|
// Check reaction level first
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { DiscordActionConfig } from "../../../config/types.discord.js";
|
||||||
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
|
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
|
||||||
import { createActionGate } from "../../../agents/tools/common.js";
|
import { createActionGate } from "../../../agents/tools/common.js";
|
||||||
import { listEnabledDiscordAccounts } from "../../../discord/accounts.js";
|
import { listEnabledDiscordAccounts } from "../../../discord/accounts.js";
|
||||||
@@ -11,7 +12,10 @@ export const discordMessageActions: ChannelMessageActionAdapter = {
|
|||||||
if (accounts.length === 0) {
|
if (accounts.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const gate = createActionGate(cfg.channels?.discord?.actions);
|
// Union of all accounts' action gates (any account enabling an action makes it available)
|
||||||
|
const gates = accounts.map((a) => createActionGate(a.config.actions));
|
||||||
|
const gate = (key: keyof DiscordActionConfig, defaultValue = true) =>
|
||||||
|
gates.some((g) => g(key, defaultValue));
|
||||||
const actions = new Set<ChannelMessageActionName>(["send"]);
|
const actions = new Set<ChannelMessageActionName>(["send"]);
|
||||||
if (gate("polls")) {
|
if (gate("polls")) {
|
||||||
actions.add("poll");
|
actions.add("poll");
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { TelegramActionConfig } from "../../../config/types.telegram.js";
|
||||||
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
|
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
|
||||||
import {
|
import {
|
||||||
createActionGate,
|
createActionGate,
|
||||||
@@ -46,7 +47,10 @@ export const telegramMessageActions: ChannelMessageActionAdapter = {
|
|||||||
if (accounts.length === 0) {
|
if (accounts.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const gate = createActionGate(cfg.channels?.telegram?.actions);
|
// Union of all accounts' action gates (any account enabling an action makes it available)
|
||||||
|
const gates = accounts.map((a) => createActionGate(a.config.actions));
|
||||||
|
const gate = (key: keyof TelegramActionConfig, defaultValue = true) =>
|
||||||
|
gates.some((g) => g(key, defaultValue));
|
||||||
const actions = new Set<ChannelMessageActionName>(["send"]);
|
const actions = new Set<ChannelMessageActionName>(["send"]);
|
||||||
if (gate("reactions")) {
|
if (gate("reactions")) {
|
||||||
actions.add("react");
|
actions.add("react");
|
||||||
|
|||||||
Reference in New Issue
Block a user