Skip to content

Commit 72dae22

Browse files
committed
Configuration to update source_id only when desired
1 parent cb942e5 commit 72dae22

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

src/config/env.config.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export type Websocket = {
7070
ENABLED: boolean;
7171
};
7272

73+
export type Chatwoot = {
74+
USE_REPLY_ID: boolean;
75+
};
76+
7377
export type EventsWebhook = {
7478
APPLICATION_STARTUP: boolean;
7579
QRCODE_UPDATED: boolean;
@@ -134,6 +138,7 @@ export interface Env {
134138
QRCODE: QrCode;
135139
AUTHENTICATION: Auth;
136140
PRODUCTION?: Production;
141+
CHATWOOT?: Chatwoot;
137142
}
138143

139144
export type Key = keyof Env;
@@ -224,9 +229,7 @@ export class ConfigService {
224229
COLOR: process.env?.LOG_COLOR === 'true',
225230
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
226231
},
227-
DEL_INSTANCE: process.env?.DEL_INSTANCE === 'true'
228-
? 5
229-
: Number.parseInt(process.env.DEL_INSTANCE) || false,
232+
DEL_INSTANCE: process.env?.DEL_INSTANCE === 'true' ? 5 : Number.parseInt(process.env.DEL_INSTANCE) || false,
230233
WEBHOOK: {
231234
GLOBAL: {
232235
URL: process.env?.WEBHOOK_GLOBAL_URL,
@@ -278,6 +281,9 @@ export class ConfigService {
278281
SECRET: process.env.AUTHENTICATION_JWT_SECRET,
279282
},
280283
},
284+
CHATWOOT: {
285+
USE_REPLY_ID: process.env?.USE_REPLY_ID === 'true',
286+
},
281287
};
282288
}
283289
}

src/dev-env.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,8 @@ AUTHENTICATION:
145145
# Set the secret key to encrypt and decrypt your token and its expiration time.
146146
JWT:
147147
EXPIRIN_IN: 0 # seconds - 3600s === 1h | zero (0) - never expires
148-
SECRET: L=0YWt]b2w[WF>#>:&E`
148+
SECRET: L=0YWt]b2w[WF>#>:&E`
149+
150+
# Configure to chatwoot
151+
CHATWOOT:
152+
USE_REPLY_ID: false

src/whatsapp/services/chatwoot.service.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createReadStream, readFileSync, unlinkSync, writeFileSync } from 'fs';
55
import mimeTypes from 'mime-types';
66
import path from 'path';
77

8-
import { ConfigService } from '../../config/env.config';
8+
import { Chatwoot, ConfigService } from '../../config/env.config';
99
import { Logger } from '../../config/logger.config';
1010
import { ROOT_DIR } from '../../config/path.config';
1111
import { ChatwootDto } from '../dto/chatwoot.dto';
@@ -966,25 +966,29 @@ export class ChatwootService {
966966
messageId: number,
967967
sourceId: string | null,
968968
) {
969-
this.logger.verbose('update message to chatwoot instance: ' + instance.instanceName);
970-
const client = await this.clientCw(instance);
969+
// const useReplyId = this.configService.get<DelInstance>('DEL_INSTANCE');
970+
const useReplyId = this.configService.get<Chatwoot>('CHATWOOT')?.USE_REPLY_ID;
971+
if (useReplyId === true) {
972+
this.logger.verbose('update message to chatwoot instance: ' + instance.instanceName);
973+
const client = await this.clientCw(instance);
971974

972-
if (!client) {
973-
this.logger.warn('client not found');
974-
return null;
975-
}
976-
this.logger.verbose('check if sourceId to update');
977-
if (sourceId) {
978-
this.logger.verbose('update message to chatwoot');
979-
const dataUpdated = {
980-
source_id: sourceId,
981-
};
982-
await client.messages.update({
983-
accountId,
984-
conversationId,
985-
data: dataUpdated,
986-
messageId,
987-
});
975+
if (!client) {
976+
this.logger.warn('client not found');
977+
return null;
978+
}
979+
this.logger.verbose('check if sourceId to update');
980+
if (sourceId) {
981+
this.logger.verbose('update message to chatwoot');
982+
const dataUpdated = {
983+
source_id: sourceId,
984+
};
985+
await client.messages.update({
986+
accountId,
987+
conversationId,
988+
data: dataUpdated,
989+
messageId,
990+
});
991+
}
988992
}
989993
}
990994

0 commit comments

Comments
 (0)