mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
feat: update message sending logic
Refactored sendMessage.controller.ts, chat.dto.ts, and sendMessage.dto.ts to improve message handling. Updated chatwoot.service.ts and sendMessage.router.ts for better integration with Chatwoot. Enhanced whatsapp.baileys.service.ts for more reliable WhatsApp communication. Adjusted chat.schema.ts and message.schema.ts for validation improvements. These changes enhance the overall messaging functionality and reliability.
This commit is contained in:
parent
2d49c73023
commit
85106667a2
@ -3,7 +3,6 @@ import { isBase64, isURL } from 'class-validator';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import {
|
||||
FakeCallDto,
|
||||
SendAudioDto,
|
||||
SendButtonDto,
|
||||
SendContactDto,
|
||||
@ -85,8 +84,4 @@ export class SendMessageController {
|
||||
public async sendStatus({ instanceName }: InstanceDto, data: SendStatusDto) {
|
||||
return await this.waMonitor.waInstances[instanceName].statusMessage(data);
|
||||
}
|
||||
|
||||
public async fakeCall({ instanceName }: InstanceDto, data: FakeCallDto) {
|
||||
return await this.waMonitor.waInstances[instanceName].fakeCall(data);
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class Key {
|
||||
remoteJid: string;
|
||||
}
|
||||
export class ReadMessageDto {
|
||||
read_messages: Key[];
|
||||
readMessages: Key[];
|
||||
}
|
||||
|
||||
export class LastMessage {
|
||||
|
@ -131,11 +131,6 @@ export class SendListDto extends Metadata {
|
||||
sections: Section[];
|
||||
}
|
||||
|
||||
export class FakeCallDto extends Metadata {
|
||||
number: string;
|
||||
delay: number;
|
||||
}
|
||||
|
||||
export class ContactMessage {
|
||||
fullName: string;
|
||||
wuid: string;
|
||||
|
@ -1346,7 +1346,7 @@ export class ChatwootService {
|
||||
};
|
||||
|
||||
waInstance?.markMessageAsRead({
|
||||
read_messages: [
|
||||
readMessages: [
|
||||
{
|
||||
id: key.id,
|
||||
fromMe: key.fromMe,
|
||||
|
@ -3,7 +3,6 @@ import { RequestHandler, Router } from 'express';
|
||||
import {
|
||||
audioMessageSchema,
|
||||
contactMessageSchema,
|
||||
fakeCallSchema,
|
||||
listMessageSchema,
|
||||
locationMessageSchema,
|
||||
mediaMessageSchema,
|
||||
@ -16,7 +15,6 @@ import {
|
||||
} from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import {
|
||||
FakeCallDto,
|
||||
SendAudioDto,
|
||||
SendContactDto,
|
||||
SendListDto,
|
||||
@ -145,16 +143,6 @@ export class MessageRouter extends RouterBroker {
|
||||
execute: (instance, data) => sendMessageController.sendList(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.post(this.routerPath('fakeCall'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<FakeCallDto>({
|
||||
request: req,
|
||||
schema: fakeCallSchema,
|
||||
ClassRef: FakeCallDto,
|
||||
execute: (instance, data) => sendMessageController.fakeCall(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.CREATED).json(response);
|
||||
});
|
||||
// .post(this.routerPath('sendButtons'), ...guards, async (req, res) => {
|
||||
|
@ -109,7 +109,6 @@ import { InstanceDto, SetPresenceDto } from '../../dto/instance.dto';
|
||||
import { HandleLabelDto, LabelDto } from '../../dto/label.dto';
|
||||
import {
|
||||
ContactMessage,
|
||||
FakeCallDto,
|
||||
MediaMessage,
|
||||
Options,
|
||||
SendAudioDto,
|
||||
@ -1985,6 +1984,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
|
||||
await this.client.sendPresenceUpdate('paused', sender);
|
||||
}
|
||||
|
||||
return { presence: data.presence };
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw new BadRequestException(error.toString());
|
||||
@ -2696,7 +2697,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
public async markMessageAsRead(data: ReadMessageDto) {
|
||||
try {
|
||||
const keys: proto.IMessageKey[] = [];
|
||||
data.read_messages.forEach((read) => {
|
||||
data.readMessages.forEach((read) => {
|
||||
if (isJidGroup(read.remoteJid) || isJidUser(read.remoteJid)) {
|
||||
keys.push({
|
||||
remoteJid: read.remoteJid,
|
||||
@ -3434,26 +3435,4 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
public async templateMessage() {
|
||||
throw new Error('Method not available in the Baileys service');
|
||||
}
|
||||
|
||||
public async fakeCall(data: FakeCallDto) {
|
||||
try {
|
||||
const number = this.createJid(data.number);
|
||||
|
||||
if (number.includes('@g.us')) {
|
||||
throw new BadRequestException('Group calls are not supported');
|
||||
}
|
||||
|
||||
const mdDelay = data.delay ?? 0;
|
||||
|
||||
const call = await this.client.offerCall(number);
|
||||
|
||||
await delay(mdDelay);
|
||||
|
||||
await this.client.rejectCall(call.callId, call.toJid);
|
||||
|
||||
return call;
|
||||
} catch (error) {
|
||||
throw new BadRequestException('Error making fake call', error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ export const readMessageSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
read_messages: {
|
||||
readMessages: {
|
||||
type: 'array',
|
||||
minItems: 1,
|
||||
uniqueItems: true,
|
||||
@ -60,7 +60,7 @@ export const readMessageSchema: JSONSchema7 = {
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['read_messages'],
|
||||
required: ['readMessages'],
|
||||
};
|
||||
|
||||
export const archiveChatSchema: JSONSchema7 = {
|
||||
|
@ -358,16 +358,3 @@ export const listMessageSchema: JSONSchema7 = {
|
||||
},
|
||||
required: ['number', 'title', 'footerText', 'buttonText', 'sections'],
|
||||
};
|
||||
|
||||
export const fakeCallSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
number: { ...numberDefinition },
|
||||
delay: {
|
||||
type: 'integer',
|
||||
description: 'Enter a value in milliseconds',
|
||||
},
|
||||
},
|
||||
required: ['number', 'delay'],
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user