MCPcopy Index your code
hub / github.com/simstudioai/sim / queueWebhookExecution

Function queueWebhookExecution

apps/sim/lib/webhooks/processor.ts:550–720  ·  view source on GitHub ↗
(
  foundWebhook: any,
  foundWorkflow: any,
  body: any,
  request: NextRequest,
  options: WebhookProcessorOptions
)

Source from the content-addressed store, hash-verified

548}
549
550export async function queueWebhookExecution(
551 foundWebhook: any,
552 foundWorkflow: any,
553 body: any,
554 request: NextRequest,
555 options: WebhookProcessorOptions
556): Promise<NextResponse> {
557 const providerConfig = (foundWebhook.providerConfig as Record<string, unknown>) || {}
558 const handler = getProviderHandler(foundWebhook.provider)
559
560 try {
561 if (handler.matchEvent) {
562 const result = await handler.matchEvent({
563 webhook: foundWebhook,
564 workflow: foundWorkflow,
565 body,
566 request,
567 requestId: options.requestId,
568 providerConfig,
569 })
570 if (result !== true) {
571 if (result instanceof NextResponse) {
572 return result
573 }
574 return NextResponse.json({
575 message: 'Event type does not match trigger configuration. Ignoring.',
576 })
577 }
578 }
579
580 const { 'x-sim-idempotency-key': _, ...headers } = Object.fromEntries(request.headers.entries())
581
582 if (handler.enrichHeaders) {
583 handler.enrichHeaders(
584 { webhook: foundWebhook, body, requestId: options.requestId, providerConfig },
585 headers
586 )
587 }
588
589 const credentialId = providerConfig.credentialId as string | undefined
590 const credentialSetId = foundWebhook.credentialSetId as string | undefined
591
592 if (credentialSetId) {
593 const billingCheck = await verifyCredentialSetBilling(credentialSetId)
594 if (!billingCheck.valid) {
595 logger.warn(
596 `[${options.requestId}] Credential set billing check failed: ${billingCheck.error}`
597 )
598 return NextResponse.json({ error: billingCheck.error }, { status: 403 })
599 }
600 }
601
602 const actorUserId = options.actorUserId
603 if (!actorUserId) {
604 logger.error(`[${options.requestId}] No actorUserId provided for webhook ${foundWebhook.id}`)
605 return NextResponse.json({ error: 'Unable to resolve billing account' }, { status: 500 })
606 }
607

Callers 2

processor.test.tsFile · 0.90
handleWebhookPostFunction · 0.90

Calls 15

getProviderHandlerFunction · 0.90
generateIdFunction · 0.90
isPollingWebhookProviderFunction · 0.90
shouldExecuteInlineFunction · 0.90
getJobQueueFunction · 0.90
getInlineJobQueueFunction · 0.90
executeWebhookJobFunction · 0.90
toErrorFunction · 0.90
matchEventMethod · 0.80
enrichHeadersMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected