🚑 (typebotLink) Fix incoming linked typebot variables filling
This commit is contained in:
@ -8,15 +8,15 @@ import {
|
|||||||
SessionState,
|
SessionState,
|
||||||
Variable,
|
Variable,
|
||||||
ReplyLog,
|
ReplyLog,
|
||||||
VariableWithValue,
|
|
||||||
Edge,
|
Edge,
|
||||||
typebotInSessionStateSchema,
|
typebotInSessionStateSchema,
|
||||||
TypebotInSession,
|
TypebotInSession,
|
||||||
} from '@typebot.io/schemas'
|
} from '@typebot.io/schemas'
|
||||||
import { ExecuteLogicResponse } from '@/features/chat/types'
|
import { ExecuteLogicResponse } from '@/features/chat/types'
|
||||||
import { createId } from '@paralleldrive/cuid2'
|
import { createId } from '@paralleldrive/cuid2'
|
||||||
import { isDefined, isNotDefined } from '@typebot.io/lib/utils'
|
import { isNotDefined } from '@typebot.io/lib/utils'
|
||||||
import { createResultIfNotExist } from '@/features/chat/queries/createResultIfNotExist'
|
import { createResultIfNotExist } from '@/features/chat/queries/createResultIfNotExist'
|
||||||
|
import { executeJumpBlock } from '../jump/executeJumpBlock'
|
||||||
|
|
||||||
export const executeTypebotLink = async (
|
export const executeTypebotLink = async (
|
||||||
state: SessionState,
|
state: SessionState,
|
||||||
@ -24,6 +24,14 @@ export const executeTypebotLink = async (
|
|||||||
): Promise<ExecuteLogicResponse> => {
|
): Promise<ExecuteLogicResponse> => {
|
||||||
const logs: ReplyLog[] = []
|
const logs: ReplyLog[] = []
|
||||||
const typebotId = block.options.typebotId
|
const typebotId = block.options.typebotId
|
||||||
|
if (
|
||||||
|
typebotId === 'current' ||
|
||||||
|
typebotId === state.typebotsQueue[0].typebot.id
|
||||||
|
) {
|
||||||
|
return executeJumpBlock(state, {
|
||||||
|
groupId: block.options.groupId,
|
||||||
|
})
|
||||||
|
}
|
||||||
if (!typebotId) {
|
if (!typebotId) {
|
||||||
logs.push({
|
logs.push({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
@ -91,10 +99,7 @@ const addLinkedTypebotToState = async (
|
|||||||
}
|
}
|
||||||
: currentTypebotInQueue
|
: currentTypebotInQueue
|
||||||
|
|
||||||
const shouldMergeResults =
|
const shouldMergeResults = block.options.mergeResults !== false
|
||||||
block.options.mergeResults !== false ||
|
|
||||||
currentTypebotInQueue.typebot.id === linkedTypebot.id ||
|
|
||||||
block.options.typebotId === 'current'
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
currentTypebotInQueue.resultId &&
|
currentTypebotInQueue.resultId &&
|
||||||
@ -168,26 +173,23 @@ const createResumeEdgeIfNecessary = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fillVariablesWithExistingValues = (
|
const fillVariablesWithExistingValues = (
|
||||||
variables: Variable[],
|
emptyVariables: Variable[],
|
||||||
variablesWithValues: Variable[]
|
existingVariables: Variable[]
|
||||||
): VariableWithValue[] =>
|
): Variable[] =>
|
||||||
variables
|
emptyVariables.map((emptyVariable) => {
|
||||||
.map((variable) => {
|
const matchedVariable = existingVariables.find(
|
||||||
const matchedVariable = variablesWithValues.find(
|
(existingVariable) => existingVariable.name === emptyVariable.name
|
||||||
(variableWithValue) => variableWithValue.name === variable.name
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...variable,
|
...emptyVariable,
|
||||||
value: matchedVariable?.value,
|
value: matchedVariable?.value,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter((variable) => isDefined(variable.value)) as VariableWithValue[]
|
|
||||||
|
|
||||||
const fetchTypebot = async (state: SessionState, typebotId: string) => {
|
const fetchTypebot = async (state: SessionState, typebotId: string) => {
|
||||||
const { typebot: typebotInState, resultId } = state.typebotsQueue[0]
|
const { resultId } = state.typebotsQueue[0]
|
||||||
const isPreview = !resultId
|
const isPreview = !resultId
|
||||||
if (typebotId === 'current') return typebotInState
|
|
||||||
if (isPreview) {
|
if (isPreview) {
|
||||||
const typebot = await prisma.typebot.findUnique({
|
const typebot = await prisma.typebot.findUnique({
|
||||||
where: { id: typebotId },
|
where: { id: typebotId },
|
||||||
|
Reference in New Issue
Block a user