@@ -1475,35 +1475,39 @@ export async function processWebhook(
14751475 return new NextResponse ( 'No messages in WhatsApp payload' , { status : 200 } )
14761476 }
14771477
1478- // --- Execute Workflow ---
1478+ // --- Send immediate acknowledgment and execute workflow asynchronously ---
14791479 logger . info (
1480- `[${ requestId } ] Executing workflow ${ foundWorkflow . id } for webhook ${ foundWebhook . id } (Execution: ${ executionId } )`
1480+ `[${ requestId } ] Acknowledging webhook ${ foundWebhook . id } and executing workflow ${ foundWorkflow . id } asynchronously (Execution: ${ executionId } )`
14811481 )
14821482
1483- await executeWorkflowFromPayload (
1483+ // Execute workflow asynchronously without waiting for completion
1484+ executeWorkflowFromPayload (
14841485 foundWorkflow ,
14851486 input ,
14861487 executionId ,
14871488 requestId ,
14881489 foundWebhook . blockId
1489- )
1490-
1491- // Since executeWorkflowFromPayload handles logging and errors internally,
1492- // we just need to return a standard success response for synchronous webhooks.
1493- // Note: The actual result isn't typically returned in the webhook response itself.
1490+ ) . catch ( ( error ) => {
1491+ // Log any errors that occur during async execution
1492+ logger . error (
1493+ `[${ requestId } ] Error during async workflow execution for webhook ${ foundWebhook . id } (Execution: ${ executionId } )` ,
1494+ error
1495+ )
1496+ } )
14941497
1498+ // Return immediate acknowledgment to the webhook provider
14951499 // For Microsoft Teams outgoing webhooks, return the expected response format
14961500 if ( foundWebhook . provider === 'microsoftteams' ) {
14971501 return NextResponse . json (
14981502 {
14991503 type : 'message' ,
1500- text : 'Webhook processed successfully ' ,
1504+ text : 'Sim Studio ' ,
15011505 } ,
15021506 { status : 200 }
15031507 )
15041508 }
15051509
1506- return NextResponse . json ( { message : 'Webhook processed ' } , { status : 200 } )
1510+ return NextResponse . json ( { message : 'Webhook received ' } , { status : 200 } )
15071511 } catch ( error : any ) {
15081512 // Catch errors *before* calling executeWorkflowFromPayload (e.g., auth errors)
15091513 logger . error (
@@ -1516,7 +1520,7 @@ export async function processWebhook(
15161520 return NextResponse . json (
15171521 {
15181522 type : 'message' ,
1519- text : 'Webhook processing failed' ,
1523+ text : 'Request received but processing failed' ,
15201524 } ,
15211525 { status : 200 }
15221526 ) // Still return 200 to prevent Teams from showing additional error messages
0 commit comments