mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 11:52:20 -06:00
feat: adiciona headers no cadastro de webhook da instância
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { Constructor } from '@api/integrations/integration.dto';
|
||||
import { JsonValue } from '@prisma/client/runtime/library';
|
||||
|
||||
export class EventDto {
|
||||
webhook?: {
|
||||
enabled?: boolean;
|
||||
events?: string[];
|
||||
url?: string;
|
||||
headers?: JsonValue;
|
||||
byEvents?: boolean;
|
||||
base64?: boolean;
|
||||
};
|
||||
@@ -30,6 +32,7 @@ export function EventInstanceMixin<TBase extends Constructor>(Base: TBase) {
|
||||
webhook?: {
|
||||
enabled?: boolean;
|
||||
events?: string[];
|
||||
headers?: JsonValue;
|
||||
url?: string;
|
||||
byEvents?: boolean;
|
||||
base64?: boolean;
|
||||
|
||||
@@ -126,6 +126,7 @@ export class EventManager {
|
||||
enabled: true,
|
||||
events: data.webhook?.events,
|
||||
url: data.webhook?.url,
|
||||
headers: data.webhook?.headers,
|
||||
base64: data.webhook?.base64,
|
||||
byEvents: data.webhook?.byEvents,
|
||||
},
|
||||
|
||||
@@ -38,6 +38,7 @@ export class WebhookController extends EventController implements EventControlle
|
||||
enabled: data.webhook?.enabled,
|
||||
events: data.webhook?.events,
|
||||
url: data.webhook?.url,
|
||||
headers: data.webhook?.headers,
|
||||
webhookBase64: data.webhook.base64,
|
||||
webhookByEvents: data.webhook.byEvents,
|
||||
},
|
||||
@@ -46,6 +47,7 @@ export class WebhookController extends EventController implements EventControlle
|
||||
events: data.webhook?.events,
|
||||
instanceId: this.monitor.waInstances[instanceName].instanceId,
|
||||
url: data.webhook?.url,
|
||||
headers: data.webhook?.headers,
|
||||
webhookBase64: data.webhook.base64,
|
||||
webhookByEvents: data.webhook.byEvents,
|
||||
},
|
||||
@@ -71,6 +73,7 @@ export class WebhookController extends EventController implements EventControlle
|
||||
|
||||
const webhookConfig = configService.get<Webhook>('WEBHOOK');
|
||||
const webhookLocal = instance?.events;
|
||||
const webhookHeaders = instance?.headers;
|
||||
const we = event.replace(/[.-]/gm, '_').toUpperCase();
|
||||
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
||||
const enabledLog = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
||||
@@ -108,7 +111,10 @@ export class WebhookController extends EventController implements EventControlle
|
||||
|
||||
try {
|
||||
if (instance?.enabled && isURL(instance.url, { require_tld: false })) {
|
||||
const httpService = axios.create({ baseURL });
|
||||
const httpService = axios.create({
|
||||
baseURL,
|
||||
headers: webhookHeaders as Record<string, string> | undefined,
|
||||
});
|
||||
|
||||
await httpService.post('', webhookData);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { EventDto } from '@api/integrations/event/event.dto';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { eventManager } from '@api/server.module';
|
||||
import { ConfigService, WaBusiness } from '@config/env.config';
|
||||
import { ConfigService } from '@config/env.config';
|
||||
import { instanceSchema, webhookSchema } from '@validate/validate.schema';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ export const webhookSchema: JSONSchema7 = {
|
||||
properties: {
|
||||
enabled: { type: 'boolean' },
|
||||
url: { type: 'string' },
|
||||
headers: { type: 'object' },
|
||||
byEvents: { type: 'boolean' },
|
||||
base64: { type: 'boolean' },
|
||||
events: {
|
||||
|
||||
Reference in New Issue
Block a user