Fix onboarding webhook timeout by running quest creation in background
This commit is contained in:
parent
c15e6eac7a
commit
a8cab41a00
@ -155,37 +155,53 @@ export async function onboardingConversation(conversation: BotConversation, ctx:
|
||||
return
|
||||
}
|
||||
|
||||
const result = await conversation.external(() =>
|
||||
createQuestFromOnboarding({
|
||||
userId,
|
||||
cityId,
|
||||
cityName,
|
||||
days,
|
||||
companions,
|
||||
pace,
|
||||
userComment,
|
||||
lang,
|
||||
})
|
||||
)
|
||||
|
||||
if (!result) {
|
||||
const chatId = ctx.chat?.id
|
||||
if (!chatId) {
|
||||
await ctx.reply('Something went wrong. Please try /start again.')
|
||||
return
|
||||
}
|
||||
|
||||
const appUrl = process.env.APP_URL || 'https://guidly.example.com'
|
||||
const isHttps = appUrl.startsWith('https://')
|
||||
const questText = t(lang, 'quest_created', {
|
||||
title: result.title,
|
||||
description: result.description,
|
||||
}) + (isHttps ? '' : `\n\n🔗 ${appUrl}`)
|
||||
// Run heavy generation in background so webhook handlers can return quickly.
|
||||
void (async () => {
|
||||
try {
|
||||
const result = await createQuestFromOnboarding({
|
||||
userId,
|
||||
cityId,
|
||||
cityName,
|
||||
days,
|
||||
companions,
|
||||
pace,
|
||||
userComment,
|
||||
lang,
|
||||
})
|
||||
|
||||
await ctx.reply(
|
||||
questText,
|
||||
isHttps ? {
|
||||
reply_markup: {
|
||||
inline_keyboard: [[ { text: t(lang, 'open_quest'), web_app: { url: appUrl } } ]],
|
||||
},
|
||||
} : {}
|
||||
)
|
||||
if (!result) {
|
||||
await ctx.api.sendMessage(chatId, 'Something went wrong. Please try /start again.')
|
||||
return
|
||||
}
|
||||
|
||||
const appUrl = process.env.APP_URL || 'https://guidly.example.com'
|
||||
const isHttps = appUrl.startsWith('https://')
|
||||
const questText = t(lang, 'quest_created', {
|
||||
title: result.title,
|
||||
description: result.description,
|
||||
}) + (isHttps ? '' : `\n\n🔗 ${appUrl}`)
|
||||
|
||||
await ctx.api.sendMessage(
|
||||
chatId,
|
||||
questText,
|
||||
isHttps ? {
|
||||
reply_markup: {
|
||||
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