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
}
const result = await conversation.external(() =>
createQuestFromOnboarding({
const chatId = ctx.chat?.id
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,
cityId,
cityName,
@ -166,10 +174,9 @@ export async function onboardingConversation(conversation: BotConversation, ctx:
userComment,
lang,
})
)
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
}
@ -180,7 +187,8 @@ export async function onboardingConversation(conversation: BotConversation, ctx:
description: result.description,
}) + (isHttps ? '' : `\n\n🔗 ${appUrl}`)
await ctx.reply(
await ctx.api.sendMessage(
chatId,
questText,
isHttps ? {
reply_markup: {
@ -188,4 +196,12 @@ export async function onboardingConversation(conversation: BotConversation, ctx:
},
} : {}
)
} 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
}