Update ESLint configuration, Dockerfile, and package dependencies; refactor bot trigger logic

- Updated ESLint configuration to use TypeScript project references and adjusted parser options.
- Modified Dockerfile to include OpenSSL in both builder and final stages.
- Changed `mime` package version from `^4.0.6` to `^3.0.0` in `package.json` and updated TypeScript ESLint packages to `^6.21.0`.
- Refactored `findBotByTrigger` function to remove unnecessary settings repository parameter.
- Adjusted bot trigger logic in multiple controller files to streamline function calls.
This commit is contained in:
Davidson Gomes 2025-01-09 12:57:21 -03:00
parent ca451bfacc
commit d598c4ed0b
13 changed files with 1671 additions and 2062 deletions

View File

@ -1,7 +1,11 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'CommonJS',
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'commonjs',
warnOnUnsupportedTypeScriptVersion: false,
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
},
plugins: ['@typescript-eslint', 'simple-import-sort', 'import'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],

View File

@ -1,7 +1,7 @@
FROM node:20-alpine AS builder
RUN apk update && \
apk add git ffmpeg wget curl bash
apk add git ffmpeg wget curl bash openssl
LABEL version="2.2.0" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
@ -32,7 +32,7 @@ RUN npm run build
FROM node:20-alpine AS final
RUN apk update && \
apk add tzdata ffmpeg bash
apk add tzdata ffmpeg bash openssl
ENV TZ=America/Sao_Paulo

3655
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -77,7 +77,7 @@
"link-preview-js": "^3.0.13",
"long": "^5.2.3",
"mediainfo.js": "^0.3.4",
"mime": "^4.0.6",
"mime": "^3.0.0",
"minio": "^8.0.3",
"multer": "^1.4.5-lts.1",
"node-cache": "^5.1.2",
@ -99,14 +99,13 @@
"@types/cors": "^2.8.17",
"@types/express": "^4.17.18",
"@types/json-schema": "^7.0.15",
"@types/mime": "4.0.0",
"@types/node": "^22.10.5",
"@types/node-cron": "^3.0.11",
"@types/qrcode": "^1.5.5",
"@types/qrcode-terminal": "^0.12.2",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.45.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.31.0",

View File

@ -271,7 +271,7 @@ export class BaileysStartupService extends ChannelStartupService {
public async getProfileStatus() {
const status = await this.client.fetchStatus(this.instance.wuid);
return status?.status;
return status[0]?.status;
}
public get profilePictureUrl() {
@ -974,7 +974,7 @@ export class BaileysStartupService extends ChannelStartupService {
const messagesRaw: any[] = [];
const messagesRepository = new Set(
const messagesRepository: Set<string> = new Set(
chatwootImport.getRepositoryMessagesCache(instance) ??
(
await this.prismaRepository.message.findMany({
@ -1790,7 +1790,7 @@ export class BaileysStartupService extends ChannelStartupService {
try {
return {
wuid: jid,
status: (await this.client.fetchStatus(jid))?.status,
status: (await this.client.fetchStatus(jid))[0]?.status,
};
} catch (error) {
return {

View File

@ -184,7 +184,6 @@ export class ChatbotController {
public async findBotTrigger(
botRepository: any,
settingsRepository: any,
content: string,
instance: InstanceDto,
session?: IntegrationSession,
@ -192,7 +191,7 @@ export class ChatbotController {
let findBot: null;
if (!session) {
findBot = await findBotByTrigger(botRepository, settingsRepository, content, instance.instanceId);
findBot = await findBotByTrigger(botRepository, content, instance.instanceId);
if (!findBot) {
return;

View File

@ -756,13 +756,7 @@ export class DifyController extends ChatbotController implements ChatbotControll
const content = getConversationMessage(msg);
let findBot = (await this.findBotTrigger(
this.botRepository,
this.settingsRepository,
content,
instance,
session,
)) as DifyModel;
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as DifyModel;
if (!findBot) {
const fallback = await this.settingsRepository.findFirst({

View File

@ -728,13 +728,7 @@ export class EvolutionBotController extends ChatbotController implements Chatbot
const content = getConversationMessage(msg);
let findBot = (await this.findBotTrigger(
this.botRepository,
this.settingsRepository,
content,
instance,
session,
)) as EvolutionBot;
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as EvolutionBot;
if (!findBot) {
const fallback = await this.settingsRepository.findFirst({

View File

@ -728,13 +728,7 @@ export class FlowiseController extends ChatbotController implements ChatbotContr
const content = getConversationMessage(msg);
let findBot = (await this.findBotTrigger(
this.botRepository,
this.settingsRepository,
content,
instance,
session,
)) as Flowise;
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as Flowise;
if (!findBot) {
const fallback = await this.settingsRepository.findFirst({

View File

@ -965,13 +965,7 @@ export class OpenaiController extends ChatbotController implements ChatbotContro
const content = getConversationMessage(msg);
let findBot = (await this.findBotTrigger(
this.botRepository,
this.settingsRepository,
content,
instance,
session,
)) as OpenaiBot;
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as OpenaiBot;
if (!findBot) {
const fallback = await this.settingsRepository.findFirst({

View File

@ -943,13 +943,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
const content = getConversationMessage(msg);
let findBot = (await this.findBotTrigger(
this.botRepository,
this.settingsRepository,
content,
instance,
session,
)) as TypebotModel;
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as TypebotModel;
if (!findBot) {
const fallback = await this.settingsRepository.findFirst({

View File

@ -1,11 +1,6 @@
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
export const findBotByTrigger = async (
botRepository: any,
settingsRepository: any,
content: string,
instanceId: string,
) => {
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
// Check for triggerType 'all'
const findTriggerAll = await botRepository.findFirst({
where: {

View File

@ -4,7 +4,7 @@
"emitDecoratorMetadata": true,
"declaration": true,
"target": "es2020",
"module": "commonjs",
"module": "NodeNext",
"rootDir": "./",
"resolveJsonModule": true,
"removeComments": true,
@ -26,7 +26,8 @@
"@libs/*": ["./src/libs/*"],
"@utils/*": ["./src/utils/*"],
"@validate/*": ["./src/validate/*"]
}
},
"moduleResolution": "NodeNext"
},
"exclude": ["node_modules", "./test", "./dist", "./prisma"],
"include": [