Skip to content

Commit d598c4e

Browse files
committed
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.
1 parent ca451bf commit d598c4e

File tree

13 files changed

+1716
-2107
lines changed

13 files changed

+1716
-2107
lines changed

.eslintrc.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module.exports = {
22
parser: '@typescript-eslint/parser',
33
parserOptions: {
4-
sourceType: 'CommonJS',
4+
project: 'tsconfig.json',
5+
tsconfigRootDir: __dirname,
6+
sourceType: 'commonjs',
7+
warnOnUnsupportedTypeScriptVersion: false,
8+
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
59
},
610
plugins: ['@typescript-eslint', 'simple-import-sort', 'import'],
711
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM node:20-alpine AS builder
22

33
RUN apk update && \
4-
apk add git ffmpeg wget curl bash
4+
apk add git ffmpeg wget curl bash openssl
55

66
LABEL version="2.2.0" description="Api to control whatsapp features through http requests."
77
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
@@ -32,7 +32,7 @@ RUN npm run build
3232
FROM node:20-alpine AS final
3333

3434
RUN apk update && \
35-
apk add tzdata ffmpeg bash
35+
apk add tzdata ffmpeg bash openssl
3636

3737
ENV TZ=America/Sao_Paulo
3838

package-lock.json

+1,693-2,052
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"link-preview-js": "^3.0.13",
7878
"long": "^5.2.3",
7979
"mediainfo.js": "^0.3.4",
80-
"mime": "^4.0.6",
80+
"mime": "^3.0.0",
8181
"minio": "^8.0.3",
8282
"multer": "^1.4.5-lts.1",
8383
"node-cache": "^5.1.2",
@@ -99,14 +99,13 @@
9999
"@types/cors": "^2.8.17",
100100
"@types/express": "^4.17.18",
101101
"@types/json-schema": "^7.0.15",
102-
"@types/mime": "4.0.0",
103102
"@types/node": "^22.10.5",
104103
"@types/node-cron": "^3.0.11",
105104
"@types/qrcode": "^1.5.5",
106105
"@types/qrcode-terminal": "^0.12.2",
107106
"@types/uuid": "^10.0.0",
108-
"@typescript-eslint/eslint-plugin": "^5.62.0",
109-
"@typescript-eslint/parser": "^5.62.0",
107+
"@typescript-eslint/eslint-plugin": "^6.21.0",
108+
"@typescript-eslint/parser": "^6.21.0",
110109
"eslint": "^8.45.0",
111110
"eslint-config-prettier": "^9.1.0",
112111
"eslint-plugin-import": "^2.31.0",

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class BaileysStartupService extends ChannelStartupService {
271271
public async getProfileStatus() {
272272
const status = await this.client.fetchStatus(this.instance.wuid);
273273

274-
return status?.status;
274+
return status[0]?.status;
275275
}
276276

277277
public get profilePictureUrl() {
@@ -974,7 +974,7 @@ export class BaileysStartupService extends ChannelStartupService {
974974

975975
const messagesRaw: any[] = [];
976976

977-
const messagesRepository = new Set(
977+
const messagesRepository: Set<string> = new Set(
978978
chatwootImport.getRepositoryMessagesCache(instance) ??
979979
(
980980
await this.prismaRepository.message.findMany({
@@ -1790,7 +1790,7 @@ export class BaileysStartupService extends ChannelStartupService {
17901790
try {
17911791
return {
17921792
wuid: jid,
1793-
status: (await this.client.fetchStatus(jid))?.status,
1793+
status: (await this.client.fetchStatus(jid))[0]?.status,
17941794
};
17951795
} catch (error) {
17961796
return {

src/api/integrations/chatbot/chatbot.controller.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,14 @@ export class ChatbotController {
184184

185185
public async findBotTrigger(
186186
botRepository: any,
187-
settingsRepository: any,
188187
content: string,
189188
instance: InstanceDto,
190189
session?: IntegrationSession,
191190
) {
192191
let findBot: null;
193192

194193
if (!session) {
195-
findBot = await findBotByTrigger(botRepository, settingsRepository, content, instance.instanceId);
194+
findBot = await findBotByTrigger(botRepository, content, instance.instanceId);
196195

197196
if (!findBot) {
198197
return;

src/api/integrations/chatbot/dify/controllers/dify.controller.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,7 @@ export class DifyController extends ChatbotController implements ChatbotControll
756756

757757
const content = getConversationMessage(msg);
758758

759-
let findBot = (await this.findBotTrigger(
760-
this.botRepository,
761-
this.settingsRepository,
762-
content,
763-
instance,
764-
session,
765-
)) as DifyModel;
759+
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as DifyModel;
766760

767761
if (!findBot) {
768762
const fallback = await this.settingsRepository.findFirst({

src/api/integrations/chatbot/evolutionBot/controllers/evolutionBot.controller.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,7 @@ export class EvolutionBotController extends ChatbotController implements Chatbot
728728

729729
const content = getConversationMessage(msg);
730730

731-
let findBot = (await this.findBotTrigger(
732-
this.botRepository,
733-
this.settingsRepository,
734-
content,
735-
instance,
736-
session,
737-
)) as EvolutionBot;
731+
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as EvolutionBot;
738732

739733
if (!findBot) {
740734
const fallback = await this.settingsRepository.findFirst({

src/api/integrations/chatbot/flowise/controllers/flowise.controller.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,7 @@ export class FlowiseController extends ChatbotController implements ChatbotContr
728728

729729
const content = getConversationMessage(msg);
730730

731-
let findBot = (await this.findBotTrigger(
732-
this.botRepository,
733-
this.settingsRepository,
734-
content,
735-
instance,
736-
session,
737-
)) as Flowise;
731+
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as Flowise;
738732

739733
if (!findBot) {
740734
const fallback = await this.settingsRepository.findFirst({

src/api/integrations/chatbot/openai/controllers/openai.controller.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -965,13 +965,7 @@ export class OpenaiController extends ChatbotController implements ChatbotContro
965965

966966
const content = getConversationMessage(msg);
967967

968-
let findBot = (await this.findBotTrigger(
969-
this.botRepository,
970-
this.settingsRepository,
971-
content,
972-
instance,
973-
session,
974-
)) as OpenaiBot;
968+
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as OpenaiBot;
975969

976970
if (!findBot) {
977971
const fallback = await this.settingsRepository.findFirst({

src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
943943

944944
const content = getConversationMessage(msg);
945945

946-
let findBot = (await this.findBotTrigger(
947-
this.botRepository,
948-
this.settingsRepository,
949-
content,
950-
instance,
951-
session,
952-
)) as TypebotModel;
946+
let findBot = (await this.findBotTrigger(this.botRepository, content, instance, session)) as TypebotModel;
953947

954948
if (!findBot) {
955949
const fallback = await this.settingsRepository.findFirst({

src/utils/findBotByTrigger.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
22

3-
export const findBotByTrigger = async (
4-
botRepository: any,
5-
settingsRepository: any,
6-
content: string,
7-
instanceId: string,
8-
) => {
3+
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
94
// Check for triggerType 'all'
105
const findTriggerAll = await botRepository.findFirst({
116
where: {

tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"emitDecoratorMetadata": true,
55
"declaration": true,
66
"target": "es2020",
7-
"module": "commonjs",
7+
"module": "NodeNext",
88
"rootDir": "./",
99
"resolveJsonModule": true,
1010
"removeComments": true,
@@ -26,7 +26,8 @@
2626
"@libs/*": ["./src/libs/*"],
2727
"@utils/*": ["./src/utils/*"],
2828
"@validate/*": ["./src/validate/*"]
29-
}
29+
},
30+
"moduleResolution": "NodeNext"
3031
},
3132
"exclude": ["node_modules", "./test", "./dist", "./prisma"],
3233
"include": [

0 commit comments

Comments
 (0)