Skip to content

Commit

Permalink
Update ESLint configuration, Dockerfile, and package dependencies; re…
Browse files Browse the repository at this point in the history
…factor 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.
  • Loading branch information
DavidsonGomes committed Jan 9, 2025
1 parent ca451bf commit d598c4e
Show file tree
Hide file tree
Showing 13 changed files with 1,716 additions and 2,107 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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

Expand Down
3,745 changes: 1,693 additions & 2,052 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/api/integrations/chatbot/chatbot.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,14 @@ export class ChatbotController {

public async findBotTrigger(
botRepository: any,
settingsRepository: any,
content: string,
instance: InstanceDto,
session?: IntegrationSession,
) {
let findBot: null;

if (!session) {
findBot = await findBotByTrigger(botRepository, settingsRepository, content, instance.instanceId);
findBot = await findBotByTrigger(botRepository, content, instance.instanceId);

if (!findBot) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 1 addition & 6 deletions src/utils/findBotByTrigger.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"emitDecoratorMetadata": true,
"declaration": true,
"target": "es2020",
"module": "commonjs",
"module": "NodeNext",
"rootDir": "./",
"resolveJsonModule": true,
"removeComments": true,
Expand All @@ -26,7 +26,8 @@
"@libs/*": ["./src/libs/*"],
"@utils/*": ["./src/utils/*"],
"@validate/*": ["./src/validate/*"]
}
},
"moduleResolution": "NodeNext"
},
"exclude": ["node_modules", "./test", "./dist", "./prisma"],
"include": [
Expand Down

0 comments on commit d598c4e

Please sign in to comment.