Telegram: prefix native command menu callbacks

This commit is contained in:
Vincent Koc 2026-03-13 13:31:17 -07:00
parent 2c8754c3e1
commit a057f2f03a
1 changed files with 16 additions and 1 deletions

View File

@ -74,6 +74,7 @@ import { resolveTelegramGroupPromptSettings } from "./group-config-helpers.js";
import { buildInlineKeyboard } from "./send.js";
const EMPTY_RESPONSE_FALLBACK = "No response generated. Please try again.";
const TELEGRAM_NATIVE_COMMAND_CALLBACK_PREFIX = "tgcmd:";
type TelegramNativeCommandContext = Context & { match?: string };
@ -142,6 +143,18 @@ type RegisterTelegramNativeCommandsParams = {
opts: { token: string };
};
export function buildTelegramNativeCommandCallbackData(commandText: string): string {
return `${TELEGRAM_NATIVE_COMMAND_CALLBACK_PREFIX}${commandText}`;
}
export function parseTelegramNativeCommandCallbackData(data: string): string | null {
if (!data.startsWith(TELEGRAM_NATIVE_COMMAND_CALLBACK_PREFIX)) {
return null;
}
const commandText = data.slice(TELEGRAM_NATIVE_COMMAND_CALLBACK_PREFIX.length).trim();
return commandText || null;
}
async function resolveTelegramCommandAuth(params: {
msg: NonNullable<TelegramNativeCommandContext["message"]>;
bot: Bot;
@ -632,7 +645,9 @@ export const registerTelegramNativeCommands = ({
};
return {
text: choice.label,
callback_data: buildCommandTextFromArgs(commandDefinition, args),
callback_data: buildTelegramNativeCommandCallbackData(
buildCommandTextFromArgs(commandDefinition, args),
),
};
}),
);