Fix setup command and refine payment clarification logic

- Fix BUTTON_TYPE_INVALID in non-private chats by using URL buttons for mini app links
- Localize clarification questions and processing messages
- Add language instructions to AI prompt
- Allow default payment amounts when not explicitly specified
This commit is contained in:
2026-03-15 02:34:34 +04:00
parent afbda43c0e
commit 5e39cdf455

View File

@@ -149,6 +149,7 @@ function setupKeyboard(input: {
bindings: readonly HouseholdTopicBindingRecord[]
miniAppUrl: string | undefined
botUsername: string | undefined
isPrivate: boolean
}) {
const t = getBotTranslations(input.locale).setup
const kt = getBotTranslations(input.locale).keyboard
@@ -199,6 +200,7 @@ function setupKeyboard(input: {
// Add dashboard button
const webAppUrl = buildOpenMiniAppUrl(input.miniAppUrl, input.botUsername)
if (webAppUrl) {
if (input.isPrivate) {
rows.push([
{
text: kt.dashboardButton,
@@ -207,6 +209,14 @@ function setupKeyboard(input: {
}
}
])
} else if (input.botUsername) {
rows.push([
{
text: kt.dashboardButton,
url: `https://t.me/${input.botUsername}/app`
}
])
}
}
return rows.length > 0
@@ -256,6 +266,7 @@ function setupReply(input: {
bindings: readonly HouseholdTopicBindingRecord[]
miniAppUrl: string | undefined
botUsername: string | undefined
isPrivate: boolean
}) {
const t = getBotTranslations(input.locale).setup
return {
@@ -274,7 +285,8 @@ function setupReply(input: {
joinDeepLink: input.joinDeepLink,
bindings: input.bindings,
miniAppUrl: input.miniAppUrl,
botUsername: input.botUsername
botUsername: input.botUsername,
isPrivate: input.isPrivate
})
}
}
@@ -324,13 +336,15 @@ function miniAppReplyMarkup(
locale: BotLocale,
miniAppUrl: string | undefined,
botUsername: string | undefined,
joinToken: string
joinToken: string,
isPrivate: boolean
) {
const webAppUrl = buildJoinMiniAppUrl(miniAppUrl, botUsername, joinToken)
if (!webAppUrl) {
return {}
}
if (isPrivate) {
return {
reply_markup: {
inline_keyboard: [
@@ -347,16 +361,34 @@ function miniAppReplyMarkup(
}
}
return botUsername
? {
reply_markup: {
inline_keyboard: [
[
{
text: getBotTranslations(locale).setup.openMiniAppButton,
url: `https://t.me/${botUsername}/app?startapp=join_${joinToken}`
}
]
]
}
}
: {}
}
function openMiniAppReplyMarkup(
locale: BotLocale,
miniAppUrl: string | undefined,
botUsername: string | undefined
botUsername: string | undefined,
isPrivate: boolean
) {
const webAppUrl = buildOpenMiniAppUrl(miniAppUrl, botUsername)
if (!webAppUrl) {
return {}
}
if (isPrivate) {
return {
reply_markup: {
inline_keyboard: [
@@ -373,6 +405,22 @@ function openMiniAppReplyMarkup(
}
}
return botUsername
? {
reply_markup: {
inline_keyboard: [
[
{
text: getBotTranslations(locale).setup.openMiniAppButton,
url: `https://t.me/${botUsername}/app`
}
]
]
}
}
: {}
}
export function registerHouseholdSetupCommands(options: {
bot: Bot
householdSetupService: HouseholdSetupService
@@ -435,7 +483,8 @@ export function registerHouseholdSetupCommands(options: {
joinDeepLink,
bindings,
miniAppUrl: input.miniAppUrl,
botUsername: input.botUsername
botUsername: input.botUsername,
isPrivate: input.ctx.chat?.type === 'private'
})
}
@@ -467,7 +516,7 @@ export function registerHouseholdSetupCommands(options: {
await ctx.reply(
t.setup.openMiniAppFromPrivateChat,
openMiniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username)
openMiniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, true)
)
return
}
@@ -525,14 +574,14 @@ export function registerHouseholdSetupCommands(options: {
if (result.status === 'active') {
await ctx.reply(
t.setup.alreadyActiveMember(result.member.displayName),
miniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, joinToken)
miniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, joinToken, true)
)
return
}
await ctx.reply(
t.setup.joinRequestSent(result.household.name),
miniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, joinToken)
miniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, joinToken, true)
)
})
@@ -1139,7 +1188,12 @@ export function registerHouseholdSetupCommands(options: {
await ctx.reply(
t.setup.openMiniAppFromPrivateChat,
openMiniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username)
openMiniAppReplyMarkup(
locale,
options.miniAppUrl,
ctx.me.username,
ctx.chat?.type === 'private'
)
)
})