Skip to content

Commit 87fe8c2

Browse files
committed
Merge branch 'v2.0.0' of github.com:EvolutionAPI/evolution-api into v2.0.0
2 parents e66f877 + eee43bb commit 87fe8c2

File tree

10 files changed

+83
-1
lines changed

10 files changed

+83
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@sentry/node": "^8.28.0",
5656
"amqplib": "^0.10.3",
5757
"axios": "^1.6.5",
58-
"baileys": "6.7.8",
58+
"baileys": "github:EvolutionAPI/Baileys",
5959
"class-validator": "^0.14.1",
6060
"compression": "^1.7.4",
6161
"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/controllers/sendMessage.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { InstanceDto } from '@api/dto/instance.dto';
22
import {
3+
OfferCallDto,
34
SendAudioDto,
45
SendButtonDto,
56
SendContactDto,
@@ -86,4 +87,8 @@ export class SendMessageController {
8687
public async sendStatus({ instanceName }: InstanceDto, data: SendStatusDto, file?: any) {
8788
return await this.waMonitor.waInstances[instanceName].statusMessage(data, file);
8889
}
90+
91+
public async offerCall({ instanceName }: InstanceDto, data: OfferCallDto) {
92+
return await this.waMonitor.waInstances[instanceName].offerCall(data);
93+
}
8994
}

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
@@ -548,6 +548,9 @@ export class EvolutionStartupService extends ChannelStartupService {
548548
public async fetchProfile() {
549549
throw new BadRequestException('Method not available on Evolution Channel');
550550
}
551+
public async offerCall() {
552+
throw new BadRequestException('Method not available on WhatsApp Business API');
553+
}
551554
public async sendPresence() {
552555
throw new BadRequestException('Method not available on Evolution Channel');
553556
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,9 @@ export class BusinessStartupService extends ChannelStartupService {
13651365
public async fetchProfile() {
13661366
throw new BadRequestException('Method not available on WhatsApp Business API');
13671367
}
1368+
public async offerCall() {
1369+
throw new BadRequestException('Method not available on WhatsApp Business API');
1370+
}
13681371
public async sendPresence() {
13691372
throw new BadRequestException('Method not available on WhatsApp Business API');
13701373
}

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,
@@ -1662,6 +1663,19 @@ export class BaileysStartupService extends ChannelStartupService {
16621663
}
16631664
}
16641665

1666+
public async offerCall({ number, isVideo, callDuration }: OfferCallDto) {
1667+
const jid = this.createJid(number);
1668+
1669+
try {
1670+
const call = await this.client.offerCall(jid, isVideo);
1671+
setTimeout(() => this.client.terminateCall(call.id, call.to), callDuration * 1000);
1672+
1673+
return call;
1674+
} catch (error) {
1675+
return error;
1676+
}
1677+
}
1678+
16651679
private async sendMessage(
16661680
sender: string,
16671681
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 { sendMessageController } 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) => sendMessageController.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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import fs from 'fs';
1111
import mime from 'mime';
1212
import path from 'path';
1313

14+
import { CallRouter } from './call.router';
1415
import { ChatRouter } from './chat.router';
1516
import { GroupRouter } from './group.router';
1617
import { InstanceRouter } from './instance.router';
@@ -79,6 +80,7 @@ router
7980
})
8081
.use('/instance', new InstanceRouter(configService, ...guards).router)
8182
.use('/message', new MessageRouter(...guards).router)
83+
.use('/call', new CallRouter(...guards).router)
8284
.use('/chat', new ChatRouter(...guards).router)
8385
.use('/group', new GroupRouter(...guards).router)
8486
.use('/template', new TemplateRouter(configService, ...guards).router)

src/validate/message.schema.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ const quotedOptionsSchema: JSONSchema7 = {
5454
},
5555
};
5656

57+
export const offerCallSchema: JSONSchema7 = {
58+
$id: v4(),
59+
type: 'object',
60+
properties: {
61+
number: { ...numberDefinition },
62+
isVideo: { type: 'boolean', enum: [true, false] },
63+
callDuration: { type: 'integer', minimum: 1, maximum: 15 },
64+
},
65+
required: ['number', 'callDuration'],
66+
};
67+
5768
export const textMessageSchema: JSONSchema7 = {
5869
$id: v4(),
5970
type: 'object',

0 commit comments

Comments
 (0)