Fork of upstream llblab/[email protected].0 (SHA afe09c5) repackaged as a drop-in extension for can1357/oh-my-pi (omp >= 16.5.2). Changes vs upstream: - Rename package: @llblab/pi-telegram -> @evandrodevbr/oh-my-pi-telegram - Bump version: 0.22.0 -> 0.22.0-evandro.1 - Update repository/homepage/bugs URLs to evandrodevbr - Add omp field in package.json (displayName + compatibleWith) - README: prepend 'Oh My Pi (omp) Compatibility' section with install commands, verified-components table, upstream lineage, and rationale - CHANGELOG: add '0.22.0-evandro.1' entry under Unreleased - docs/: rename @llblab/pi-telegram imports to @evandrodevbr/oh-my-pi-telegram - tests/public-api.test.ts: rename package import paths Gates re-run on the fork: - npm run typecheck -> tsc --noEmit (success) - npm test -> 1229 pass / 0 fail / 1 platform-only skip - npm run audit -> found 0 vulnerabilities - npm run pack:check -> evandrodevbr-oh-my-pi-telegram-0.22.0-evandro.1.tgz Verified: - omp install --link ./pi-telegram -> Linked OK - omp plugin list -> @evandrodevbr/[email protected].0-evandro.1 Upstream lineage: badlogic/pi-telegram -> llblab/pi-telegram (0.22.0) -> evandrodevbr/oh-my-pi-telegram (this fork)
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
/**
|
|
* Telegram inline-keyboard structural contracts
|
|
* Zones: telegram ui, shared structure
|
|
* Owns the shared Bot API reply-markup shape while feature domains own their button semantics
|
|
*/
|
|
|
|
export interface TelegramInlineKeyboardButton {
|
|
text: string;
|
|
callback_data: string;
|
|
}
|
|
|
|
export interface TelegramInlineKeyboardMarkup {
|
|
inline_keyboard: TelegramInlineKeyboardButton[][];
|
|
}
|
|
|
|
export const TELEGRAM_CALLBACK_DATA_MAX_BYTES = 64;
|
|
|
|
export function getTelegramCallbackDataByteLength(value: string): number {
|
|
return new TextEncoder().encode(value).byteLength;
|
|
}
|
|
|
|
export function assertTelegramCallbackData(
|
|
callbackData: string,
|
|
context = "Telegram callback_data",
|
|
): string {
|
|
const byteLength = getTelegramCallbackDataByteLength(callbackData);
|
|
if (byteLength > TELEGRAM_CALLBACK_DATA_MAX_BYTES) {
|
|
throw new Error(
|
|
`${context} exceeds ${TELEGRAM_CALLBACK_DATA_MAX_BYTES} bytes (${byteLength}). Use a shorter action/payload or store state behind a compact key.`,
|
|
);
|
|
}
|
|
return callbackData;
|
|
}
|
|
|
|
export function assertTelegramInlineKeyboardCallbackData(
|
|
replyMarkup: unknown,
|
|
context = "Telegram inline keyboard callback_data",
|
|
): void {
|
|
if (!replyMarkup || typeof replyMarkup !== "object") return;
|
|
const keyboard = (replyMarkup as { inline_keyboard?: unknown })
|
|
.inline_keyboard;
|
|
if (!Array.isArray(keyboard)) return;
|
|
for (const row of keyboard) {
|
|
if (!Array.isArray(row)) continue;
|
|
for (const button of row) {
|
|
if (!button || typeof button !== "object") continue;
|
|
const callbackData = (button as { callback_data?: unknown })
|
|
.callback_data;
|
|
if (typeof callbackData !== "string") continue;
|
|
assertTelegramCallbackData(callbackData, context);
|
|
}
|
|
}
|
|
}
|