@@ -305,48 +305,6 @@ export async function POST(
305305 }
306306 }
307307
308- // For Gmail: Process with specific email handling
309- if ( isGmailWebhook ) {
310- try {
311- logger . info ( `[${ requestId } ] Gmail webhook request received for webhook: ${ foundWebhook . id } ` )
312-
313- const webhookSecret = foundWebhook . secret
314- if ( webhookSecret ) {
315- const secretHeader = request . headers . get ( 'X-Webhook-Secret' )
316- if ( secretHeader !== webhookSecret ) {
317- logger . warn ( `[${ requestId } ] Invalid webhook secret` )
318- return new NextResponse ( 'Unauthorized' , { status : 401 } )
319- }
320- }
321-
322- if ( body . email ) {
323- logger . info ( `[${ requestId } ] Processing Gmail email` , {
324- emailId : body . email . id ,
325- subject :
326- body . email ?. payload ?. headers ?. find ( ( h : any ) => h . name === 'Subject' ) ?. value ||
327- 'No subject' ,
328- } )
329-
330- const executionId = uuidv4 ( )
331- logger . info ( `[${ requestId } ] Executing workflow ${ foundWorkflow . id } for Gmail email` )
332-
333- return await processWebhook (
334- foundWebhook ,
335- foundWorkflow ,
336- body ,
337- request ,
338- executionId ,
339- requestId
340- )
341- }
342- logger . warn ( `[${ requestId } ] Invalid Gmail webhook payload format` )
343- return new NextResponse ( 'Invalid payload format' , { status : 400 } )
344- } catch ( error : any ) {
345- logger . error ( `[${ requestId } ] Error processing Gmail webhook` , error )
346- return new NextResponse ( `Internal server error: ${ error . message } ` , { status : 500 } )
347- }
348- }
349-
350308 // --- For all other webhook types: Use async processing with timeout ---
351309
352310 // Create timeout promise for fast initial response (2.5 seconds)
@@ -370,7 +328,38 @@ export async function POST(
370328 if ( whatsappDuplicateResponse ) {
371329 return whatsappDuplicateResponse
372330 }
331+ } else if ( foundWebhook . provider === 'gmail' ) {
332+ // Gmail-specific validation and logging
333+ logger . info ( `[${ requestId } ] Gmail webhook request received for webhook: ${ foundWebhook . id } ` )
334+
335+ const webhookSecret = foundWebhook . secret
336+ if ( webhookSecret ) {
337+ const secretHeader = request . headers . get ( 'X-Webhook-Secret' )
338+ if ( secretHeader !== webhookSecret ) {
339+ logger . warn ( `[${ requestId } ] Invalid webhook secret` )
340+ return new NextResponse ( 'Unauthorized' , { status : 401 } )
341+ }
342+ }
343+
344+ if ( ! body . email ) {
345+ logger . warn ( `[${ requestId } ] Invalid Gmail webhook payload format` )
346+ return new NextResponse ( 'Invalid payload format' , { status : 400 } )
347+ }
348+
349+ logger . info ( `[${ requestId } ] Processing Gmail email` , {
350+ emailId : body . email . id ,
351+ subject :
352+ body . email ?. payload ?. headers ?. find ( ( h : any ) => h . name === 'Subject' ) ?. value ||
353+ 'No subject' ,
354+ } )
355+
356+ // Gmail deduplication using generic method
357+ const genericDuplicateResponse = await processGenericDeduplication ( requestId , path , body )
358+ if ( genericDuplicateResponse ) {
359+ return genericDuplicateResponse
360+ }
373361 } else if ( foundWebhook . provider !== 'slack' ) {
362+ // Generic deduplication for all other providers
374363 const genericDuplicateResponse = await processGenericDeduplication ( requestId , path , body )
375364 if ( genericDuplicateResponse ) {
376365 return genericDuplicateResponse
0 commit comments