@@ -24,6 +24,7 @@ import {
2424 validateTypeformSignature ,
2525 verifyProviderWebhook ,
2626} from '@/lib/webhooks/utils.server'
27+ import { getWorkspaceBilledAccountUserId } from '@/lib/workspaces/utils'
2728import { executeWebhookJob } from '@/background/webhook-execution'
2829import { resolveEnvVarReferences } from '@/executor/utils/reference-validation'
2930import { isGitHubEventMatch } from '@/triggers/github/utils'
@@ -1003,10 +1004,23 @@ export async function queueWebhookExecution(
10031004 }
10041005 }
10051006
1007+ if ( ! foundWorkflow . workspaceId ) {
1008+ logger . error ( `[${ options . requestId } ] Workflow ${ foundWorkflow . id } has no workspaceId` )
1009+ return NextResponse . json ( { error : 'Workflow has no associated workspace' } , { status : 500 } )
1010+ }
1011+
1012+ const actorUserId = await getWorkspaceBilledAccountUserId ( foundWorkflow . workspaceId )
1013+ if ( ! actorUserId ) {
1014+ logger . error (
1015+ `[${ options . requestId } ] No billing account for workspace ${ foundWorkflow . workspaceId } `
1016+ )
1017+ return NextResponse . json ( { error : 'Unable to resolve billing account' } , { status : 500 } )
1018+ }
1019+
10061020 const payload = {
10071021 webhookId : foundWebhook . id ,
10081022 workflowId : foundWorkflow . id ,
1009- userId : foundWorkflow . userId ,
1023+ userId : actorUserId ,
10101024 provider : foundWebhook . provider ,
10111025 body,
10121026 headers,
@@ -1017,7 +1031,7 @@ export async function queueWebhookExecution(
10171031
10181032 const jobQueue = await getJobQueue ( )
10191033 const jobId = await jobQueue . enqueue ( 'webhook-execution' , payload , {
1020- metadata : { workflowId : foundWorkflow . id , userId : foundWorkflow . userId } ,
1034+ metadata : { workflowId : foundWorkflow . id , userId : actorUserId } ,
10211035 } )
10221036 logger . info (
10231037 `[${ options . requestId } ] Queued webhook execution task ${ jobId } for ${ foundWebhook . provider } webhook`
0 commit comments