[core] chore: Add LabelsController to handle label-related API requests

This commit is contained in:
aziz authored and devlikepro committed 2024-08-04 10:08:58 +07:00
1 parent dbff2b659a
commit e44aeefda8
5 files changed
+50 -3

No files matched your search

+19
View File
@@ -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();
}
}
+8
View File
@@ -332,6 +332,14 @@ export abstract class WhatsappSession {
throw new NotImplementedByEngineError();
}
/**
* Labels methods
*/
public getLabels() {
throw new NotImplementedByEngineError();
}
/**
* Contacts methods
*/
+3
View File
@@ -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,
@@ -723,6 +723,14 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
return this.chatsPutArchive(chatId, false);
}
/**
* Labels methods
*/
getLabels() {
throw new NotImplementedByEngineError();
}
/**
* Contacts methods
*/
+12 -3
View File
@@ -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
*/