Register pi commands in Telegram menu

This commit is contained in:
wassname
2026-04-24 21:56:07 +08:00
parent 14798607c6
commit 3ce880d5bc
7 changed files with 159 additions and 27 deletions
+3 -27
View File
@@ -75,6 +75,7 @@ import {
type TelegramQueueItem,
} from "./lib/queue.ts";
import {
buildTelegramBotCommands,
registerTelegramAttachmentTool,
registerTelegramCommands,
registerTelegramLifecycleHooks,
@@ -255,11 +256,6 @@ interface TelegramSentMessage {
message_id: number;
}
interface TelegramBotCommand {
command: string;
description: string;
}
// --- Extension State Types ---
interface DownloadedTelegramFile {
@@ -1051,27 +1047,7 @@ export default function (pi: ExtensionAPI) {
}
async function registerTelegramBotCommands(): Promise<void> {
const localCommands: TelegramBotCommand[] = [
{ command: "start", description: "Show help" },
{ command: "status", description: "Show model, usage, cost, and context status" },
{ command: "trace", description: "Cycle display mode: text / compact / full" },
{ command: "model", description: "Open the interactive model selector" },
{ command: "compact", description: "Compact the current pi session" },
{ command: "stop", description: "Abort the current pi task" },
];
const localNames = new Set(localCommands.map((c) => c.command));
const telegramCommandNamePattern = /^[a-z0-9_]{1,32}$/;
const extensionCommands: TelegramBotCommand[] = pi.getCommands()
.filter((c: { name: string; description?: string; source?: string }) =>
c.source === "extension" &&
!localNames.has(c.name) &&
telegramCommandNamePattern.test(c.name),
)
.map((c: { name: string; description?: string }) => ({
command: c.name,
description: c.description ?? c.name,
}));
const commands = [...localCommands, ...extensionCommands];
const commands = buildTelegramBotCommands(pi.getCommands());
await callTelegramApi<boolean>("setMyCommands", { commands });
}
@@ -1798,7 +1774,7 @@ export default function (pi: ExtensionAPI) {
ctx: ExtensionContext,
): Promise<void> {
let helpText =
"Send me a message and I will forward it to pi.\n\nLocal: /status, /trace, /model, /compact, /stop, /quit\nOther /commands and ! shell commands pass through to pi directly.";
"Send me a message and I will forward it to pi.\n\nLocal: /status, /trace, /model, /compact, /stop, /quit\n/start refreshes Telegram's command menu with local controls plus valid pi prompt, skill, and extension commands.\nOther /commands and ! shell commands pass through to pi directly.";
if (commandName === "start") {
try {