mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: refactor helpers (nlu)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user