Skip to content

Commit 5404672

Browse files
committed
Enhance settings and integrate Baileys controller for WhatsApp functionality
- Added `wavoipToken` field to `Setting` model in both MySQL and PostgreSQL schemas. - Updated `package.json` and `package-lock.json` to include `mime-types` and `socket.io-client` dependencies. - Introduced `BaileysController` and `BaileysRouter` for handling WhatsApp interactions. - Refactored media type handling to use `mime-types` instead of `mime` across various services. - Updated DTOs and validation schemas to accommodate the new `wavoipToken` field. - Implemented voice call functionalities using the Wavoip service in the Baileys integration. - Enhanced event handling in the WebSocket controller to support new features.
1 parent 616ae0a commit 5404672

30 files changed

+748
-36
lines changed

package-lock.json

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"long": "^5.2.3",
8080
"mediainfo.js": "^0.3.4",
8181
"mime": "^4.0.0",
82+
"mime-types": "^2.1.35",
8283
"minio": "^8.0.3",
8384
"multer": "^1.4.5-lts.1",
8485
"node-cache": "^5.1.2",
@@ -93,6 +94,7 @@
9394
"redis": "^4.7.0",
9495
"sharp": "^0.32.6",
9596
"socket.io": "^4.8.1",
97+
"socket.io-client": "^4.8.1",
9698
"tsup": "^8.3.5"
9799
},
98100
"devDependencies": {
@@ -101,6 +103,7 @@
101103
"@types/express": "^4.17.18",
102104
"@types/json-schema": "^7.0.15",
103105
"@types/mime": "^4.0.0",
106+
"@types/mime-types": "^2.1.4",
104107
"@types/node": "^22.10.5",
105108
"@types/node-cron": "^3.0.11",
106109
"@types/qrcode": "^1.5.5",

prisma/mysql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ model Setting {
264264
readMessages Boolean @default(false)
265265
readStatus Boolean @default(false)
266266
syncFullHistory Boolean @default(false)
267+
wavoipToken String? @db.VarChar(100)
267268
createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp
268269
updatedAt DateTime @updatedAt @db.Timestamp
269270
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Chat` will be added. If there are existing duplicate values, this will fail.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "Setting" ADD COLUMN "wavoipToken" VARCHAR(100);
9+
10+
-- CreateIndex
11+
CREATE UNIQUE INDEX "Chat_remoteJid_instanceId_key" ON "Chat"("remoteJid", "instanceId");

prisma/postgresql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ model Setting {
265265
readMessages Boolean @default(false) @db.Boolean
266266
readStatus Boolean @default(false) @db.Boolean
267267
syncFullHistory Boolean @default(false) @db.Boolean
268+
wavoipToken String? @db.VarChar(100)
268269
createdAt DateTime? @default(now()) @db.Timestamp
269270
updatedAt DateTime @updatedAt @db.Timestamp
270271
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)

src/api/controllers/instance.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class InstanceController {
119119
readMessages: instanceData.readMessages === true,
120120
readStatus: instanceData.readStatus === true,
121121
syncFullHistory: instanceData.syncFullHistory === true,
122+
wavoipToken: instanceData.wavoipToken || '',
122123
};
123124

124125
await this.settingsService.create(instance, settings);

src/api/dto/instance.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class InstanceDto extends IntegrationDto {
1919
readMessages?: boolean;
2020
readStatus?: boolean;
2121
syncFullHistory?: boolean;
22+
wavoipToken?: string;
2223
// proxy
2324
proxyHost?: string;
2425
proxyPort?: string;

src/api/dto/settings.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export class SettingsDto {
66
readMessages?: boolean;
77
readStatus?: boolean;
88
syncFullHistory?: boolean;
9+
wavoipToken?: string;
910
}

src/api/integrations/channel/channel.router.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { Router } from 'express';
22

33
import { EvolutionRouter } from './evolution/evolution.router';
44
import { MetaRouter } from './meta/meta.router';
5+
import { BaileysRouter } from './whatsapp/baileys.router';
56

67
export class ChannelRouter {
78
public readonly router: Router;
89

9-
constructor(configService: any) {
10+
constructor(configService: any, ...guards: any[]) {
1011
this.router = Router();
1112

1213
this.router.use('/', new EvolutionRouter(configService).router);
1314
this.router.use('/', new MetaRouter(configService).router);
15+
this.router.use('/baileys', new BaileysRouter(...guards).router);
1416
}
1517
}

src/api/integrations/channel/evolution/evolution.channel.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BadRequestException, InternalServerErrorException } from '@exceptions';
1010
import { status } from '@utils/renderStatus';
1111
import { isURL } from 'class-validator';
1212
import EventEmitter2 from 'eventemitter2';
13-
import mime from 'mime';
13+
import mimeTypes from 'mime-types';
1414
import { v4 } from 'uuid';
1515

1616
export class EvolutionStartupService extends ChannelStartupService {
@@ -396,7 +396,7 @@ export class EvolutionStartupService extends ChannelStartupService {
396396
mediaMessage.fileName = 'video.mp4';
397397
}
398398

399-
let mimetype: string;
399+
let mimetype: string | false;
400400

401401
const prepareMedia: any = {
402402
caption: mediaMessage?.caption,
@@ -407,9 +407,9 @@ export class EvolutionStartupService extends ChannelStartupService {
407407
};
408408

409409
if (isURL(mediaMessage.media)) {
410-
mimetype = mime.getType(mediaMessage.media);
410+
mimetype = mimeTypes.lookup(mediaMessage.media);
411411
} else {
412-
mimetype = mime.getType(mediaMessage.fileName);
412+
mimetype = mimeTypes.lookup(mediaMessage.fileName);
413413
}
414414

415415
prepareMedia.mimetype = mimetype;
@@ -449,7 +449,7 @@ export class EvolutionStartupService extends ChannelStartupService {
449449
number = number.replace(/\D/g, '');
450450
const hash = `${number}-${new Date().getTime()}`;
451451

452-
let mimetype: string;
452+
let mimetype: string | false;
453453

454454
const prepareMedia: any = {
455455
fileName: `${hash}.mp4`,
@@ -458,9 +458,9 @@ export class EvolutionStartupService extends ChannelStartupService {
458458
};
459459

460460
if (isURL(audio)) {
461-
mimetype = mime.getType(audio);
461+
mimetype = mimeTypes.lookup(audio);
462462
} else {
463-
mimetype = mime.getType(prepareMedia.fileName);
463+
mimetype = mimeTypes.lookup(prepareMedia.fileName);
464464
}
465465

466466
prepareMedia.mimetype = mimetype;

0 commit comments

Comments
 (0)