Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(webhooks): dedup and custom ack configuration#3525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,7 +22,7 @@ export class TriggerBlockHandler implements BlockHandler { | ||
| } | ||
| const existingState = ctx.blockStates.get(block.id) | ||
| if (existingState?.output && Object.keys(existingState.output).length > 0) { | ||
| if (existingState?.output) { | ||
| return existingState.output | ||
| } | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1038,7 +1038,7 @@ export async function queueWebhookExecution( | ||
| } | ||
| } | ||
| const headers = Object.fromEntries(request.headers.entries()) | ||
| const { 'x-sim-idempotency-key': _, ...headers } = Object.fromEntries(request.headers.entries()) | ||
| // For Microsoft Teams Graph notifications, extract unique identifiers for idempotency | ||
| if ( | ||
| @@ -1056,9 +1056,20 @@ export async function queueWebhookExecution( | ||
| } | ||
| } | ||
| // Extract credentialId from webhook config | ||
| // Note: Each webhook now has its own credentialId (credential sets are fanned out at save time) | ||
| const providerConfig = (foundWebhook.providerConfig as Record<string, any>) || {} | ||
| if (foundWebhook.provider === 'generic') { | ||
| const idempotencyField = providerConfig.idempotencyField as string | undefined | ||
| if (idempotencyField && body) { | ||
| const value = idempotencyField | ||
| .split('.') | ||
| .reduce((acc: any, key: string) => acc?.[key], body) | ||
| if (value !== undefined && value !== null && typeof value !== 'object') { | ||
| headers['x-sim-idempotency-key'] = String(value) | ||
| } | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const credentialId = providerConfig.credentialId as string | undefined | ||
| let credentialAccountUserId: string | undefined | ||
| if (credentialId) { | ||
| @@ -1204,6 +1215,26 @@ export async function queueWebhookExecution( | ||
| }) | ||
| } | ||
| if (foundWebhook.provider === 'generic' && providerConfig.responseMode === 'custom') { | ||
| const rawCode = Number(providerConfig.responseStatusCode) || 200 | ||
| const statusCode = rawCode >= 100 && rawCode <= 599 ? rawCode : 200 | ||
| const responseBody = (providerConfig.responseBody as string | undefined)?.trim() | ||
| if (!responseBody) { | ||
| return new NextResponse(null, { status: statusCode }) | ||
| } | ||
| try { | ||
| const parsed = JSON.parse(responseBody) | ||
| return NextResponse.json(parsed, { status: statusCode }) | ||
| } catch { | ||
| return new NextResponse(responseBody, { | ||
| status: statusCode, | ||
| headers: { 'Content-Type': 'text/plain' }, | ||
| }) | ||
| } | ||
| } | ||
| return NextResponse.json({ message: 'Webhook processed' }) | ||
| } catch (error: any) { | ||
| logger.error(`[${options.requestId}] Failed to queue webhook execution:`, error) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -496,7 +496,14 @@ export function normalizeSubBlockValue(subBlockId: string, value: unknown): unkn | ||
| * @returns SubBlock fields excluding value and is_diff | ||
| */ | ||
| export function extractSubBlockRest(subBlock: Record<string, unknown>): Record<string, unknown> { | ||
| const { value: _v, is_diff: _sd, ...rest } = subBlock as SubBlockWithDiffMarker | ||
| const { | ||
| value: _v, | ||
| is_diff: _sd, | ||
| type: _type, | ||
| ...rest | ||
| } = subBlock as SubBlockWithDiffMarker & { | ||
| type?: unknown | ||
| } | ||
| return rest | ||
| } | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -49,6 +49,49 @@ export const genericWebhookTrigger: TriggerConfig = { | ||
| required: false, | ||
| mode: 'trigger', | ||
| }, | ||
| { | ||
| id: 'idempotencyField', | ||
| title: 'Deduplication Field (Optional)', | ||
| type: 'short-input', | ||
| placeholder: 'e.g. event.id', | ||
| description: | ||
| 'Dot-notation path to a unique field in the payload for deduplication. If the same value is seen within 7 days, the duplicate webhook will be skipped.', | ||
| required: false, | ||
| mode: 'trigger', | ||
| }, | ||
| { | ||
| id: 'responseMode', | ||
| title: 'Acknowledgement', | ||
| type: 'dropdown', | ||
| options: [ | ||
| { label: 'Default', id: 'default' }, | ||
| { label: 'Custom', id: 'custom' }, | ||
| ], | ||
| defaultValue: 'default', | ||
| mode: 'trigger', | ||
| }, | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| { | ||
| id: 'responseStatusCode', | ||
| title: 'Response Status Code', | ||
| type: 'short-input', | ||
| placeholder: '200 (default)', | ||
| description: | ||
| 'HTTP status code (100–599) to return to the webhook caller. Defaults to 200 if empty or invalid.', | ||
| required: false, | ||
| mode: 'trigger', | ||
| condition: { field: 'responseMode', value: 'custom' }, | ||
| }, | ||
| { | ||
| id: 'responseBody', | ||
| title: 'Response Body', | ||
| type: 'code', | ||
| language: 'json', | ||
| placeholder: '{"ok": true}', | ||
| description: 'JSON body to return to the webhook caller. Leave empty for no body.', | ||
| required: false, | ||
| mode: 'trigger', | ||
| condition: { field: 'responseMode', value: 'custom' }, | ||
| }, | ||
| { | ||
| id: 'inputFormat', | ||
| title: 'Input Format', | ||
| @@ -76,7 +119,7 @@ export const genericWebhookTrigger: TriggerConfig = { | ||
| 'The webhook will receive any HTTP method (GET, POST, PUT, DELETE, etc.).', | ||
| 'All request data (headers, body, query parameters) will be available in your workflow.', | ||
| 'If authentication is enabled, include the token in requests using either the custom header or "Authorization: Bearer TOKEN".', | ||
| 'Common fields like "event", "id", and "data" will be automatically extracted from the payload when available.', | ||
| 'To deduplicate incoming events, set the Deduplication Field to the dot-notation path of a unique identifier in the payload (e.g. "event.id"). Duplicate values within 7 days will be skipped.', | ||
| ] | ||
| .map( | ||
| (instruction, index) => | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.