Fix onboarding webhook timeout by running quest creation in background
This commit is contained in:
parent
c15e6eac7a
commit
a8cab41a00
@ -155,8 +155,16 @@ export async function onboardingConversation(conversation: BotConversation, ctx:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await conversation.external(() =>
|
const chatId = ctx.chat?.id
|
||||||
createQuestFromOnboarding({
|
if (!chatId) {
|
||||||
|
await ctx.reply('Something went wrong. Please try /start again.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run heavy generation in background so webhook handlers can return quickly.
|
||||||
|
void (async () => {
|
||||||
|
try {
|
||||||
|
const result = await createQuestFromOnboarding({
|
||||||
userId,
|
userId,
|
||||||
cityId,
|
cityId,
|
||||||
cityName,
|
cityName,
|
||||||
@ -166,10 +174,9 @@ export async function onboardingConversation(conversation: BotConversation, ctx:
|
|||||||
userComment,
|
userComment,
|
||||||
lang,
|
lang,
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
await ctx.reply('Something went wrong. Please try /start again.')
|
await ctx.api.sendMessage(chatId, 'Something went wrong. Please try /start again.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,12 +187,21 @@ export async function onboardingConversation(conversation: BotConversation, ctx:
|
|||||||
description: result.description,
|
description: result.description,
|
||||||
}) + (isHttps ? '' : `\n\n🔗 ${appUrl}`)
|
}) + (isHttps ? '' : `\n\n🔗 ${appUrl}`)
|
||||||
|
|
||||||
await ctx.reply(
|
await ctx.api.sendMessage(
|
||||||
|
chatId,
|
||||||
questText,
|
questText,
|
||||||
isHttps ? {
|
isHttps ? {
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
inline_keyboard: [[ { text: t(lang, 'open_quest'), web_app: { url: appUrl } } ]],
|
inline_keyboard: [[{ text: t(lang, 'open_quest'), web_app: { url: appUrl } }]],
|
||||||
},
|
},
|
||||||
} : {}
|
} : {}
|
||||||
)
|
)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Background quest creation failed:', error)
|
||||||
|
await ctx.api.sendMessage(chatId, 'Something went wrong. Please try /start again.')
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
|
// Conversation finishes immediately; final quest message will be sent by background task.
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user