mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 16:20:23 +00:00
feat: improve /help and /commands formatting with categories and pagination
- Add CommandCategory type to organize commands into groups (session, options, status, management, media, tools, docks) - Refactor /help to show grouped sections for better discoverability - Add pagination support for /commands on Telegram (8 commands per page with nav buttons) - Show grouped list without pagination on other channels - Handle commands_page_N callback queries for Telegram pagination navigation
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
d3a6333ef7
commit
d91b4a3045
@@ -4,6 +4,9 @@ import {
|
||||
createInboundDebouncer,
|
||||
resolveInboundDebounceMs,
|
||||
} from "../auto-reply/inbound-debounce.js";
|
||||
import { buildCommandsPaginationKeyboard } from "../auto-reply/reply/commands-info.js";
|
||||
import { buildCommandsMessagePaginated } from "../auto-reply/status.js";
|
||||
import { listSkillCommandsForAgents } from "../auto-reply/skill-commands.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { writeConfigFile } from "../config/io.js";
|
||||
import { danger, logVerbose, warn } from "../globals.js";
|
||||
@@ -17,6 +20,7 @@ import { migrateTelegramGroupConfig } from "./group-migration.js";
|
||||
import { resolveTelegramInlineButtonsScope } from "./inline-buttons.js";
|
||||
import { readTelegramAllowFromStore } from "./pairing-store.js";
|
||||
import { resolveChannelConfigWrites } from "../channels/plugins/config-writes.js";
|
||||
import { buildInlineKeyboard } from "./send.js";
|
||||
|
||||
export const registerTelegramHandlers = ({
|
||||
cfg,
|
||||
@@ -199,6 +203,47 @@ export const registerTelegramHandlers = ({
|
||||
const callbackMessage = callback.message;
|
||||
if (!data || !callbackMessage) return;
|
||||
|
||||
// Handle commands pagination callback
|
||||
const paginationMatch = data.match(/^commands_page_(\d+|noop)$/);
|
||||
if (paginationMatch) {
|
||||
const pageValue = paginationMatch[1];
|
||||
if (pageValue === "noop") return; // Page number button - no action
|
||||
|
||||
const page = parseInt(pageValue, 10);
|
||||
if (isNaN(page) || page < 1) return;
|
||||
|
||||
const skillCommands = listSkillCommandsForAgents({ cfg });
|
||||
const result = buildCommandsMessagePaginated(cfg, skillCommands, {
|
||||
page,
|
||||
surface: "telegram",
|
||||
});
|
||||
|
||||
const messageId = callbackMessage.message_id;
|
||||
const chatId = callbackMessage.chat.id;
|
||||
const keyboard =
|
||||
result.totalPages > 1
|
||||
? buildInlineKeyboard(
|
||||
buildCommandsPaginationKeyboard(result.currentPage, result.totalPages),
|
||||
)
|
||||
: undefined;
|
||||
|
||||
try {
|
||||
await bot.api.editMessageText(
|
||||
chatId,
|
||||
messageId,
|
||||
result.text,
|
||||
keyboard ? { reply_markup: keyboard } : undefined,
|
||||
);
|
||||
} catch (editErr) {
|
||||
// Ignore "message is not modified" errors (user clicked same page)
|
||||
const errStr = String(editErr);
|
||||
if (!errStr.includes("message is not modified")) {
|
||||
throw editErr;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const inlineButtonsScope = resolveTelegramInlineButtonsScope({
|
||||
cfg,
|
||||
accountId,
|
||||
|
||||
Reference in New Issue
Block a user