mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 15:54:03 +00:00
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:
@@ -149,6 +149,7 @@ function setupKeyboard(input: {
|
|||||||
bindings: readonly HouseholdTopicBindingRecord[]
|
bindings: readonly HouseholdTopicBindingRecord[]
|
||||||
miniAppUrl: string | undefined
|
miniAppUrl: string | undefined
|
||||||
botUsername: string | undefined
|
botUsername: string | undefined
|
||||||
|
isPrivate: boolean
|
||||||
}) {
|
}) {
|
||||||
const t = getBotTranslations(input.locale).setup
|
const t = getBotTranslations(input.locale).setup
|
||||||
const kt = getBotTranslations(input.locale).keyboard
|
const kt = getBotTranslations(input.locale).keyboard
|
||||||
@@ -199,6 +200,7 @@ function setupKeyboard(input: {
|
|||||||
// Add dashboard button
|
// Add dashboard button
|
||||||
const webAppUrl = buildOpenMiniAppUrl(input.miniAppUrl, input.botUsername)
|
const webAppUrl = buildOpenMiniAppUrl(input.miniAppUrl, input.botUsername)
|
||||||
if (webAppUrl) {
|
if (webAppUrl) {
|
||||||
|
if (input.isPrivate) {
|
||||||
rows.push([
|
rows.push([
|
||||||
{
|
{
|
||||||
text: kt.dashboardButton,
|
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
|
return rows.length > 0
|
||||||
@@ -256,6 +266,7 @@ function setupReply(input: {
|
|||||||
bindings: readonly HouseholdTopicBindingRecord[]
|
bindings: readonly HouseholdTopicBindingRecord[]
|
||||||
miniAppUrl: string | undefined
|
miniAppUrl: string | undefined
|
||||||
botUsername: string | undefined
|
botUsername: string | undefined
|
||||||
|
isPrivate: boolean
|
||||||
}) {
|
}) {
|
||||||
const t = getBotTranslations(input.locale).setup
|
const t = getBotTranslations(input.locale).setup
|
||||||
return {
|
return {
|
||||||
@@ -274,7 +285,8 @@ function setupReply(input: {
|
|||||||
joinDeepLink: input.joinDeepLink,
|
joinDeepLink: input.joinDeepLink,
|
||||||
bindings: input.bindings,
|
bindings: input.bindings,
|
||||||
miniAppUrl: input.miniAppUrl,
|
miniAppUrl: input.miniAppUrl,
|
||||||
botUsername: input.botUsername
|
botUsername: input.botUsername,
|
||||||
|
isPrivate: input.isPrivate
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,13 +336,15 @@ function miniAppReplyMarkup(
|
|||||||
locale: BotLocale,
|
locale: BotLocale,
|
||||||
miniAppUrl: string | undefined,
|
miniAppUrl: string | undefined,
|
||||||
botUsername: string | undefined,
|
botUsername: string | undefined,
|
||||||
joinToken: string
|
joinToken: string,
|
||||||
|
isPrivate: boolean
|
||||||
) {
|
) {
|
||||||
const webAppUrl = buildJoinMiniAppUrl(miniAppUrl, botUsername, joinToken)
|
const webAppUrl = buildJoinMiniAppUrl(miniAppUrl, botUsername, joinToken)
|
||||||
if (!webAppUrl) {
|
if (!webAppUrl) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPrivate) {
|
||||||
return {
|
return {
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
inline_keyboard: [
|
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(
|
function openMiniAppReplyMarkup(
|
||||||
locale: BotLocale,
|
locale: BotLocale,
|
||||||
miniAppUrl: string | undefined,
|
miniAppUrl: string | undefined,
|
||||||
botUsername: string | undefined
|
botUsername: string | undefined,
|
||||||
|
isPrivate: boolean
|
||||||
) {
|
) {
|
||||||
const webAppUrl = buildOpenMiniAppUrl(miniAppUrl, botUsername)
|
const webAppUrl = buildOpenMiniAppUrl(miniAppUrl, botUsername)
|
||||||
if (!webAppUrl) {
|
if (!webAppUrl) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPrivate) {
|
||||||
return {
|
return {
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
inline_keyboard: [
|
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: {
|
export function registerHouseholdSetupCommands(options: {
|
||||||
bot: Bot
|
bot: Bot
|
||||||
householdSetupService: HouseholdSetupService
|
householdSetupService: HouseholdSetupService
|
||||||
@@ -435,7 +483,8 @@ export function registerHouseholdSetupCommands(options: {
|
|||||||
joinDeepLink,
|
joinDeepLink,
|
||||||
bindings,
|
bindings,
|
||||||
miniAppUrl: input.miniAppUrl,
|
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(
|
await ctx.reply(
|
||||||
t.setup.openMiniAppFromPrivateChat,
|
t.setup.openMiniAppFromPrivateChat,
|
||||||
openMiniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username)
|
openMiniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, true)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -525,14 +574,14 @@ export function registerHouseholdSetupCommands(options: {
|
|||||||
if (result.status === 'active') {
|
if (result.status === 'active') {
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
t.setup.alreadyActiveMember(result.member.displayName),
|
t.setup.alreadyActiveMember(result.member.displayName),
|
||||||
miniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, joinToken)
|
miniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username, joinToken, true)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
t.setup.joinRequestSent(result.household.name),
|
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(
|
await ctx.reply(
|
||||||
t.setup.openMiniAppFromPrivateChat,
|
t.setup.openMiniAppFromPrivateChat,
|
||||||
openMiniAppReplyMarkup(locale, options.miniAppUrl, ctx.me.username)
|
openMiniAppReplyMarkup(
|
||||||
|
locale,
|
||||||
|
options.miniAppUrl,
|
||||||
|
ctx.me.username,
|
||||||
|
ctx.chat?.type === 'private'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user