⚡ Improve new bot engine client side actions
We make sure to save client side actions in an array that will be executed sequentially
This commit is contained in:
@@ -48,6 +48,7 @@ export const sendMessageProcedure = publicProcedure
|
||||
resultId,
|
||||
dynamicTheme,
|
||||
logs,
|
||||
clientSideActions,
|
||||
} = await startSession(startParams)
|
||||
return {
|
||||
sessionId,
|
||||
@@ -63,9 +64,10 @@ export const sendMessageProcedure = publicProcedure
|
||||
resultId,
|
||||
dynamicTheme,
|
||||
logs,
|
||||
clientSideActions,
|
||||
}
|
||||
} else {
|
||||
const { messages, input, logic, newSessionState, integrations, logs } =
|
||||
const { messages, input, clientSideActions, newSessionState, logs } =
|
||||
await continueBotFlow(session.state)(message)
|
||||
|
||||
await prisma.chatSession.updateMany({
|
||||
@@ -78,8 +80,7 @@ export const sendMessageProcedure = publicProcedure
|
||||
return {
|
||||
messages,
|
||||
input,
|
||||
logic,
|
||||
integrations,
|
||||
clientSideActions,
|
||||
dynamicTheme: parseDynamicThemeReply(newSessionState),
|
||||
logs,
|
||||
}
|
||||
@@ -133,7 +134,7 @@ const startSession = async (startParams?: StartParams) => {
|
||||
const {
|
||||
messages,
|
||||
input,
|
||||
logic,
|
||||
clientSideActions,
|
||||
newSessionState: newInitialState,
|
||||
logs,
|
||||
} = await startBotFlow(initialState, startParams.startGroupId)
|
||||
@@ -141,7 +142,7 @@ const startSession = async (startParams?: StartParams) => {
|
||||
if (!input)
|
||||
return {
|
||||
messages,
|
||||
logic,
|
||||
clientSideActions,
|
||||
typebot: {
|
||||
id: typebot.id,
|
||||
settings: deepParseVariable(newInitialState.typebot.variables)(
|
||||
@@ -183,7 +184,7 @@ const startSession = async (startParams?: StartParams) => {
|
||||
},
|
||||
messages,
|
||||
input,
|
||||
logic,
|
||||
clientSideActions,
|
||||
dynamicTheme: parseDynamicThemeReply(newInitialState),
|
||||
logs,
|
||||
} satisfies ChatReply
|
||||
|
||||
@@ -25,8 +25,8 @@ export const executeGroup =
|
||||
group: Group
|
||||
): Promise<ChatReply & { newSessionState: SessionState }> => {
|
||||
const messages: ChatReply['messages'] = currentReply?.messages ?? []
|
||||
let logic: ChatReply['logic'] = currentReply?.logic
|
||||
let integrations: ChatReply['integrations'] = currentReply?.integrations
|
||||
let clientSideActions: ChatReply['clientSideActions'] =
|
||||
currentReply?.clientSideActions
|
||||
let logs: ChatReply['logs'] = currentReply?.logs
|
||||
let nextEdgeId = null
|
||||
|
||||
@@ -59,8 +59,7 @@ export const executeGroup =
|
||||
blockId: block.id,
|
||||
},
|
||||
},
|
||||
logic,
|
||||
integrations,
|
||||
clientSideActions,
|
||||
logs,
|
||||
}
|
||||
const executionResponse = isLogicBlock(block)
|
||||
@@ -70,10 +69,14 @@ export const executeGroup =
|
||||
: null
|
||||
|
||||
if (!executionResponse) continue
|
||||
if ('logic' in executionResponse && executionResponse.logic)
|
||||
logic = { ...logic, ...executionResponse.logic }
|
||||
if ('integrations' in executionResponse && executionResponse.integrations)
|
||||
integrations = { ...integrations, ...executionResponse.integrations }
|
||||
if (
|
||||
'clientSideActions' in executionResponse &&
|
||||
executionResponse.clientSideActions
|
||||
)
|
||||
clientSideActions = [
|
||||
...(clientSideActions ?? []),
|
||||
...executionResponse.clientSideActions,
|
||||
]
|
||||
if (executionResponse.logs)
|
||||
logs = [...(logs ?? []), ...executionResponse.logs]
|
||||
if (executionResponse.newSessionState)
|
||||
@@ -85,20 +88,19 @@ export const executeGroup =
|
||||
}
|
||||
|
||||
if (!nextEdgeId)
|
||||
return { messages, newSessionState, logic, integrations, logs }
|
||||
return { messages, newSessionState, clientSideActions, logs }
|
||||
|
||||
const nextGroup = getNextGroup(newSessionState)(nextEdgeId)
|
||||
|
||||
if (nextGroup?.updatedContext) newSessionState = nextGroup.updatedContext
|
||||
|
||||
if (!nextGroup) {
|
||||
return { messages, newSessionState, logic, integrations, logs }
|
||||
return { messages, newSessionState, clientSideActions, logs }
|
||||
}
|
||||
|
||||
return executeGroup(newSessionState, {
|
||||
messages,
|
||||
logic,
|
||||
integrations,
|
||||
clientSideActions,
|
||||
logs,
|
||||
})(nextGroup.group)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user