mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 20:12:02 -06:00
Merge pull request #952 from fmedeiros95/v2.0.0
Adiciona a função de fake call
This commit is contained in:
commit
eee43bb073
@ -55,7 +55,7 @@
|
||||
"@sentry/node": "^8.28.0",
|
||||
"amqplib": "^0.10.3",
|
||||
"axios": "^1.6.5",
|
||||
"baileys": "6.7.8",
|
||||
"baileys": "github:EvolutionAPI/Baileys",
|
||||
"class-validator": "^0.14.1",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
|
11
src/api/controllers/call.controller.ts
Normal file
11
src/api/controllers/call.controller.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { OfferCallDto } from '@api/dto/call.dto';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
|
||||
export class CallController {
|
||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||
|
||||
public async offerCall({ instanceName }: InstanceDto, data: OfferCallDto) {
|
||||
return await this.waMonitor.waInstances[instanceName].offerCall(data);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import {
|
||||
OfferCallDto,
|
||||
SendAudioDto,
|
||||
SendButtonDto,
|
||||
SendContactDto,
|
||||
@ -86,4 +87,8 @@ export class SendMessageController {
|
||||
public async sendStatus({ instanceName }: InstanceDto, data: SendStatusDto, file?: any) {
|
||||
return await this.waMonitor.waInstances[instanceName].statusMessage(data, file);
|
||||
}
|
||||
|
||||
public async offerCall({ instanceName }: InstanceDto, data: OfferCallDto) {
|
||||
return await this.waMonitor.waInstances[instanceName].offerCall(data);
|
||||
}
|
||||
}
|
||||
|
8
src/api/dto/call.dto.ts
Normal file
8
src/api/dto/call.dto.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export class Metadata {
|
||||
number: string;
|
||||
}
|
||||
|
||||
export class OfferCallDto extends Metadata {
|
||||
isVideo?: boolean;
|
||||
callDuration?: number;
|
||||
}
|
@ -548,6 +548,9 @@ export class EvolutionStartupService extends ChannelStartupService {
|
||||
public async fetchProfile() {
|
||||
throw new BadRequestException('Method not available on Evolution Channel');
|
||||
}
|
||||
public async offerCall() {
|
||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||
}
|
||||
public async sendPresence() {
|
||||
throw new BadRequestException('Method not available on Evolution Channel');
|
||||
}
|
||||
|
@ -1365,6 +1365,9 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
public async fetchProfile() {
|
||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||
}
|
||||
public async offerCall() {
|
||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||
}
|
||||
public async sendPresence() {
|
||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { OfferCallDto } from '@api/dto/call.dto';
|
||||
import {
|
||||
ArchiveChatDto,
|
||||
BlockUserDto,
|
||||
@ -1662,6 +1663,19 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
public async offerCall({ number, isVideo, callDuration }: OfferCallDto) {
|
||||
const jid = this.createJid(number);
|
||||
|
||||
try {
|
||||
const call = await this.client.offerCall(jid, isVideo);
|
||||
setTimeout(() => this.client.terminateCall(call.id, call.to), callDuration * 1000);
|
||||
|
||||
return call;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
private async sendMessage(
|
||||
sender: string,
|
||||
message: any,
|
||||
|
25
src/api/routes/call.router.ts
Normal file
25
src/api/routes/call.router.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { OfferCallDto } from '@api/dto/call.dto';
|
||||
import { sendMessageController } from '@api/server.module';
|
||||
import { offerCallSchema } from '@validate/validate.schema';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { HttpStatus } from './index.router';
|
||||
|
||||
export class CallRouter extends RouterBroker {
|
||||
constructor(...guards: RequestHandler[]) {
|
||||
super();
|
||||
this.router.post(this.routerPath('offer'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<OfferCallDto>({
|
||||
request: req,
|
||||
schema: offerCallSchema,
|
||||
ClassRef: OfferCallDto,
|
||||
execute: (instance, data) => sendMessageController.offerCall(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
});
|
||||
}
|
||||
|
||||
public readonly router: Router = Router();
|
||||
}
|
@ -11,6 +11,7 @@ import fs from 'fs';
|
||||
import mime from 'mime';
|
||||
import path from 'path';
|
||||
|
||||
import { CallRouter } from './call.router';
|
||||
import { ChatRouter } from './chat.router';
|
||||
import { GroupRouter } from './group.router';
|
||||
import { InstanceRouter } from './instance.router';
|
||||
@ -79,6 +80,7 @@ router
|
||||
})
|
||||
.use('/instance', new InstanceRouter(configService, ...guards).router)
|
||||
.use('/message', new MessageRouter(...guards).router)
|
||||
.use('/call', new CallRouter(...guards).router)
|
||||
.use('/chat', new ChatRouter(...guards).router)
|
||||
.use('/group', new GroupRouter(...guards).router)
|
||||
.use('/template', new TemplateRouter(configService, ...guards).router)
|
||||
|
@ -54,6 +54,17 @@ const quotedOptionsSchema: JSONSchema7 = {
|
||||
},
|
||||
};
|
||||
|
||||
export const offerCallSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
number: { ...numberDefinition },
|
||||
isVideo: { type: 'boolean', enum: [true, false] },
|
||||
callDuration: { type: 'integer', minimum: 1, maximum: 15 },
|
||||
},
|
||||
required: ['number', 'callDuration'],
|
||||
};
|
||||
|
||||
export const textMessageSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
|
Loading…
Reference in New Issue
Block a user