fix: Fetch webhooks by flow id
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import path from 'node:path';
|
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { IRequest } from '@automatisch/types';
|
import { IRequest } from '@automatisch/types';
|
||||||
|
|
||||||
import Step from '../../models/step';
|
import Flow from '../../models/flow';
|
||||||
import logger from '../../helpers/logger';
|
import logger from '../../helpers/logger';
|
||||||
import handler from '../../helpers/webhook-handler';
|
import handler from '../../helpers/webhook-handler';
|
||||||
|
|
||||||
@@ -13,19 +12,20 @@ export default async (request: IRequest, response: Response) => {
|
|||||||
query: request.query,
|
query: request.query,
|
||||||
params: request.params,
|
params: request.params,
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.debug(`Handling incoming webhook request at ${request.originalUrl}.`);
|
logger.debug(`Handling incoming webhook request at ${request.originalUrl}.`);
|
||||||
logger.debug(JSON.stringify(computedRequestPayload, null, 2));
|
logger.debug(JSON.stringify(computedRequestPayload, null, 2));
|
||||||
|
|
||||||
const flowId = request.params.flowId;
|
const flowId = request.params.flowId;
|
||||||
const triggerStep = await Step.query()
|
const flow = await Flow.query().findById(flowId).throwIfNotFound();
|
||||||
.findOne({
|
const triggerStep = await flow.getTriggerStep();
|
||||||
webhook_path: path.join(request.baseUrl, request.path),
|
|
||||||
})
|
|
||||||
.throwIfNotFound();
|
|
||||||
const connection = await triggerStep.$relatedQuery('connection');
|
|
||||||
|
|
||||||
if (!await connection.verifyWebhook(request)) {
|
if (triggerStep.appKey !== 'webhook') {
|
||||||
return response.sendStatus(401);
|
const connection = await triggerStep.$relatedQuery('connection');
|
||||||
|
|
||||||
|
if (!(await connection.verifyWebhook(request))) {
|
||||||
|
return response.sendStatus(401);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await handler(flowId, request, response);
|
await handler(flowId, request, response);
|
||||||
|
Reference in New Issue
Block a user