2
0

🐛 New sendMessage version for the new parser

Make sure old client still communicate with old parser
This commit is contained in:
Baptiste Arnaud
2023-10-06 10:14:26 +02:00
parent 6f3e9e9251
commit 3838ac9c3f
35 changed files with 710 additions and 416 deletions

View File

@ -3,10 +3,17 @@ import { ChatReply, SessionState } from '@typebot.io/schemas'
import { executeGroup } from './executeGroup'
import { getNextGroup } from './getNextGroup'
export const startBotFlow = async (
state: SessionState,
type Props = {
version: 1 | 2
state: SessionState
startGroupId?: string
): Promise<ChatReply & { newSessionState: SessionState }> => {
}
export const startBotFlow = async ({
version,
state,
startGroupId,
}: Props): Promise<ChatReply & { newSessionState: SessionState }> => {
let newSessionState = state
if (startGroupId) {
const group = state.typebotsQueue[0].typebot.groups.find(
@ -17,7 +24,7 @@ export const startBotFlow = async (
code: 'BAD_REQUEST',
message: "startGroupId doesn't exist",
})
return executeGroup(newSessionState)(group)
return executeGroup(group, { version, state: newSessionState })
}
const firstEdgeId =
newSessionState.typebotsQueue[0].typebot.groups[0].blocks[0].outgoingEdgeId
@ -25,5 +32,5 @@ export const startBotFlow = async (
const nextGroup = await getNextGroup(newSessionState)(firstEdgeId)
newSessionState = nextGroup.newSessionState
if (!nextGroup.group) return { messages: [], newSessionState }
return executeGroup(newSessionState)(nextGroup.group)
return executeGroup(nextGroup.group, { version, state: newSessionState })
}