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,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
} }