🐛 (webhook) Prioritize variables parsing over answers
This commit is contained in:
@@ -255,6 +255,7 @@ const convertKeyValueTableToObject = (
|
||||
}, {})
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const safeJsonParse = (json: string): { data: any; isJson: boolean } => {
|
||||
try {
|
||||
return { data: JSON.parse(json), isJson: true }
|
||||
|
||||
@@ -190,7 +190,12 @@ export const parseAnswers =
|
||||
...[...answers, ...resultVariables].reduce<{
|
||||
[key: string]: string
|
||||
}>((o, answerOrVariable) => {
|
||||
if ('blockId' in answerOrVariable) {
|
||||
const isVariable = !('blockId' in answerOrVariable)
|
||||
if (isVariable) {
|
||||
const variable = answerOrVariable as VariableWithValue
|
||||
if (variable.value === null) return o
|
||||
return { ...o, [variable.name]: variable.value }
|
||||
}
|
||||
const answer = answerOrVariable as Answer
|
||||
const key = answer.variableId
|
||||
? header.find(
|
||||
@@ -202,14 +207,11 @@ export const parseAnswers =
|
||||
cell.blocks?.some((block) => block.id === answer.blockId)
|
||||
)?.label
|
||||
if (!key) return o
|
||||
if (isDefined(o[key])) return o
|
||||
return {
|
||||
...o,
|
||||
[key]: answer.content.toString(),
|
||||
}
|
||||
}
|
||||
const variable = answerOrVariable as VariableWithValue
|
||||
if (isDefined(o[variable.name]) || variable.value === null) return o
|
||||
return { ...o, [variable.name]: variable.value }
|
||||
}, {}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user