Skip to content

Commit 70b8d2f

Browse files
committed
feat: Fake Call function
1 parent 240f519 commit 70b8d2f

File tree

11 files changed

+91
-17
lines changed

11 files changed

+91
-17
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# 2.2.0 (develop)
2+
3+
### Features
4+
5+
* Fake Call function
6+
7+
### Fixed
8+
9+
* Fixed prefilledVariables in startTypebot
10+
* Fix duplicate file upload
11+
112
# 2.1.2 (2024-10-06 10:09)
213

314
### Features

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@sentry/node": "^8.28.0",
5454
"amqplib": "^0.10.3",
5555
"axios": "^1.6.5",
56-
"baileys": "github:renatoiub/Baileys",
56+
"baileys": "github:EvolutionAPI/Baileys",
5757
"class-validator": "^0.14.1",
5858
"compression": "^1.7.4",
5959
"cors": "^2.8.5",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { OfferCallDto } from '@api/dto/call.dto';
2+
import { InstanceDto } from '@api/dto/instance.dto';
3+
import { WAMonitoringService } from '@api/services/monitor.service';
4+
5+
export class CallController {
6+
constructor(private readonly waMonitor: WAMonitoringService) {}
7+
8+
public async offerCall({ instanceName }: InstanceDto, data: OfferCallDto) {
9+
return await this.waMonitor.waInstances[instanceName].offerCall(data);
10+
}
11+
}

src/api/dto/call.dto.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class Metadata {
2+
number: string;
3+
}
4+
5+
export class OfferCallDto extends Metadata {
6+
isVideo?: boolean;
7+
callDuration?: number;
8+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,7 @@ export class EvolutionStartupService extends ChannelStartupService {
555555
public async fakeCall() {
556556
throw new BadRequestException('Method not available on Evolution Channel');
557557
}
558+
public async offerCall() {
559+
throw new BadRequestException('Method not available on Evolution Channel');
560+
}
558561
}

src/api/integrations/channel/meta/whatsapp.business.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,4 +1300,7 @@ export class BusinessStartupService extends ChannelStartupService {
13001300
public async fakeCall() {
13011301
throw new BadRequestException('Method not available on WhatsApp Business API');
13021302
}
1303+
public async offerCall() {
1304+
throw new BadRequestException('Method not available on WhatsApp Business API');
1305+
}
13031306
}

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OfferCallDto } from '@api/dto/call.dto';
12
import {
23
ArchiveChatDto,
34
BlockUserDto,
@@ -1351,6 +1352,19 @@ export class BaileysStartupService extends ChannelStartupService {
13511352
}
13521353
}
13531354

1355+
public async offerCall({ number, isVideo, callDuration }: OfferCallDto) {
1356+
const jid = this.createJid(number);
1357+
1358+
try {
1359+
const call = await this.client.offerCall(jid, isVideo);
1360+
setTimeout(() => this.client.terminateCall(call.id, call.to), callDuration * 1000);
1361+
1362+
return call;
1363+
} catch (error) {
1364+
return error;
1365+
}
1366+
}
1367+
13541368
private async sendMessage(
13551369
sender: string,
13561370
message: any,

src/api/routes/call.router.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RouterBroker } from '@api/abstract/abstract.router';
2+
import { OfferCallDto } from '@api/dto/call.dto';
3+
import { callController } from '@api/server.module';
4+
import { offerCallSchema } from '@validate/validate.schema';
5+
import { RequestHandler, Router } from 'express';
6+
7+
import { HttpStatus } from './index.router';
8+
9+
export class CallRouter extends RouterBroker {
10+
constructor(...guards: RequestHandler[]) {
11+
super();
12+
this.router.post(this.routerPath('offer'), ...guards, async (req, res) => {
13+
const response = await this.dataValidate<OfferCallDto>({
14+
request: req,
15+
schema: offerCallSchema,
16+
ClassRef: OfferCallDto,
17+
execute: (instance, data) => callController.offerCall(instance, data),
18+
});
19+
20+
return res.status(HttpStatus.CREATED).json(response);
21+
});
22+
}
23+
24+
public readonly router: Router = Router();
25+
}

src/api/routes/index.router.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { EventRouter } from '@api/integrations/event/event.router';
66
import { configService } from '@config/env.config';
77
import { Router } from 'express';
88
import fs from 'fs';
9-
import mime from 'mime';
10-
import path from 'path';
119

10+
import { CallRouter } from './call.router';
1211
import { ChatRouter } from './chat.router';
1312
import { GroupRouter } from './group.router';
1413
import { InstanceRouter } from './instance.router';
@@ -35,20 +34,6 @@ const telemetry = new Telemetry();
3534

3635
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
3736

38-
router.get('/assets/*', (req, res) => {
39-
const fileName = req.params[0];
40-
const basePath = path.join(process.cwd(), 'manager', 'dist');
41-
42-
const filePath = path.join(basePath, 'assets/', fileName);
43-
44-
if (fs.existsSync(filePath)) {
45-
res.set('Content-Type', mime.getType(filePath) || 'text/css');
46-
res.send(fs.readFileSync(filePath));
47-
} else {
48-
res.status(404).send('File not found');
49-
}
50-
});
51-
5237
router
5338
.use((req, res, next) => telemetry.collectTelemetry(req, res, next))
5439

@@ -72,6 +57,7 @@ router
7257
})
7358
.use('/instance', new InstanceRouter(configService, ...guards).router)
7459
.use('/message', new MessageRouter(...guards).router)
60+
.use('/call', new CallRouter(...guards).router)
7561
.use('/chat', new ChatRouter(...guards).router)
7662
.use('/group', new GroupRouter(...guards).router)
7763
.use('/template', new TemplateRouter(configService, ...guards).router)

src/api/server.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { configService, ProviderSession } from '@config/env.config';
33
import { eventEmitter } from '@config/event.config';
44
import { Logger } from '@config/logger.config';
55

6+
import { CallController } from './controllers/call.controller';
67
import { ChatController } from './controllers/chat.controller';
78
import { GroupController } from './controllers/group.controller';
89
import { InstanceController } from './controllers/instance.controller';
@@ -65,6 +66,7 @@ export const instanceController = new InstanceController(
6566
providerFiles,
6667
);
6768
export const sendMessageController = new SendMessageController(waMonitor);
69+
export const callController = new CallController(waMonitor);
6870
export const chatController = new ChatController(waMonitor);
6971
export const groupController = new GroupController(waMonitor);
7072
export const labelController = new LabelController(waMonitor);

0 commit comments

Comments
 (0)