🐛 (chat) Make sure objects are deeply parsed with variables value
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { checkChatsUsage } from '@/features/usage'
|
||||
import { parsePrefilledVariables } from '@/features/variables'
|
||||
import {
|
||||
parsePrefilledVariables,
|
||||
deepParseVariable,
|
||||
} from '@/features/variables'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { publicProcedure } from '@/utils/server/trpc'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { Prisma } from 'db'
|
||||
import {
|
||||
ChatReply,
|
||||
chatReplySchema,
|
||||
ChatSession,
|
||||
PublicTypebot,
|
||||
@@ -192,13 +196,13 @@ const startSession = async (startParams?: StartParams) => {
|
||||
resultId: result?.id,
|
||||
sessionId: session.id,
|
||||
typebot: {
|
||||
theme: typebot.theme,
|
||||
settings: typebot.settings,
|
||||
settings: deepParseVariable(typebot.variables)(typebot.settings),
|
||||
theme: deepParseVariable(typebot.variables)(typebot.theme),
|
||||
},
|
||||
messages,
|
||||
input,
|
||||
logic,
|
||||
}
|
||||
} satisfies ChatReply
|
||||
}
|
||||
|
||||
const getResult = async ({
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { parseVariables } from '@/features/variables'
|
||||
import { deepParseVariable } from '@/features/variables'
|
||||
import {
|
||||
BubbleBlock,
|
||||
BubbleBlockType,
|
||||
ChatMessage,
|
||||
ChatReply,
|
||||
Group,
|
||||
InputBlock,
|
||||
@@ -38,20 +35,22 @@ export const executeGroup =
|
||||
nextEdgeId = block.outgoingEdgeId
|
||||
|
||||
if (isBubbleBlock(block)) {
|
||||
messages.push(parseBubbleBlockContent(newSessionState)(block))
|
||||
messages.push(
|
||||
deepParseVariable(newSessionState.typebot.variables)(block)
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
if (isInputBlock(block))
|
||||
return {
|
||||
messages,
|
||||
input: {
|
||||
input: deepParseVariable(newSessionState.typebot.variables)({
|
||||
...block,
|
||||
runtimeOptions: await computeRuntimeOptions(newSessionState)(block),
|
||||
prefilledValue: getPrefilledInputValue(
|
||||
newSessionState.typebot.variables
|
||||
)(block),
|
||||
},
|
||||
}),
|
||||
newSessionState: {
|
||||
...newSessionState,
|
||||
currentBlock: {
|
||||
@@ -102,34 +101,6 @@ const computeRuntimeOptions =
|
||||
}
|
||||
}
|
||||
|
||||
const parseBubbleBlockContent =
|
||||
({ typebot: { variables } }: SessionState) =>
|
||||
(block: BubbleBlock): ChatMessage => {
|
||||
switch (block.type) {
|
||||
case BubbleBlockType.TEXT: {
|
||||
const plainText = parseVariables(variables)(block.content.plainText)
|
||||
const html = parseVariables(variables)(block.content.html)
|
||||
return { type: block.type, content: { plainText, html } }
|
||||
}
|
||||
case BubbleBlockType.IMAGE: {
|
||||
const url = parseVariables(variables)(block.content.url)
|
||||
return { type: block.type, content: { ...block.content, url } }
|
||||
}
|
||||
case BubbleBlockType.VIDEO: {
|
||||
const url = parseVariables(variables)(block.content.url)
|
||||
return { type: block.type, content: { ...block.content, url } }
|
||||
}
|
||||
case BubbleBlockType.AUDIO: {
|
||||
const url = parseVariables(variables)(block.content.url)
|
||||
return { type: block.type, content: { ...block.content, url } }
|
||||
}
|
||||
case BubbleBlockType.EMBED: {
|
||||
const url = parseVariables(variables)(block.content.url)
|
||||
return { type: block.type, content: { ...block.content, url } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getPrefilledInputValue =
|
||||
(variables: SessionState['typebot']['variables']) => (block: InputBlock) => {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user