mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
Merge pull request #869 from fmedeiros95/v2.0.0
feat: adds headers to the instance's webhook registration
This commit is contained in:
commit
63dac9d04f
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ lerna-debug.log*
|
||||
|
||||
# Package
|
||||
/yarn.lock
|
||||
/pnpm-lock.yaml
|
||||
/package-lock.json
|
||||
|
||||
# IDEs
|
||||
|
@ -181,6 +181,7 @@ model MessageUpdate {
|
||||
model Webhook {
|
||||
id String @id @default(cuid())
|
||||
url String @db.VarChar(500)
|
||||
headers Json? @db.Json
|
||||
enabled Boolean? @default(true)
|
||||
events Json? @db.Json
|
||||
webhookByEvents Boolean? @default(false)
|
||||
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" ADD COLUMN "headers" JSONB;
|
@ -180,6 +180,7 @@ model MessageUpdate {
|
||||
model Webhook {
|
||||
id String @id @default(cuid())
|
||||
url String @db.VarChar(500)
|
||||
headers Json? @db.JsonB
|
||||
enabled Boolean? @default(true) @db.Boolean
|
||||
events Json? @db.JsonB
|
||||
webhookByEvents Boolean? @default(false) @db.Boolean
|
||||
|
@ -151,6 +151,7 @@ export class InstanceController {
|
||||
hash,
|
||||
webhook: {
|
||||
webhookUrl: instanceData?.webhook?.url,
|
||||
webhookHeaders: instanceData?.webhook?.headers,
|
||||
webhookByEvents: instanceData?.webhook?.byEvents,
|
||||
webhookBase64: instanceData?.webhook?.base64,
|
||||
},
|
||||
@ -238,6 +239,7 @@ export class InstanceController {
|
||||
hash,
|
||||
webhook: {
|
||||
webhookUrl: instanceData?.webhook?.url,
|
||||
webhookHeaders: instanceData?.webhook?.headers,
|
||||
webhookByEvents: instanceData?.webhook?.byEvents,
|
||||
webhookBase64: instanceData?.webhook?.base64,
|
||||
},
|
||||
|
@ -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: {
|
||||
|
@ -94,6 +94,7 @@ export declare namespace wa {
|
||||
|
||||
export type LocalWebHook = LocalEvent & {
|
||||
url?: string;
|
||||
headers?: JsonValue;
|
||||
webhookByEvents?: boolean;
|
||||
webhookBase64?: boolean;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user