[core] Add type
This commit is contained in:
1 parent
e44aeefda8
commit
ac37745721
7 files changed
+48
-10
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
|
||||
import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
|
||||
import { Label } from '@waha/structures/labels.dto';
|
||||
|
||||
import { SessionManager } from '../core/abc/manager.abc';
|
||||
import { SessionQuery } from '../structures/base.dto';
|
||||
@@ -12,7 +13,7 @@ export class LabelsController {
|
||||
|
||||
@Get('/')
|
||||
@ApiOperation({ summary: 'Get all labels' })
|
||||
getAll(@Query() query: SessionQuery) {
|
||||
getAll(@Query() query: SessionQuery): Promise<Label[]> {
|
||||
const whatsapp = this.manager.getSession(query.session);
|
||||
return whatsapp.getLabels();
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ export class SwaggerConfiguratorCore {
|
||||
)
|
||||
.addTag('groups', `Groups methods.<br>`)
|
||||
.addTag('presence', `Presence information`)
|
||||
.addTag(
|
||||
'labels',
|
||||
'Labels - available only for WhatsApp Business accounts',
|
||||
)
|
||||
.addTag('other', 'Other methods')
|
||||
.addApiKey({
|
||||
type: 'apiKey',
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
ListChannelsQuery,
|
||||
} from '@waha/structures/channels.dto';
|
||||
import { GetChatsQuery } from '@waha/structures/chats.dto';
|
||||
import { Label } from '@waha/structures/labels.dto';
|
||||
import { LoggerBuilder } from '@waha/utils/logging';
|
||||
import { EventEmitter } from 'events';
|
||||
import * as fs from 'fs';
|
||||
@@ -336,7 +337,7 @@ export abstract class WhatsappSession {
|
||||
* Labels methods
|
||||
*/
|
||||
|
||||
public getLabels() {
|
||||
public getLabels(): Promise<Label[]> {
|
||||
throw new NotImplementedByEngineError();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ 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';
|
||||
import { LabelsController } from '../api/labels.controller';
|
||||
import { PingController } from '../api/ping.controller';
|
||||
import { PresenceController } from '../api/presence.controller';
|
||||
import { ScreenshotController } from '../api/screenshot.controller';
|
||||
@@ -37,7 +37,6 @@ import { SwaggerConfigServiceCore } from './config/SwaggerConfigServiceCore';
|
||||
import { WAHAHealthCheckServiceCore } from './health/WAHAHealthCheckServiceCore';
|
||||
import { SessionManagerCore } from './manager.core';
|
||||
|
||||
|
||||
export const IMPORTS = [
|
||||
LoggerModule.forRoot({
|
||||
renameContext: 'name',
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
} from '@waha/structures/channels.dto';
|
||||
import { GetChatsQuery } from '@waha/structures/chats.dto';
|
||||
import { ContactQuery, ContactRequest } from '@waha/structures/contacts.dto';
|
||||
import { Label } from '@waha/structures/labels.dto';
|
||||
import {
|
||||
PollVote,
|
||||
PollVotePayload,
|
||||
@@ -727,7 +728,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
|
||||
* Labels methods
|
||||
*/
|
||||
|
||||
getLabels() {
|
||||
public getLabels(): Promise<Label[]> {
|
||||
throw new NotImplementedByEngineError();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import {
|
||||
ParticipantsRequest,
|
||||
SettingsSecurityChangeInfo,
|
||||
} from '@waha/structures/groups.dto';
|
||||
import { Label } from '@waha/structures/labels.dto';
|
||||
import { WAMessage, WAMessageReaction } from '@waha/structures/responses.dto';
|
||||
import { MeInfo } from '@waha/structures/sessions.dto';
|
||||
import { WAMessageRevokedBody } from '@waha/structures/webhooks.dto';
|
||||
@@ -62,6 +63,7 @@ import {
|
||||
Contact,
|
||||
Events,
|
||||
GroupChat,
|
||||
Label as WEBJSLabel,
|
||||
Location,
|
||||
Message,
|
||||
Reaction,
|
||||
@@ -337,7 +339,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 +361,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 +370,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);
|
||||
}
|
||||
@@ -485,8 +487,17 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
* Label methods
|
||||
*/
|
||||
|
||||
getLabels() {
|
||||
return this.whatsapp.getLabels();
|
||||
public async getLabels(): Promise<Label[]> {
|
||||
const labels = await this.whatsapp.getLabels();
|
||||
return labels.map(this.toLabel);
|
||||
}
|
||||
|
||||
protected toLabel(label: WEBJSLabel): Label {
|
||||
return {
|
||||
id: label.id,
|
||||
name: label.name,
|
||||
color: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class Label {
|
||||
@ApiProperty({
|
||||
example: '1',
|
||||
description: 'Label ID',
|
||||
})
|
||||
id: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'Lead',
|
||||
description: 'Label name',
|
||||
})
|
||||
name: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 0,
|
||||
description: 'Internal color number, not hex',
|
||||
})
|
||||
color: number;
|
||||
}
|
||||
Reference in new issue
Block a user