🐛 (webhook) Fix test request execution invalid timeout
This commit is contained in:
@@ -9,7 +9,13 @@ import {
|
||||
} from '@typebot.io/schemas'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import got, { Method, Headers, HTTPError } from 'got'
|
||||
import { byId, isEmpty, isWebhookBlock, omit } from '@typebot.io/lib'
|
||||
import {
|
||||
byId,
|
||||
isEmpty,
|
||||
isNotDefined,
|
||||
isWebhookBlock,
|
||||
omit,
|
||||
} from '@typebot.io/lib'
|
||||
import { parseAnswers } from '@typebot.io/lib/results'
|
||||
import { initMiddleware, methodNotAllowed, notFound } from '@typebot.io/lib/api'
|
||||
import { stringify } from 'qs'
|
||||
@@ -32,6 +38,7 @@ import {
|
||||
convertKeyValueTableToObject,
|
||||
longReqTimeoutWhitelist,
|
||||
} from '@typebot.io/bot-engine/blocks/integrations/webhook/executeWebhookBlock'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
const cors = initMiddleware(Cors())
|
||||
|
||||
@@ -78,6 +85,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
resultId,
|
||||
parentTypebotIds,
|
||||
isCustomBody: block.options?.isCustomBody,
|
||||
timeout: block.options?.timeout,
|
||||
})
|
||||
return res.status(200).send(result)
|
||||
}
|
||||
@@ -96,6 +104,7 @@ export const executeWebhook =
|
||||
resultId,
|
||||
parentTypebotIds = [],
|
||||
isCustomBody,
|
||||
timeout,
|
||||
}: {
|
||||
webhook: Webhook
|
||||
variables: Variable[]
|
||||
@@ -104,6 +113,7 @@ export const executeWebhook =
|
||||
resultId?: string
|
||||
parentTypebotIds: string[]
|
||||
isCustomBody?: boolean
|
||||
timeout?: number
|
||||
}): Promise<WebhookResponse> => {
|
||||
if (!webhook.url)
|
||||
return {
|
||||
@@ -184,7 +194,13 @@ export const executeWebhook =
|
||||
: undefined,
|
||||
body: body && !isJson ? body : undefined,
|
||||
timeout: {
|
||||
response: isLongRequest ? maxTimeout : defaultTimeout,
|
||||
response: isNotDefined(env.CHAT_API_TIMEOUT)
|
||||
? undefined
|
||||
: timeout && timeout !== defaultTimeout
|
||||
? Math.min(timeout, maxTimeout) * 1000
|
||||
: isLongRequest
|
||||
? maxTimeout * 1000
|
||||
: defaultTimeout * 1000,
|
||||
},
|
||||
}
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user