feat(bot): persist locale preferences across mini app and replies

This commit is contained in:
2026-03-09 13:17:46 +04:00
parent 9de6bcc31b
commit 2d8e0491cc
19 changed files with 904 additions and 77 deletions

View File

@@ -5,6 +5,8 @@ export interface MiniAppSession {
member?: {
displayName: string
isAdmin: boolean
preferredLocale: 'en' | 'ru' | null
householdDefaultLocale: 'en' | 'ru'
}
telegramUser?: {
firstName: string | null
@@ -14,9 +16,17 @@ export interface MiniAppSession {
onboarding?: {
status: 'join_required' | 'pending' | 'open_from_group'
householdName?: string
householdDefaultLocale?: 'en' | 'ru'
}
}
export interface MiniAppLocalePreference {
scope: 'member' | 'household'
effectiveLocale: 'en' | 'ru'
memberPreferredLocale: 'en' | 'ru' | null
householdDefaultLocale: 'en' | 'ru'
}
export interface MiniAppPendingMember {
telegramUserId: string
displayName: string
@@ -219,3 +229,34 @@ export async function approveMiniAppPendingMember(
throw new Error(payload.error ?? 'Failed to approve member')
}
}
export async function updateMiniAppLocalePreference(
initData: string,
locale: 'en' | 'ru',
scope: 'member' | 'household'
): Promise<MiniAppLocalePreference> {
const response = await fetch(`${apiBaseUrl()}/api/miniapp/preferences/locale`, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
initData,
locale,
scope
})
})
const payload = (await response.json()) as {
ok: boolean
authorized?: boolean
locale?: MiniAppLocalePreference
error?: string
}
if (!response.ok || !payload.authorized || !payload.locale) {
throw new Error(payload.error ?? 'Failed to update locale preference')
}
return payload.locale
}