bug fix webhook response not sending data to tinybird (#7952)
Solves https://github.com/twentyhq/private-issues/issues/118 **TLDR** Fix webhook response not sending data to tinybird when the url is not a link. **Changes in Tinybird:** - Add column Success to webhook payload (boolean) - Changed the parameter WebhookIdRequest to WebhookId in the getWebhooksResponse api point. - Those changes can be seen in the tinybird workspace twenty_analytics_playground **In order to test** 1. Set ANALYTICS_ENABLED to true 2. Set TINYBIRD_INGEST_TOKEN to your token from the workspace twenty_analytics_playground 3. Set TINYBIRD_GENERATE_JWT_TOKEN to the admin kwt token from the workspace twenty_analytics_playground 4. Set TINYBIRD_WORKSPACE_UUID to the UUID of twenty_analytics_playground 5. Create a Webhook in twenty and set wich events it needs to track 6. Run twenty-worker in order to make the webhooks work. 7. Do your tasks in order to populate the data 8. Look at your webhooks in settings>api and webhooks> your webhook and the statistics should be displayed
This commit is contained in:
committed by
GitHub
parent
f0a2d38471
commit
18cfe79b80
@ -7,6 +7,7 @@ global.fetch = jest.fn();
|
|||||||
describe('fetchGraphDataOrThrow', () => {
|
describe('fetchGraphDataOrThrow', () => {
|
||||||
const mockWebhookId = 'test-webhook-id';
|
const mockWebhookId = 'test-webhook-id';
|
||||||
const mockWindowLength = '7D';
|
const mockWindowLength = '7D';
|
||||||
|
const mockTinybirdJwt = 'test-jwt';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
@ -27,6 +28,7 @@ describe('fetchGraphDataOrThrow', () => {
|
|||||||
const result = await fetchGraphDataOrThrow({
|
const result = await fetchGraphDataOrThrow({
|
||||||
webhookId: mockWebhookId,
|
webhookId: mockWebhookId,
|
||||||
windowLength: mockWindowLength,
|
windowLength: mockWindowLength,
|
||||||
|
tinybirdJwt: mockTinybirdJwt,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(global.fetch).toHaveBeenCalledWith(
|
expect(global.fetch).toHaveBeenCalledWith(
|
||||||
@ -71,6 +73,7 @@ describe('fetchGraphDataOrThrow', () => {
|
|||||||
fetchGraphDataOrThrow({
|
fetchGraphDataOrThrow({
|
||||||
webhookId: mockWebhookId,
|
webhookId: mockWebhookId,
|
||||||
windowLength: mockWindowLength,
|
windowLength: mockWindowLength,
|
||||||
|
tinybirdJwt: mockTinybirdJwt,
|
||||||
}),
|
}),
|
||||||
).rejects.toThrow('Something went wrong while fetching webhook usage');
|
).rejects.toThrow('Something went wrong while fetching webhook usage');
|
||||||
});
|
});
|
||||||
@ -85,13 +88,14 @@ describe('fetchGraphDataOrThrow', () => {
|
|||||||
await fetchGraphDataOrThrow({
|
await fetchGraphDataOrThrow({
|
||||||
webhookId: mockWebhookId,
|
webhookId: mockWebhookId,
|
||||||
windowLength: '1D',
|
windowLength: '1D',
|
||||||
|
tinybirdJwt: mockTinybirdJwt,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(global.fetch).toHaveBeenCalledWith(
|
expect(global.fetch).toHaveBeenCalledWith(
|
||||||
expect.stringContaining(
|
expect.stringContaining(
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
...WEBHOOK_GRAPH_API_OPTIONS_MAP['1D'],
|
...WEBHOOK_GRAPH_API_OPTIONS_MAP['1D'],
|
||||||
webhookIdRequest: mockWebhookId,
|
webhookId: mockWebhookId,
|
||||||
}).toString(),
|
}).toString(),
|
||||||
),
|
),
|
||||||
expect.any(Object),
|
expect.any(Object),
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export const fetchGraphDataOrThrow = async ({
|
|||||||
}: fetchGraphDataOrThrowProps) => {
|
}: fetchGraphDataOrThrowProps) => {
|
||||||
const queryString = new URLSearchParams({
|
const queryString = new URLSearchParams({
|
||||||
...WEBHOOK_GRAPH_API_OPTIONS_MAP[windowLength],
|
...WEBHOOK_GRAPH_API_OPTIONS_MAP[windowLength],
|
||||||
webhookIdRequest: webhookId,
|
webhookId,
|
||||||
}).toString();
|
}).toString();
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
|
|||||||
@ -26,18 +26,24 @@ export class CallWebhookJob {
|
|||||||
|
|
||||||
@Process(CallWebhookJob.name)
|
@Process(CallWebhookJob.name)
|
||||||
async handle(data: CallWebhookJobData): Promise<void> {
|
async handle(data: CallWebhookJobData): Promise<void> {
|
||||||
|
const commonPayload = {
|
||||||
|
url: data.targetUrl,
|
||||||
|
webhookId: data.webhookId,
|
||||||
|
eventName: data.eventName,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.httpService.axiosRef.post(
|
const response = await this.httpService.axiosRef.post(
|
||||||
data.targetUrl,
|
data.targetUrl,
|
||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
|
const success = response.status >= 200 && response.status < 300;
|
||||||
const eventInput = {
|
const eventInput = {
|
||||||
action: 'webhook.response',
|
action: 'webhook.response',
|
||||||
payload: {
|
payload: {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
url: data.targetUrl,
|
success,
|
||||||
webhookId: data.webhookId,
|
...commonPayload,
|
||||||
eventName: data.eventName,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,10 +52,9 @@ export class CallWebhookJob {
|
|||||||
const eventInput = {
|
const eventInput = {
|
||||||
action: 'webhook.response',
|
action: 'webhook.response',
|
||||||
payload: {
|
payload: {
|
||||||
status: err.response.status,
|
success: false,
|
||||||
url: data.targetUrl,
|
...commonPayload,
|
||||||
webhookId: data.webhookId,
|
...(err.response && { status: err.response.status }),
|
||||||
eventName: data.eventName,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user