Skip to content

Commit

Permalink
added: route - /assertSessions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Oct 22, 2024
1 parent a057b12 commit 4ee80de
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/whatsapp/controllers/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ export class ChatController {
public async rejectCall({ instanceName }: InstanceDto, data: RejectCallDto) {
return await this.waMonitor.waInstances.get(instanceName).rejectCall(data);
}

public async assertSessions({ instanceName }: InstanceDto, data: WhatsAppNumberDto) {
return await this.waMonitor.waInstances
.get(instanceName)
.assertSessions(data.numbers);
}
}
9 changes: 9 additions & 0 deletions src/whatsapp/routers/chat.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ export function ChatRouter(chatController: ChatController, ...guards: RequestHan
execute: (instance, data) => chatController.rejectCall(instance, data),
});

return res.status(HttpStatus.OK).json(response);
})
.post(routerPath('assertSessions'), ...guards, async (req, res) => {
const response = await dataValidate<WhatsAppNumberDto>({
request: req,
schema: whatsappNumberSchema,
execute: (instance, data) => chatController.assertSessions(instance, data),
});

return res.status(HttpStatus.OK).json(response);
});

Expand Down
25 changes: 20 additions & 5 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1635,17 +1635,17 @@ export class WAStartupService {
return await this.sendMessageWithTyping(data.number, {
extendedTextMessage: {
text: (() => {
let t = data.linkMessage.link;
if (data.linkMessage?.text) {
let t = data.linkMessage.link;
t += '\n\n';
t += data.linkMessage.text;
return t;
}
return t;
})(),
canonicalUrl: data.linkMessage.link,
matchedText: data.linkMessage?.text,
previewType: 0,
title: data.linkMessage?.title,
matchedText: data.linkMessage?.link,
previewType: proto.Message.ExtendedTextMessage.PreviewType.IMAGE,
title: data.linkMessage?.title || data.linkMessage?.link,
description: data.linkMessage?.description,
jpegThumbnail: await (async () => {
if (data.linkMessage?.thumbnailUrl) {
Expand Down Expand Up @@ -2059,6 +2059,21 @@ export class WAStartupService {
}
}

public async assertSessions(chats: string[]) {
if (!Array.isArray(chats) || chats.length === 0) {
throw new BadRequestException('Empty or invalid array');
}
try {
await this.client.assertSessions(
chats.map((c) => this.createJid(c)),
true,
);
return { message: 'Session asserted' };
} catch (error) {
throw new InternalServerErrorException('Error asserting session', error.toString());
}
}

// Group
public async createGroup(create: CreateGroupDto) {
try {
Expand Down

0 comments on commit 4ee80de

Please sign in to comment.