Skip to content

Commit

Permalink
🚸 (http) Allow for query params list
Browse files Browse the repository at this point in the history
Closes #1638
  • Loading branch information
baptisteArno committed Jul 15, 2024
1 parent 94ed572 commit 8e15472
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export const parseWebhookAttributes = async ({
typebot.variables
) as ExecutableHttpRequest['headers'] | undefined
const queryParams = stringify(
convertKeyValueTableToObject(webhook.queryParams, typebot.variables)
convertKeyValueTableToObject(webhook.queryParams, typebot.variables, true),
{ indices: false }
)
const bodyContent = await getBodyContent({
body: webhook.body,
Expand Down Expand Up @@ -325,17 +326,19 @@ const getBodyContent = async ({

export const convertKeyValueTableToObject = (
keyValues: KeyValue[] | undefined,
variables: Variable[]
variables: Variable[],
concatDuplicateInArray = false
) => {
if (!keyValues) return
return keyValues.reduce((object, item) => {
return keyValues.reduce<Record<string, string | string[]>>((object, item) => {
const key = parseVariables(variables)(item.key)
const value = parseVariables(variables)(item.value)
if (isEmpty(key) || isEmpty(value)) return object
return {
...object,
[key]: value,
}
if (object[key] && concatDuplicateInArray) {
if (Array.isArray(object[key])) object[key].push(value)
else object[key] = [object[key], value]
} else object[key] = value
return object
}, {})
}

Expand Down

0 comments on commit 8e15472

Please sign in to comment.