Merge pull request #802 from judsonjuniorr/v2-webhook-fix

Fix webhook validation
This commit is contained in:
Davidson Gomes 2024-08-21 14:01:17 -03:00 committed by GitHub
commit 9a09a6662a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 12 deletions

View File

@ -81,7 +81,11 @@ export class WebhookController extends EventController implements EventControlle
local,
}: EmitData): Promise<void> {
const instanceWebhook = await this.get(instanceName);
const webhookGlobal = configService.get<Webhook>('WEBHOOK');
if (!instanceWebhook || !instanceWebhook.enabled) {
return;
}
const webhookConfig = configService.get<Webhook>('WEBHOOK');
const webhookLocal = instanceWebhook?.events;
const we = event.replace(/[.-]/gm, '_').toUpperCase();
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
@ -141,16 +145,12 @@ export class WebhookController extends EventController implements EventControlle
}
}
if (webhookGlobal.GLOBAL?.ENABLED) {
if (webhookGlobal.EVENTS[we]) {
const globalWebhook = configService.get<Webhook>('WEBHOOK').GLOBAL;
if (webhookConfig.GLOBAL?.ENABLED) {
if (webhookConfig.EVENTS[we]) {
let globalURL = webhookConfig.GLOBAL.URL;
let globalURL;
if (webhookGlobal.GLOBAL.WEBHOOK_BY_EVENTS) {
globalURL = `${globalWebhook.URL}/${transformedWe}`;
} else {
globalURL = globalWebhook.URL;
if (webhookConfig.GLOBAL.WEBHOOK_BY_EVENTS) {
globalURL = `${globalURL}/${transformedWe}`;
}
if (enabledLog) {
@ -164,7 +164,7 @@ export class WebhookController extends EventController implements EventControlle
}
try {
if (globalWebhook && globalWebhook?.ENABLED && isURL(globalURL)) {
if (isURL(globalURL)) {
const httpService = axios.create({ baseURL: globalURL });
await httpService.post('', webhookData);

View File

@ -1,7 +1,7 @@
import { RouterBroker } from '@api/abstract/abstract.router';
import { InstanceDto } from '@api/dto/instance.dto';
import { webhookController } from '@api/server.module';
import { HttpStatus } from '@api/routes/index.router';
import { webhookController } from '@api/server.module';
import { ConfigService, WaBusiness } from '@config/env.config';
import { instanceSchema, webhookSchema } from '@validate/validate.schema';
import { RequestHandler, Router } from 'express';