Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/api/integrations/channel/meta/whatsapp.business.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,14 @@
mediaType = 'video';
}

if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
this.logger?.info?.('Video upload attempted but is disabled by configuration.');
return {
success: false,
message: 'Video upload is currently disabled. Please contact support if you need this feature enabled.',

Check failure on line 466 in src/api/integrations/channel/meta/whatsapp.business.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `⏎·····················`
};
}

const mimetype = result.data?.mime_type || result.headers['content-type'];

const contentDisposition = result.headers['content-disposition'];
Expand Down Expand Up @@ -1205,9 +1213,8 @@
const token = this.token;

const headers = { Authorization: `Bearer ${token}` };
const url = `${this.configService.get<WaBusiness>('WA_BUSINESS').URL}/${
this.configService.get<WaBusiness>('WA_BUSINESS').VERSION
}/${this.number}/media`;
const url = `${this.configService.get<WaBusiness>('WA_BUSINESS').URL}/${this.configService.get<WaBusiness>('WA_BUSINESS').VERSION

Check failure on line 1216 in src/api/integrations/channel/meta/whatsapp.business.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `⏎········`
}/${this.number}/media`;

Check failure on line 1217 in src/api/integrations/channel/meta/whatsapp.business.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Delete `··`

const res = await axios.post(url, formData, { headers });
return res.data.id;
Expand Down
36 changes: 25 additions & 11 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
qrcodeTerminal.generate(qr, { small: true }, (qrcode) =>
this.logger.log(
`\n{ instance: ${this.instance.name} pairingCode: ${this.instance.qrcode.pairingCode}, qrcodeCount: ${this.instance.qrcode.count} }\n` +
qrcode,
qrcode,

Check failure on line 371 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
),
);

Expand Down Expand Up @@ -961,16 +961,16 @@

const messagesRepository: Set<string> = new Set(
chatwootImport.getRepositoryMessagesCache(instance) ??
(
await this.prismaRepository.message.findMany({
select: { key: true },
where: { instanceId: this.instanceId },
})
).map((message) => {
const key = message.key as { id: string };

return key.id;
}),
(

Check failure on line 964 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
await this.prismaRepository.message.findMany({

Check failure on line 965 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
select: { key: true },

Check failure on line 966 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Replace `··············` with `················`
where: { instanceId: this.instanceId },

Check failure on line 967 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
})

Check failure on line 968 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Replace `············` with `··············`
).map((message) => {

Check failure on line 969 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `··`
const key = message.key as { id: string };

return key.id;
}),
);

if (chatwootImport.getRepositoryMessagesCache(instance) === null) {
Expand Down Expand Up @@ -1188,6 +1188,8 @@
received?.message?.ptvMessage ||
received?.message?.audioMessage;

const isVideo = received?.message?.videoMessage;

if (this.localSettings.readMessages && received.key.id !== 'status@broadcast') {
await this.client.readMessages([received.key]);
}
Expand Down Expand Up @@ -1258,6 +1260,12 @@
if (isMedia) {
if (this.configService.get<S3>('S3').ENABLE) {
try {
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
this.logger.warn('Video upload is disabled. Skipping video upload.');
// Skip video upload by returning early from this block
return;
}

const message: any = received;

// Verificação adicional para garantir que há conteúdo de mídia real
Expand Down Expand Up @@ -2143,6 +2151,8 @@
messageSent?.message?.ptvMessage ||
messageSent?.message?.audioMessage;

const isVideo = messageSent?.message?.videoMessage;

if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) {
this.chatwootService.eventWhatsapp(
Events.SEND_MESSAGE,
Expand All @@ -2167,6 +2177,10 @@

if (isMedia && this.configService.get<S3>('S3').ENABLE) {
try {
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}

const message: any = messageRaw;

// Verificação adicional para garantir que há conteúdo de mídia real
Expand Down
2 changes: 2 additions & 0 deletions src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export type S3 = {
USE_SSL?: boolean;
REGION?: string;
SKIP_POLICY?: boolean;
SAVE_VIDEO?: boolean;
};

export type CacheConf = { REDIS: CacheConfRedis; LOCAL: CacheConfLocal };
Expand Down Expand Up @@ -653,6 +654,7 @@ export class ConfigService {
USE_SSL: process.env?.S3_USE_SSL === 'true',
REGION: process.env?.S3_REGION,
SKIP_POLICY: process.env?.S3_SKIP_POLICY === 'true',
SAVE_VIDEO: process.env?.S3_SAVE_VIDEO === 'true',
},
AUTHENTICATION: {
API_KEY: {
Expand Down
22 changes: 13 additions & 9 deletions src/utils/getConversationMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { configService, S3 } from '@config/env.config';
const getTypeMessage = (msg: any) => {
let mediaId: string;

if (configService.get<S3>('S3').ENABLE) mediaId = msg.message?.mediaUrl;
if (
configService.get<S3>('S3').ENABLE &&
(configService.get<S3>('S3').SAVE_VIDEO ||
(msg?.message?.videoMessage === undefined &&
msg?.message?.viewOnceMessageV2?.message?.videoMessage === undefined))
)
mediaId = msg.message?.mediaUrl;
else mediaId = msg.key?.id;

const types = {
Expand Down Expand Up @@ -32,16 +38,14 @@ const getTypeMessage = (msg: any) => {
? `videoMessage|${mediaId}${msg?.message?.videoMessage?.caption ? `|${msg?.message?.videoMessage?.caption}` : ''}`
: undefined,
documentMessage: msg?.message?.documentMessage
? `documentMessage|${mediaId}${
msg?.message?.documentMessage?.caption ? `|${msg?.message?.documentMessage?.caption}` : ''
}`
? `documentMessage|${mediaId}${msg?.message?.documentMessage?.caption ? `|${msg?.message?.documentMessage?.caption}` : ''
}`
: undefined,
documentWithCaptionMessage: msg?.message?.documentWithCaptionMessage?.message?.documentMessage
? `documentWithCaptionMessage|${mediaId}${
msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption
? `|${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption}`
: ''
}`
? `documentWithCaptionMessage|${mediaId}${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption
? `|${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption}`
: ''
}`
: undefined,
externalAdReplyBody: msg?.contextInfo?.externalAdReply?.body
? `externalAdReplyBody|${msg.contextInfo.externalAdReply.body}`
Expand Down