Telegram: fix model button review issues

- Add currentModel to callback handler for checkmark display
- Add 64-byte callback_data limit protection (skip long model IDs)
- Add tests for large model lists and callback_data limits
This commit is contained in:
Ermenegildo Fiorito
2026-02-03 19:15:22 +01:00
committed by Ayaan Zaidi
parent 16349b6e93
commit 202c554d09
3 changed files with 107 additions and 4 deletions

View File

@@ -31,6 +31,7 @@ export type ModelsKeyboardParams = {
};
const MODELS_PAGE_SIZE = 8;
const MAX_CALLBACK_DATA_BYTES = 64;
/**
* Parse a model callback_data string into a structured object.
@@ -132,6 +133,12 @@ export function buildModelsKeyboard(params: ModelsKeyboardParams): ButtonRow[] {
: currentModel;
for (const model of pageModels) {
const callbackData = `mdl_sel_${provider}/${model}`;
// Skip models that would exceed Telegram's callback_data limit
if (Buffer.byteLength(callbackData, "utf8") > MAX_CALLBACK_DATA_BYTES) {
continue;
}
const isCurrentModel = model === currentModelId;
const displayText = truncateModelId(model, 38);
const text = isCurrentModel ? `${displayText}` : displayText;
@@ -139,7 +146,7 @@ export function buildModelsKeyboard(params: ModelsKeyboardParams): ButtonRow[] {
rows.push([
{
text,
callback_data: `mdl_sel_${provider}/${model}`,
callback_data: callbackData,
},
]);
}