global update and global fix

This commit is contained in:
lendry
2026-06-25 23:48:57 +03:00
parent 3880c68d59
commit b0ea87e898
121 changed files with 13759 additions and 663 deletions

View File

@@ -0,0 +1,46 @@
export type ComposerMenuButton = {
type: 'web_app';
text: string;
web_app: { url: string };
};
export function parseComposerMenuButtonJson(raw?: string | null): ComposerMenuButton | null {
if (!raw?.trim()) {
return null;
}
try {
const parsed = JSON.parse(raw) as unknown;
if (
typeof parsed === 'object' &&
parsed !== null &&
(parsed as ComposerMenuButton).type === 'web_app' &&
typeof (parsed as ComposerMenuButton).text === 'string' &&
typeof (parsed as ComposerMenuButton).web_app?.url === 'string'
) {
const button = parsed as ComposerMenuButton;
const url = button.web_app.url.trim();
if (!url) {
return null;
}
return { type: 'web_app', text: button.text.trim() || 'App', web_app: { url } };
}
} catch {
return null;
}
return null;
}
export function resolveComposerMenuButton(options: {
composerMenuButtonJson?: string | null;
composerWebAppUrl?: string | null;
}): ComposerMenuButton | null {
const fromJson = parseComposerMenuButtonJson(options.composerMenuButtonJson);
if (fromJson) {
return fromJson;
}
const url = options.composerWebAppUrl?.trim();
if (url) {
return { type: 'web_app', text: 'App', web_app: { url } };
}
return null;
}