Skip to content

Commit 8510666

Browse files
committed
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.
1 parent 2d49c73 commit 8510666

8 files changed

Lines changed: 7 additions & 63 deletions

File tree

src/api/controllers/sendMessage.controller.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { isBase64, isURL } from 'class-validator';
33
import { BadRequestException } from '../../exceptions';
44
import { InstanceDto } from '../dto/instance.dto';
55
import {
6-
FakeCallDto,
76
SendAudioDto,
87
SendButtonDto,
98
SendContactDto,
@@ -85,8 +84,4 @@ export class SendMessageController {
8584
public async sendStatus({ instanceName }: InstanceDto, data: SendStatusDto) {
8685
return await this.waMonitor.waInstances[instanceName].statusMessage(data);
8786
}
88-
89-
public async fakeCall({ instanceName }: InstanceDto, data: FakeCallDto) {
90-
return await this.waMonitor.waInstances[instanceName].fakeCall(data);
91-
}
9287
}

src/api/dto/chat.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Key {
5959
remoteJid: string;
6060
}
6161
export class ReadMessageDto {
62-
read_messages: Key[];
62+
readMessages: Key[];
6363
}
6464

6565
export class LastMessage {

src/api/dto/sendMessage.dto.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ export class SendListDto extends Metadata {
131131
sections: Section[];
132132
}
133133

134-
export class FakeCallDto extends Metadata {
135-
number: string;
136-
delay: number;
137-
}
138-
139134
export class ContactMessage {
140135
fullName: string;
141136
wuid: string;

src/api/integrations/chatwoot/services/chatwoot.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ export class ChatwootService {
13461346
};
13471347

13481348
waInstance?.markMessageAsRead({
1349-
read_messages: [
1349+
readMessages: [
13501350
{
13511351
id: key.id,
13521352
fromMe: key.fromMe,

src/api/routes/sendMessage.router.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { RequestHandler, Router } from 'express';
33
import {
44
audioMessageSchema,
55
contactMessageSchema,
6-
fakeCallSchema,
76
listMessageSchema,
87
locationMessageSchema,
98
mediaMessageSchema,
@@ -16,7 +15,6 @@ import {
1615
} from '../../validate/validate.schema';
1716
import { RouterBroker } from '../abstract/abstract.router';
1817
import {
19-
FakeCallDto,
2018
SendAudioDto,
2119
SendContactDto,
2220
SendListDto,
@@ -145,16 +143,6 @@ export class MessageRouter extends RouterBroker {
145143
execute: (instance, data) => sendMessageController.sendList(instance, data),
146144
});
147145

148-
return res.status(HttpStatus.CREATED).json(response);
149-
})
150-
.post(this.routerPath('fakeCall'), ...guards, async (req, res) => {
151-
const response = await this.dataValidate<FakeCallDto>({
152-
request: req,
153-
schema: fakeCallSchema,
154-
ClassRef: FakeCallDto,
155-
execute: (instance, data) => sendMessageController.fakeCall(instance, data),
156-
});
157-
158146
return res.status(HttpStatus.CREATED).json(response);
159147
});
160148
// .post(this.routerPath('sendButtons'), ...guards, async (req, res) => {

src/api/services/channels/whatsapp.baileys.service.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ import { InstanceDto, SetPresenceDto } from '../../dto/instance.dto';
109109
import { HandleLabelDto, LabelDto } from '../../dto/label.dto';
110110
import {
111111
ContactMessage,
112-
FakeCallDto,
113112
MediaMessage,
114113
Options,
115114
SendAudioDto,
@@ -1985,6 +1984,8 @@ export class BaileysStartupService extends ChannelStartupService {
19851984

19861985
await this.client.sendPresenceUpdate('paused', sender);
19871986
}
1987+
1988+
return { presence: data.presence };
19881989
} catch (error) {
19891990
this.logger.error(error);
19901991
throw new BadRequestException(error.toString());
@@ -2696,7 +2697,7 @@ export class BaileysStartupService extends ChannelStartupService {
26962697
public async markMessageAsRead(data: ReadMessageDto) {
26972698
try {
26982699
const keys: proto.IMessageKey[] = [];
2699-
data.read_messages.forEach((read) => {
2700+
data.readMessages.forEach((read) => {
27002701
if (isJidGroup(read.remoteJid) || isJidUser(read.remoteJid)) {
27012702
keys.push({
27022703
remoteJid: read.remoteJid,
@@ -3434,26 +3435,4 @@ export class BaileysStartupService extends ChannelStartupService {
34343435
public async templateMessage() {
34353436
throw new Error('Method not available in the Baileys service');
34363437
}
3437-
3438-
public async fakeCall(data: FakeCallDto) {
3439-
try {
3440-
const number = this.createJid(data.number);
3441-
3442-
if (number.includes('@g.us')) {
3443-
throw new BadRequestException('Group calls are not supported');
3444-
}
3445-
3446-
const mdDelay = data.delay ?? 0;
3447-
3448-
const call = await this.client.offerCall(number);
3449-
3450-
await delay(mdDelay);
3451-
3452-
await this.client.rejectCall(call.callId, call.toJid);
3453-
3454-
return call;
3455-
} catch (error) {
3456-
throw new BadRequestException('Error making fake call', error.toString());
3457-
}
3458-
}
34593438
}

src/validate/chat.schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const readMessageSchema: JSONSchema7 = {
4545
$id: v4(),
4646
type: 'object',
4747
properties: {
48-
read_messages: {
48+
readMessages: {
4949
type: 'array',
5050
minItems: 1,
5151
uniqueItems: true,
@@ -60,7 +60,7 @@ export const readMessageSchema: JSONSchema7 = {
6060
},
6161
},
6262
},
63-
required: ['read_messages'],
63+
required: ['readMessages'],
6464
};
6565

6666
export const archiveChatSchema: JSONSchema7 = {

src/validate/message.schema.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,3 @@ export const listMessageSchema: JSONSchema7 = {
358358
},
359359
required: ['number', 'title', 'footerText', 'buttonText', 'sections'],
360360
};
361-
362-
export const fakeCallSchema: JSONSchema7 = {
363-
$id: v4(),
364-
type: 'object',
365-
properties: {
366-
number: { ...numberDefinition },
367-
delay: {
368-
type: 'integer',
369-
description: 'Enter a value in milliseconds',
370-
},
371-
},
372-
required: ['number', 'delay'],
373-
};

0 commit comments

Comments
 (0)