From 3bd07c60daa3c8bdf1ab124b507aadaecc7b4b27 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Wed, 13 Dec 2023 10:55:04 +0100 Subject: [PATCH] :heavy_plus_sign: (webhook) Add Orimon in long request whitelist --- .../blocks/[blockId]/executeWebhook.ts | 20 ++++++++++++++++--- .../webhook/executeWebhookBlock.ts | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts index e783fdc9f..008da50be 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts @@ -27,6 +27,11 @@ import { defaultWebhookAttributes, } from '@typebot.io/schemas/features/blocks/integrations/webhook/constants' import { getBlockById } from '@typebot.io/lib/getBlockById' +import { + longReqTimeoutWhitelist, + longRequestTimeout, + responseDefaultTimeout, +} from '@typebot.io/bot-engine/blocks/integrations/webhook/executeWebhookBlock' const cors = initMiddleware(Cors()) @@ -156,10 +161,16 @@ export const executeWebhook = ) : { data: undefined, isJson: false } + const url = parseVariables(variables)( + webhook.url + (queryParams !== '' ? `?${queryParams}` : '') + ) + + const isLongRequest = longReqTimeoutWhitelist.some((whiteListedUrl) => + url?.includes(whiteListedUrl) + ) + const request = { - url: parseVariables(variables)( - webhook.url + (queryParams !== '' ? `?${queryParams}` : '') - ), + url, method: (webhook.method ?? defaultWebhookAttributes.method) as Method, headers: headers ?? {}, ...basicAuth, @@ -172,6 +183,9 @@ export const executeWebhook = ? body : undefined, body: body && !isJson ? body : undefined, + timeout: { + response: isLongRequest ? longRequestTimeout : responseDefaultTimeout, + }, } try { const response = await got(request.url, omit(request, 'url')) diff --git a/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts b/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts index b75ca3bab..4ac506b18 100644 --- a/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts +++ b/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts @@ -33,10 +33,11 @@ type ParsedWebhook = ExecutableWebhook & { export const responseDefaultTimeout = 10000 export const longRequestTimeout = 120000 -const longReqTimeoutWhitelist = [ +export const longReqTimeoutWhitelist = [ 'https://api.openai.com', 'https://retune.so', 'https://www.chatbase.co', + 'https://channel-connector.orimon.ai', ] export const executeWebhookBlock = async (