♻️ Export bot-engine code into its own package
This commit is contained in:
29
packages/bot-engine/blocks/logic/jump/executeJumpBlock.ts
Normal file
29
packages/bot-engine/blocks/logic/jump/executeJumpBlock.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { addEdgeToTypebot, createPortalEdge } from '../../../addEdgeToTypebot'
|
||||
import { ExecuteLogicResponse } from '../../../types'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { SessionState } from '@typebot.io/schemas'
|
||||
import { JumpBlock } from '@typebot.io/schemas/features/blocks/logic/jump'
|
||||
|
||||
export const executeJumpBlock = (
|
||||
state: SessionState,
|
||||
{ groupId, blockId }: JumpBlock['options']
|
||||
): ExecuteLogicResponse => {
|
||||
const { typebot } = state.typebotsQueue[0]
|
||||
const groupToJumpTo = typebot.groups.find((group) => group.id === groupId)
|
||||
const blockToJumpTo =
|
||||
groupToJumpTo?.blocks.find((block) => block.id === blockId) ??
|
||||
groupToJumpTo?.blocks[0]
|
||||
|
||||
if (!blockToJumpTo?.groupId)
|
||||
throw new TRPCError({
|
||||
code: 'INTERNAL_SERVER_ERROR',
|
||||
message: 'Block to jump to is not found',
|
||||
})
|
||||
|
||||
const portalEdge = createPortalEdge({
|
||||
to: { groupId: blockToJumpTo?.groupId, blockId: blockToJumpTo?.id },
|
||||
})
|
||||
const newSessionState = addEdgeToTypebot(state, portalEdge)
|
||||
|
||||
return { outgoingEdgeId: portalEdge.id, newSessionState }
|
||||
}
|
||||
Reference in New Issue
Block a user