From e44aeefda83f74c06b6b6944afd9b1cffe6d98ee Mon Sep 17 00:00:00 2001 From: aziz Date: Wed, 8 May 2024 20:07:37 +0700 Subject: [PATCH] [core] chore: Add LabelsController to handle label-related API requests --- src/api/labels.controller.ts | 19 +++++++++++++++++++ src/core/abc/session.abc.ts | 8 ++++++++ src/core/app.module.core.ts | 3 +++ src/core/engines/noweb/session.noweb.core.ts | 8 ++++++++ src/core/engines/webjs/session.webjs.core.ts | 15 ++++++++++++--- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/api/labels.controller.ts diff --git a/src/api/labels.controller.ts b/src/api/labels.controller.ts new file mode 100644 index 00000000..8f9cd75f --- /dev/null +++ b/src/api/labels.controller.ts @@ -0,0 +1,19 @@ +import { Body, Controller, Get, Post, Query } from '@nestjs/common'; +import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger'; + +import { SessionManager } from '../core/abc/manager.abc'; +import { SessionQuery } from '../structures/base.dto'; + +@ApiSecurity('api_key') +@Controller('api/labels') +@ApiTags('labels') +export class LabelsController { + constructor(private manager: SessionManager) {} + + @Get('/') + @ApiOperation({ summary: 'Get all labels' }) + getAll(@Query() query: SessionQuery) { + const whatsapp = this.manager.getSession(query.session); + return whatsapp.getLabels(); + } +} diff --git a/src/core/abc/session.abc.ts b/src/core/abc/session.abc.ts index 7df0a296..10883bbe 100644 --- a/src/core/abc/session.abc.ts +++ b/src/core/abc/session.abc.ts @@ -332,6 +332,14 @@ export abstract class WhatsappSession { throw new NotImplementedByEngineError(); } + /** + * Labels methods + */ + + public getLabels() { + throw new NotImplementedByEngineError(); + } + /** * Contacts methods */ diff --git a/src/core/app.module.core.ts b/src/core/app.module.core.ts index 9b7d1ef8..b8201e25 100644 --- a/src/core/app.module.core.ts +++ b/src/core/app.module.core.ts @@ -15,6 +15,7 @@ import { Logger } from 'pino'; import { AuthController } from '../api/auth.controller'; import { ChatsController } from '../api/chats.controller'; import { ChattingController } from '../api/chatting.controller'; +import { LabelsController } from '../api/labels.controller'; import { ContactsController } from '../api/contacts.controller'; import { GroupsController } from '../api/groups.controller'; import { HealthController } from '../api/health.controller'; @@ -36,6 +37,7 @@ import { SwaggerConfigServiceCore } from './config/SwaggerConfigServiceCore'; import { WAHAHealthCheckServiceCore } from './health/WAHAHealthCheckServiceCore'; import { SessionManagerCore } from './manager.core'; + export const IMPORTS = [ LoggerModule.forRoot({ renameContext: 'name', @@ -100,6 +102,7 @@ export const CONTROLLERS = [ ChatsController, ChannelsController, StatusController, + LabelsController, ContactsController, GroupsController, PresenceController, diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index 73977581..cf7559f5 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -723,6 +723,14 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { return this.chatsPutArchive(chatId, false); } + /** + * Labels methods + */ + + getLabels() { + throw new NotImplementedByEngineError(); + } + /** * Contacts methods */ diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 53645095..1a964e6d 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -337,7 +337,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { sendText(request: MessageTextRequest) { const options = { // It's fine to sent just ids instead of Contact object - mentions: request.mentions as unknown as string[], + mentions: (request.mentions as unknown) as string[], }; return this.whatsapp.sendMessage( this.ensureSuffix(request.chatId), @@ -359,7 +359,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { const message = this.recreateMessage(messageId); const options = { // It's fine to sent just ids instead of Contact object - mentions: request.mentions as unknown as string[], + mentions: (request.mentions as unknown) as string[], }; return message.edit(request.text, options); } @@ -368,7 +368,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { const options = { quotedMessageId: request.reply_to, // It's fine to sent just ids instead of Contact object - mentions: request.mentions as unknown as string[], + mentions: (request.mentions as unknown) as string[], }; return this.whatsapp.sendMessage(request.chatId, request.text, options); } @@ -480,6 +480,15 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { return this.whatsapp.unarchiveChat(id); } + /** + * + * Label methods + */ + + getLabels() { + return this.whatsapp.getLabels(); + } + /** * Contacts methods */