mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:38:27 +00:00
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:
committed by
Ayaan Zaidi
parent
16349b6e93
commit
202c554d09
@@ -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,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user