The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
bug fix webhook response not sending data to tinybird (#7952)
Ana Sofia Marin Alexandre18cfe79b8023
diff --git a/packages/twenty-front/src/modules/settings/developers/webhook/utils/__tests__/fetchGraphDataOrThrow.test.js b/packages/twenty-front/src/modules/settings/developers/webhook/utils/__tests__/fetchGraphDataOrThrow.test.jsindex 365c964d2c9..89e493e65af 100644--- a/packages/twenty-front/src/modules/settings/developers/webhook/utils/__tests__/fetchGraphDataOrThrow.test.js+++ b/packages/twenty-front/src/modules/settings/developers/webhook/utils/__tests__/fetchGraphDataOrThrow.test.js@@ -7,6 +7,7 @@ global.fetch = jest.fn();describe('fetchGraphDataOrThrow', () => {const mockWebhookId = 'test-webhook-id';const mockWindowLength = '7D';+ const mockTinybirdJwt = 'test-jwt';beforeEach(() => {jest.resetAllMocks();@@ -27,6 +28,7 @@ describe('fetchGraphDataOrThrow', () => {const result = await fetchGraphDataOrThrow({webhookId: mockWebhookId,windowLength: mockWindowLength,+ tinybirdJwt: mockTinybirdJwt,});expect(global.fetch).toHaveBeenCalledWith(@@ -71,6 +73,7 @@ describe('fetchGraphDataOrThrow', () => {fetchGraphDataOrThrow({webhookId: mockWebhookId,windowLength: mockWindowLength,+ tinybirdJwt: mockTinybirdJwt,}),).rejects.toThrow('Something went wrong while fetching webhook usage');});@@ -85,13 +88,14 @@ describe('fetchGraphDataOrThrow', () => {await fetchGraphDataOrThrow({webhookId: mockWebhookId,windowLength: '1D',+ tinybirdJwt: mockTinybirdJwt,});expect(global.fetch).toHaveBeenCalledWith(expect.stringContaining(new URLSearchParams({...WEBHOOK_GRAPH_API_OPTIONS_MAP['1D'],- webhookIdRequest: mockWebhookId,+ webhookId: mockWebhookId,}).toString(),),expect.any(Object),diff --git a/packages/twenty-front/src/modules/settings/developers/webhook/utils/fetchGraphDataOrThrow.ts b/packages/twenty-front/src/modules/settings/developers/webhook/utils/fetchGraphDataOrThrow.tsindex 4b66c4b9b0d..083b061da8d 100644--- a/packages/twenty-front/src/modules/settings/developers/webhook/utils/fetchGraphDataOrThrow.ts+++ b/packages/twenty-front/src/modules/settings/developers/webhook/utils/fetchGraphDataOrThrow.ts@@ -14,7 +14,7 @@ export const fetchGraphDataOrThrow = async ({}: fetchGraphDataOrThrowProps) => {const queryString = new URLSearchParams({...WEBHOOK_GRAPH_API_OPTIONS_MAP[windowLength],- webhookIdRequest: webhookId,+ webhookId,}).toString();const response = await fetch(diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/jobs/call-webhook.job.ts b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/jobs/call-webhook.job.tsindex e03c83204e8..f0ec8317a62 100644--- a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/jobs/call-webhook.job.ts+++ b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/jobs/call-webhook.job.ts@@ -26,18 +26,24 @@ export class CallWebhookJob {@Process(CallWebhookJob.name)async handle(data: CallWebhookJobData): Promise<void> {+ const commonPayload = {+ url: data.targetUrl,+ webhookId: data.webhookId,+ eventName: data.eventName,+ };+try {const response = await this.httpService.axiosRef.post(data.targetUrl,data,);+ const success = response.status >= 200 && response.status < 300;const eventInput = {action: 'webhook.response',payload: {status: response.status,- url: data.targetUrl,- webhookId: data.webhookId,- eventName: data.eventName,+ success,+ ...commonPayload,},};@@ -46,10 +52,9 @@ export class CallWebhookJob {const eventInput = {action: 'webhook.response',payload: {- status: err.response.status,- url: data.targetUrl,- webhookId: data.webhookId,- eventName: data.eventName,+ success: false,+ ...commonPayload,+ ...(err.response && { status: err.response.status }),},};