Skip to content

Commit bfcf99b

Browse files
committed
Merge branch 'v2.0.0' of github.com:EvolutionAPI/evolution-api into v2.0.0
2 parents 80ae86b + 63dac9d commit bfcf99b

File tree

11 files changed

+21
-2
lines changed

11 files changed

+21
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ lerna-debug.log*
2020

2121
# Package
2222
/yarn.lock
23+
/pnpm-lock.yaml
2324
/package-lock.json
2425

2526
# IDEs

prisma/mysql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ model MessageUpdate {
181181
model Webhook {
182182
id String @id @default(cuid())
183183
url String @db.VarChar(500)
184+
headers Json? @db.Json
184185
enabled Boolean? @default(true)
185186
events Json? @db.Json
186187
webhookByEvents Boolean? @default(false)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Webhook" ADD COLUMN "headers" JSONB;

prisma/postgresql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ model MessageUpdate {
180180
model Webhook {
181181
id String @id @default(cuid())
182182
url String @db.VarChar(500)
183+
headers Json? @db.JsonB
183184
enabled Boolean? @default(true) @db.Boolean
184185
events Json? @db.JsonB
185186
webhookByEvents Boolean? @default(false) @db.Boolean

src/api/controllers/instance.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export class InstanceController {
156156
hash,
157157
webhook: {
158158
webhookUrl: instanceData?.webhook?.url,
159+
webhookHeaders: instanceData?.webhook?.headers,
159160
webhookByEvents: instanceData?.webhook?.byEvents,
160161
webhookBase64: instanceData?.webhook?.base64,
161162
},
@@ -243,6 +244,7 @@ export class InstanceController {
243244
hash,
244245
webhook: {
245246
webhookUrl: instanceData?.webhook?.url,
247+
webhookHeaders: instanceData?.webhook?.headers,
246248
webhookByEvents: instanceData?.webhook?.byEvents,
247249
webhookBase64: instanceData?.webhook?.base64,
248250
},

src/api/integrations/event/event.dto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Constructor } from '@api/integrations/integration.dto';
2+
import { JsonValue } from '@prisma/client/runtime/library';
23

34
export class EventDto {
45
webhook?: {
56
enabled?: boolean;
67
events?: string[];
78
url?: string;
9+
headers?: JsonValue;
810
byEvents?: boolean;
911
base64?: boolean;
1012
};
@@ -30,6 +32,7 @@ export function EventInstanceMixin<TBase extends Constructor>(Base: TBase) {
3032
webhook?: {
3133
enabled?: boolean;
3234
events?: string[];
35+
headers?: JsonValue;
3336
url?: string;
3437
byEvents?: boolean;
3538
base64?: boolean;

src/api/integrations/event/event.manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class EventManager {
126126
enabled: true,
127127
events: data.webhook?.events,
128128
url: data.webhook?.url,
129+
headers: data.webhook?.headers,
129130
base64: data.webhook?.base64,
130131
byEvents: data.webhook?.byEvents,
131132
},

src/api/integrations/event/webhook/webhook.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class WebhookController extends EventController implements EventControlle
3838
enabled: data.webhook?.enabled,
3939
events: data.webhook?.events,
4040
url: data.webhook?.url,
41+
headers: data.webhook?.headers,
4142
webhookBase64: data.webhook.base64,
4243
webhookByEvents: data.webhook.byEvents,
4344
},
@@ -46,6 +47,7 @@ export class WebhookController extends EventController implements EventControlle
4647
events: data.webhook?.events,
4748
instanceId: this.monitor.waInstances[instanceName].instanceId,
4849
url: data.webhook?.url,
50+
headers: data.webhook?.headers,
4951
webhookBase64: data.webhook.base64,
5052
webhookByEvents: data.webhook.byEvents,
5153
},
@@ -71,6 +73,7 @@ export class WebhookController extends EventController implements EventControlle
7173

7274
const webhookConfig = configService.get<Webhook>('WEBHOOK');
7375
const webhookLocal = instance?.events;
76+
const webhookHeaders = instance?.headers;
7477
const we = event.replace(/[.-]/gm, '_').toUpperCase();
7578
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
7679
const enabledLog = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
@@ -108,7 +111,10 @@ export class WebhookController extends EventController implements EventControlle
108111

109112
try {
110113
if (instance?.enabled && isURL(instance.url, { require_tld: false })) {
111-
const httpService = axios.create({ baseURL });
114+
const httpService = axios.create({
115+
baseURL,
116+
headers: webhookHeaders as Record<string, string> | undefined,
117+
});
112118

113119
await httpService.post('', webhookData);
114120
}

src/api/integrations/event/webhook/webhook.router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InstanceDto } from '@api/dto/instance.dto';
33
import { EventDto } from '@api/integrations/event/event.dto';
44
import { HttpStatus } from '@api/routes/index.router';
55
import { eventManager } from '@api/server.module';
6-
import { ConfigService, WaBusiness } from '@config/env.config';
6+
import { ConfigService } from '@config/env.config';
77
import { instanceSchema, webhookSchema } from '@validate/validate.schema';
88
import { RequestHandler, Router } from 'express';
99

src/api/integrations/event/webhook/webhook.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const webhookSchema: JSONSchema7 = {
3131
properties: {
3232
enabled: { type: 'boolean' },
3333
url: { type: 'string' },
34+
headers: { type: 'object' },
3435
byEvents: { type: 'boolean' },
3536
base64: { type: 'boolean' },
3637
events: {

0 commit comments

Comments
 (0)