mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-26 08:31:55 +00:00
* refactor: move Telegram channel implementation to extensions/telegram/src/ Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin files) from src/telegram/ and src/channels/plugins/*/telegram.ts to extensions/telegram/src/. Leave thin re-export shims at original locations so cross-cutting src/ imports continue to resolve. - Fix all relative import paths in moved files (../X/ -> ../../../src/X/) - Fix vi.mock paths in 60 test files - Fix inline typeof import() expressions - Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS - Update write-plugin-sdk-entry-dts.ts for new rootDir structure - Move channel plugin files with correct path remapping * fix: support keyed telegram send deps * fix: sync telegram extension copies with latest main * fix: correct import paths and remove misplaced files in telegram extension * fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import type { ExecApprovalReplyDecision } from "../../../src/infra/exec-approval-reply.js";
|
|
import type { TelegramInlineButtons } from "./button-types.js";
|
|
|
|
const MAX_CALLBACK_DATA_BYTES = 64;
|
|
|
|
function fitsCallbackData(value: string): boolean {
|
|
return Buffer.byteLength(value, "utf8") <= MAX_CALLBACK_DATA_BYTES;
|
|
}
|
|
|
|
export function buildTelegramExecApprovalButtons(
|
|
approvalId: string,
|
|
): TelegramInlineButtons | undefined {
|
|
return buildTelegramExecApprovalButtonsForDecisions(approvalId, [
|
|
"allow-once",
|
|
"allow-always",
|
|
"deny",
|
|
]);
|
|
}
|
|
|
|
function buildTelegramExecApprovalButtonsForDecisions(
|
|
approvalId: string,
|
|
allowedDecisions: readonly ExecApprovalReplyDecision[],
|
|
): TelegramInlineButtons | undefined {
|
|
const allowOnce = `/approve ${approvalId} allow-once`;
|
|
if (!allowedDecisions.includes("allow-once") || !fitsCallbackData(allowOnce)) {
|
|
return undefined;
|
|
}
|
|
|
|
const primaryRow: Array<{ text: string; callback_data: string }> = [
|
|
{ text: "Allow Once", callback_data: allowOnce },
|
|
];
|
|
const allowAlways = `/approve ${approvalId} allow-always`;
|
|
if (allowedDecisions.includes("allow-always") && fitsCallbackData(allowAlways)) {
|
|
primaryRow.push({ text: "Allow Always", callback_data: allowAlways });
|
|
}
|
|
const rows: Array<Array<{ text: string; callback_data: string }>> = [primaryRow];
|
|
const deny = `/approve ${approvalId} deny`;
|
|
if (allowedDecisions.includes("deny") && fitsCallbackData(deny)) {
|
|
rows.push([{ text: "Deny", callback_data: deny }]);
|
|
}
|
|
return rows;
|
|
}
|