fix: Updated media handling in WhatsApp Baileys and Typebot services

This commit fixes issues with media handling in the WhatsApp Baileys and Typebot services. Specifically, it updates the way media messages are processed and stored. The changes include:

- Importing the `S3` class from the configuration in the Typebot service (`src/api/integrations/typebot/services/typebot.service.ts`).
- Modifying the `getTypeMessage` method in the Typebot service to handle media messages more efficiently.
- Refactoring the `BaileysStartupService` in the WhatsApp Baileys service (`src/api/services/channels/whatsapp.baileys.service.ts`) to handle media messages more consistently.

These changes improve the handling and storage of media messages, ensuring that they are processed correctly and efficiently.
This commit is contained in:
Davidson Gomes
2024-07-14 10:39:32 -03:00
parent e6916acf45
commit 484736facd
2 changed files with 67 additions and 74 deletions

View File

@@ -1,7 +1,7 @@
import { Message, Typebot as TypebotModel, TypebotSession } from '@prisma/client';
import axios from 'axios';
import { ConfigService, Typebot } from '../../../../config/env.config';
import { ConfigService, S3, Typebot } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { PrismaRepository } from '../../../repository/repository.service';
@@ -839,6 +839,11 @@ export class TypebotService {
}
private getTypeMessage(msg: any) {
let mediaId: string;
if (this.configService.get<S3>('S3').ENABLE) mediaId = msg.message.mediaUrl;
else mediaId = msg.key.id;
const types = {
conversation: msg?.message?.conversation,
extendedTextMessage: msg?.message?.extendedTextMessage?.text,
@@ -851,12 +856,12 @@ export class TypebotService {
listResponseMessage: msg?.message?.listResponseMessage?.singleSelectReply?.selectedRowId,
responseRowId: msg?.message?.listResponseMessage?.singleSelectReply?.selectedRowId,
// Medias
audioMessage: msg?.message?.audioMessage ? `audioMessage:${msg?.key?.id}` : undefined,
imageMessage: msg?.message?.imageMessage ? `imageMessage:${msg?.key?.id}` : undefined,
videoMessage: msg?.message?.videoMessage ? `videoMessage:${msg?.key?.id}` : undefined,
documentMessage: msg?.message?.documentMessage ? `documentMessage:${msg?.key?.id}` : undefined,
audioMessage: msg?.message?.audioMessage ? `audioMessage|${mediaId}` : undefined,
imageMessage: msg?.message?.imageMessage ? `imageMessage|${mediaId}` : undefined,
videoMessage: msg?.message?.videoMessage ? `videoMessage|${mediaId}` : undefined,
documentMessage: msg?.message?.documentMessage ? `documentMessage|${mediaId}` : undefined,
documentWithCaptionMessage: msg?.message?.auddocumentWithCaptionMessageioMessage
? `documentWithCaptionMessage:${msg?.key?.id}`
? `documentWithCaptionMessage|${mediaId}`
: undefined,
};