Fix onboarding webhook timeout by running quest creation in background
All checks were successful
CI/CD / lint (push) Successful in 7s
CI/CD / build (push) Successful in 18s
CI/CD / deploy (push) Successful in 19s

This commit is contained in:
Jaymiesh 2026-02-11 16:23:34 +07:00
parent c15e6eac7a
commit a8cab41a00

View File

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