mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 19:32:27 +00:00
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
|
import type { ExecApprovalRequest } from "openclaw/plugin-sdk/infra-runtime";
|
|
import {
|
|
buildExecApprovalPendingReplyPayload,
|
|
resolveExecApprovalCommandDisplay,
|
|
} from "openclaw/plugin-sdk/infra-runtime";
|
|
import { normalizeMessageChannel } from "openclaw/plugin-sdk/routing";
|
|
import { buildTelegramExecApprovalButtons } from "./approval-buttons.js";
|
|
import { isTelegramExecApprovalClientEnabled } from "./exec-approvals.js";
|
|
|
|
export function shouldSuppressTelegramExecApprovalForwardingFallback(params: {
|
|
cfg: OpenClawConfig;
|
|
target: { channel: string; accountId?: string | null };
|
|
request: ExecApprovalRequest;
|
|
}): boolean {
|
|
const channel = normalizeMessageChannel(params.target.channel) ?? params.target.channel;
|
|
if (channel !== "telegram") {
|
|
return false;
|
|
}
|
|
const requestChannel = normalizeMessageChannel(params.request.request.turnSourceChannel ?? "");
|
|
if (requestChannel !== "telegram") {
|
|
return false;
|
|
}
|
|
const accountId =
|
|
params.target.accountId?.trim() || params.request.request.turnSourceAccountId?.trim();
|
|
return isTelegramExecApprovalClientEnabled({ cfg: params.cfg, accountId });
|
|
}
|
|
|
|
export function buildTelegramExecApprovalPendingPayload(params: {
|
|
request: ExecApprovalRequest;
|
|
nowMs: number;
|
|
}) {
|
|
const payload = buildExecApprovalPendingReplyPayload({
|
|
approvalId: params.request.id,
|
|
approvalSlug: params.request.id.slice(0, 8),
|
|
approvalCommandId: params.request.id,
|
|
command: resolveExecApprovalCommandDisplay(params.request.request).commandText,
|
|
cwd: params.request.request.cwd ?? undefined,
|
|
host: params.request.request.host === "node" ? "node" : "gateway",
|
|
nodeId: params.request.request.nodeId ?? undefined,
|
|
expiresAtMs: params.request.expiresAtMs,
|
|
nowMs: params.nowMs,
|
|
});
|
|
const buttons = buildTelegramExecApprovalButtons(params.request.id);
|
|
if (!buttons) {
|
|
return payload;
|
|
}
|
|
return {
|
|
...payload,
|
|
channelData: {
|
|
...payload.channelData,
|
|
telegram: { buttons },
|
|
},
|
|
};
|
|
}
|