feat: refactor helpers (nlu)

This commit is contained in:
Mohamed Marrouchi
2024-10-21 15:09:59 +01:00
parent b2c32fe27d
commit b7eef89981
53 changed files with 901 additions and 731 deletions

View File

@@ -13,7 +13,6 @@ import { InjectDynamicProviders } from 'nestjs-dynamic-providers';
import { AttachmentModule } from '@/attachment/attachment.module';
import { ChatModule } from '@/chat/chat.module';
import { CmsModule } from '@/cms/cms.module';
import { NlpModule } from '@/nlp/nlp.module';
import { ChannelController } from './channel.controller';
import { ChannelMiddleware } from './channel.middleware';
@@ -29,7 +28,7 @@ export interface ChannelModuleOptions {
controllers: [WebhookController, ChannelController],
providers: [ChannelService],
exports: [ChannelService],
imports: [NlpModule, ChatModule, AttachmentModule, CmsModule, HttpModule],
imports: [ChatModule, AttachmentModule, CmsModule, HttpModule],
})
export class ChannelModule {
configure(consumer: MiddlewareConsumer) {

View File

@@ -17,7 +17,7 @@ import {
StdIncomingMessage,
} from '@/chat/schemas/types/message';
import { Payload } from '@/chat/schemas/types/quick-reply';
import { Nlp } from '@/nlp/lib/types';
import { Nlp } from '@/helper/types';
import ChannelHandler from './Handler';

View File

@@ -16,8 +16,6 @@ import {
StdOutgoingMessage,
} from '@/chat/schemas/types/message';
import { LoggerService } from '@/logger/logger.service';
import BaseNlpHelper from '@/nlp/lib/BaseNlpHelper';
import { NlpService } from '@/nlp/services/nlp.service';
import { SettingService } from '@/setting/services/setting.service';
import { hyphenToUnderscore } from '@/utils/helpers/misc';
import { SocketRequest } from '@/websocket/utils/socket-request';
@@ -34,14 +32,11 @@ export default abstract class ChannelHandler<N extends string = string> {
private readonly settings: ChannelSetting<N>[];
protected NLP: BaseNlpHelper;
constructor(
name: N,
settings: ChannelSetting<N>[],
protected readonly settingService: SettingService,
private readonly channelService: ChannelService,
protected readonly nlpService: NlpService,
protected readonly logger: LoggerService,
) {
this.name = name;
@@ -56,10 +51,6 @@ export default abstract class ChannelHandler<N extends string = string> {
this.setup();
}
protected getGroup() {
return hyphenToUnderscore(this.getChannel()) as ChannelSetting<N>['group'];
}
async setup() {
await this.settingService.seedIfNotExist(
this.getChannel(),
@@ -68,19 +59,9 @@ export default abstract class ChannelHandler<N extends string = string> {
weight: i + 1,
})),
);
const nlp = this.nlpService.getNLP();
this.setNLP(nlp);
this.init();
}
setNLP(nlp: BaseNlpHelper) {
this.NLP = nlp;
}
getNLP() {
return this.NLP;
}
/**
* Returns the channel's name
* @returns Channel's name
@@ -89,6 +70,14 @@ export default abstract class ChannelHandler<N extends string = string> {
return this.name;
}
/**
* Returns the channel's group
* @returns Channel's group
*/
protected getGroup() {
return hyphenToUnderscore(this.getChannel()) as ChannelSetting<N>['group'];
}
/**
* Returns the channel's settings
* @returns Channel's settings