mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
feat: adiciona headers no cadastro de webhook da instância
This commit is contained in:
parent
a9e4860a77
commit
65c6ecff88
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ lerna-debug.log*
|
|||||||
|
|
||||||
# Package
|
# Package
|
||||||
/yarn.lock
|
/yarn.lock
|
||||||
|
/pnpm-lock.yaml
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
|
|
||||||
# IDEs
|
# IDEs
|
||||||
|
@ -181,6 +181,7 @@ model MessageUpdate {
|
|||||||
model Webhook {
|
model Webhook {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
url String @db.VarChar(500)
|
url String @db.VarChar(500)
|
||||||
|
headers Json? @db.Json
|
||||||
enabled Boolean? @default(true)
|
enabled Boolean? @default(true)
|
||||||
events Json? @db.Json
|
events Json? @db.Json
|
||||||
webhookByEvents Boolean? @default(false)
|
webhookByEvents Boolean? @default(false)
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Webhook" ADD COLUMN "headers" JSONB;
|
@ -180,6 +180,7 @@ model MessageUpdate {
|
|||||||
model Webhook {
|
model Webhook {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
url String @db.VarChar(500)
|
url String @db.VarChar(500)
|
||||||
|
headers Json? @db.JsonB
|
||||||
enabled Boolean? @default(true) @db.Boolean
|
enabled Boolean? @default(true) @db.Boolean
|
||||||
events Json? @db.JsonB
|
events Json? @db.JsonB
|
||||||
webhookByEvents Boolean? @default(false) @db.Boolean
|
webhookByEvents Boolean? @default(false) @db.Boolean
|
||||||
|
@ -151,6 +151,7 @@ export class InstanceController {
|
|||||||
hash,
|
hash,
|
||||||
webhook: {
|
webhook: {
|
||||||
webhookUrl: instanceData?.webhook?.url,
|
webhookUrl: instanceData?.webhook?.url,
|
||||||
|
webhookHeaders: instanceData?.webhook?.headers,
|
||||||
webhookByEvents: instanceData?.webhook?.byEvents,
|
webhookByEvents: instanceData?.webhook?.byEvents,
|
||||||
webhookBase64: instanceData?.webhook?.base64,
|
webhookBase64: instanceData?.webhook?.base64,
|
||||||
},
|
},
|
||||||
@ -238,6 +239,7 @@ export class InstanceController {
|
|||||||
hash,
|
hash,
|
||||||
webhook: {
|
webhook: {
|
||||||
webhookUrl: instanceData?.webhook?.url,
|
webhookUrl: instanceData?.webhook?.url,
|
||||||
|
webhookHeaders: instanceData?.webhook?.headers,
|
||||||
webhookByEvents: instanceData?.webhook?.byEvents,
|
webhookByEvents: instanceData?.webhook?.byEvents,
|
||||||
webhookBase64: instanceData?.webhook?.base64,
|
webhookBase64: instanceData?.webhook?.base64,
|
||||||
},
|
},
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import { Constructor } from '@api/integrations/integration.dto';
|
import { Constructor } from '@api/integrations/integration.dto';
|
||||||
|
import { JsonValue } from '@prisma/client/runtime/library';
|
||||||
|
|
||||||
export class EventDto {
|
export class EventDto {
|
||||||
webhook?: {
|
webhook?: {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
url?: string;
|
url?: string;
|
||||||
|
headers?: JsonValue;
|
||||||
byEvents?: boolean;
|
byEvents?: boolean;
|
||||||
base64?: boolean;
|
base64?: boolean;
|
||||||
};
|
};
|
||||||
@ -30,6 +32,7 @@ export function EventInstanceMixin<TBase extends Constructor>(Base: TBase) {
|
|||||||
webhook?: {
|
webhook?: {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
|
headers?: JsonValue;
|
||||||
url?: string;
|
url?: string;
|
||||||
byEvents?: boolean;
|
byEvents?: boolean;
|
||||||
base64?: boolean;
|
base64?: boolean;
|
||||||
|
@ -126,6 +126,7 @@ export class EventManager {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
events: data.webhook?.events,
|
events: data.webhook?.events,
|
||||||
url: data.webhook?.url,
|
url: data.webhook?.url,
|
||||||
|
headers: data.webhook?.headers,
|
||||||
base64: data.webhook?.base64,
|
base64: data.webhook?.base64,
|
||||||
byEvents: data.webhook?.byEvents,
|
byEvents: data.webhook?.byEvents,
|
||||||
},
|
},
|
||||||
|
@ -38,6 +38,7 @@ export class WebhookController extends EventController implements EventControlle
|
|||||||
enabled: data.webhook?.enabled,
|
enabled: data.webhook?.enabled,
|
||||||
events: data.webhook?.events,
|
events: data.webhook?.events,
|
||||||
url: data.webhook?.url,
|
url: data.webhook?.url,
|
||||||
|
headers: data.webhook?.headers,
|
||||||
webhookBase64: data.webhook.base64,
|
webhookBase64: data.webhook.base64,
|
||||||
webhookByEvents: data.webhook.byEvents,
|
webhookByEvents: data.webhook.byEvents,
|
||||||
},
|
},
|
||||||
@ -46,6 +47,7 @@ export class WebhookController extends EventController implements EventControlle
|
|||||||
events: data.webhook?.events,
|
events: data.webhook?.events,
|
||||||
instanceId: this.monitor.waInstances[instanceName].instanceId,
|
instanceId: this.monitor.waInstances[instanceName].instanceId,
|
||||||
url: data.webhook?.url,
|
url: data.webhook?.url,
|
||||||
|
headers: data.webhook?.headers,
|
||||||
webhookBase64: data.webhook.base64,
|
webhookBase64: data.webhook.base64,
|
||||||
webhookByEvents: data.webhook.byEvents,
|
webhookByEvents: data.webhook.byEvents,
|
||||||
},
|
},
|
||||||
@ -71,6 +73,7 @@ export class WebhookController extends EventController implements EventControlle
|
|||||||
|
|
||||||
const webhookConfig = configService.get<Webhook>('WEBHOOK');
|
const webhookConfig = configService.get<Webhook>('WEBHOOK');
|
||||||
const webhookLocal = instance?.events;
|
const webhookLocal = instance?.events;
|
||||||
|
const webhookHeaders = instance?.headers;
|
||||||
const we = event.replace(/[.-]/gm, '_').toUpperCase();
|
const we = event.replace(/[.-]/gm, '_').toUpperCase();
|
||||||
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
||||||
const enabledLog = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
const enabledLog = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
||||||
@ -108,7 +111,10 @@ export class WebhookController extends EventController implements EventControlle
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (instance?.enabled && isURL(instance.url, { require_tld: false })) {
|
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);
|
await httpService.post('', webhookData);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { InstanceDto } from '@api/dto/instance.dto';
|
|||||||
import { EventDto } from '@api/integrations/event/event.dto';
|
import { EventDto } from '@api/integrations/event/event.dto';
|
||||||
import { HttpStatus } from '@api/routes/index.router';
|
import { HttpStatus } from '@api/routes/index.router';
|
||||||
import { eventManager } from '@api/server.module';
|
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 { instanceSchema, webhookSchema } from '@validate/validate.schema';
|
||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ export const webhookSchema: JSONSchema7 = {
|
|||||||
properties: {
|
properties: {
|
||||||
enabled: { type: 'boolean' },
|
enabled: { type: 'boolean' },
|
||||||
url: { type: 'string' },
|
url: { type: 'string' },
|
||||||
|
headers: { type: 'object' },
|
||||||
byEvents: { type: 'boolean' },
|
byEvents: { type: 'boolean' },
|
||||||
base64: { type: 'boolean' },
|
base64: { type: 'boolean' },
|
||||||
events: {
|
events: {
|
||||||
|
@ -94,6 +94,7 @@ export declare namespace wa {
|
|||||||
|
|
||||||
export type LocalWebHook = LocalEvent & {
|
export type LocalWebHook = LocalEvent & {
|
||||||
url?: string;
|
url?: string;
|
||||||
|
headers?: JsonValue;
|
||||||
webhookByEvents?: boolean;
|
webhookByEvents?: boolean;
|
||||||
webhookBase64?: boolean;
|
webhookBase64?: boolean;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user