@@ -3,15 +3,38 @@ import { ScriptBlock, SessionState, Variable } from '@typebot.io/schemas'
|
||||
import { extractVariablesFromText } from '@typebot.io/variables/extractVariablesFromText'
|
||||
import { parseGuessedValueType } from '@typebot.io/variables/parseGuessedValueType'
|
||||
import { parseVariables } from '@typebot.io/variables/parseVariables'
|
||||
import { defaultScriptOptions } from '@typebot.io/schemas/features/blocks/logic/script/constants'
|
||||
import { executeFunction } from '@typebot.io/variables/executeFunction'
|
||||
import { updateVariablesInSession } from '@typebot.io/variables/updateVariablesInSession'
|
||||
|
||||
export const executeScript = (
|
||||
export const executeScript = async (
|
||||
state: SessionState,
|
||||
block: ScriptBlock
|
||||
): ExecuteLogicResponse => {
|
||||
): Promise<ExecuteLogicResponse> => {
|
||||
const { variables } = state.typebotsQueue[0].typebot
|
||||
if (!block.options?.content || state.whatsApp)
|
||||
return { outgoingEdgeId: block.outgoingEdgeId }
|
||||
|
||||
const isExecutedOnClient =
|
||||
block.options.isExecutedOnClient ?? defaultScriptOptions.isExecutedOnClient
|
||||
|
||||
if (!isExecutedOnClient) {
|
||||
const { newVariables, error } = await executeFunction({
|
||||
variables,
|
||||
body: block.options.content,
|
||||
})
|
||||
|
||||
const newSessionState = newVariables
|
||||
? updateVariablesInSession(state)(newVariables)
|
||||
: state
|
||||
|
||||
return {
|
||||
outgoingEdgeId: block.outgoingEdgeId,
|
||||
logs: error ? [{ status: 'error', description: error }] : [],
|
||||
newSessionState,
|
||||
}
|
||||
}
|
||||
|
||||
const scriptToExecute = parseScriptToExecuteClientSideAction(
|
||||
variables,
|
||||
block.options.content
|
||||
|
||||
@@ -101,6 +101,7 @@ export const executeForgedBlock = async (
|
||||
newSessionState.typebotsQueue[0].typebot.variables,
|
||||
params
|
||||
)(text),
|
||||
list: () => newSessionState.typebotsQueue[0].typebot.variables,
|
||||
}
|
||||
let logs: NonNullable<ContinueChatResponse['logs']> = []
|
||||
const logsStore: LogsStore = {
|
||||
|
||||
Reference in New Issue
Block a user