From 31ec93e68805cc9c0807c503fc5941f3afa6d29b Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sun, 9 Mar 2025 17:22:23 -0700 Subject: [PATCH] fix(webhook): fix webhook execution to be identical to scheduled, manual executions besides pre-processing --- app/api/webhooks/trigger/[path]/route.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/api/webhooks/trigger/[path]/route.ts b/app/api/webhooks/trigger/[path]/route.ts index 60c073aba..af1e31eae 100644 --- a/app/api/webhooks/trigger/[path]/route.ts +++ b/app/api/webhooks/trigger/[path]/route.ts @@ -8,7 +8,6 @@ import { db } from '@/db' import { environment, webhook, workflow } from '@/db/schema' import { Executor } from '@/executor' import { Serializer } from '@/serializer' -import { SerializedWorkflow } from '@/serializer/types' export const dynamic = 'force-dynamic' @@ -252,10 +251,25 @@ export async function POST( } } + // Process the block states to extract values from subBlocks + const currentBlockStates = Object.entries(mergedStates).reduce( + (acc, [id, block]) => { + acc[id] = Object.entries(block.subBlocks).reduce( + (subAcc, [key, subBlock]) => { + subAcc[key] = subBlock.value + return subAcc + }, + {} as Record + ) + return acc + }, + {} as Record> + ) + // Serialize and execute the workflow const serializedWorkflow = new Serializer().serializeWorkflow(mergedStates as any, edges, loops) - const executor = new Executor(serializedWorkflow, mergedStates as any, decryptedEnvVars, input) + const executor = new Executor(serializedWorkflow, currentBlockStates, decryptedEnvVars, input) const result = await executor.execute(foundWorkflow.id) console.log(`Successfully executed workflow ${foundWorkflow.id}`)