Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 22 additions & 9 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ export interface ExtendedIMessageKey extends proto.IMessageKey {
isViewOnce?: boolean;
}

export interface IMessageRaw {
key: ExtendedIMessageKey;
pushName?: string;
status?: string;
message: any;
contextInfo?: any;
messageType: string;
messageTimestamp: number;
instanceId: string;
source: string;
}

const groupMetadataCache = new CacheService(new CacheEngine(configService, 'groups').getEngine());

// Adicione a função getVideoDuration no início do arquivo
Expand Down Expand Up @@ -1234,22 +1246,23 @@ export class BaileysStartupService extends ChannelStartupService {
}

if (pollVote.encPayload && pollEncKey) {
const pollKey = pollMessage.key as ExtendedIMessageKey;
const creatorCandidates = [
this.instance.wuid,
this.client.user?.lid,
pollMessage.key.participant,
(pollMessage.key as any).participantAlt,
pollMessage.key.remoteJid,
pollKey.participant,
pollKey.participantAlt,
pollKey.remoteJid,
];

const key = received.key as any;
const receivedKey = received.key as ExtendedIMessageKey;
const voterCandidates = [
this.instance.wuid,
this.client.user?.lid,
key.participant,
key.participantAlt,
key.remoteJidAlt,
key.remoteJid,
receivedKey.participant,
receivedKey.participantAlt,
receivedKey.remoteJidAlt,
receivedKey.remoteJid,
];

const uniqueCreators = [
Expand Down Expand Up @@ -4649,7 +4662,7 @@ export class BaileysStartupService extends ChannelStartupService {
return obj;
}

private prepareMessage(message: proto.IWebMessageInfo): any {
private prepareMessage(message: proto.IWebMessageInfo): IMessageRaw {
const contentType = getContentType(message.message);
const contentMsg = message?.message[contentType] as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import i18next from '@utils/i18n';
import { sendTelemetry } from '@utils/sendTelemetry';
import axios from 'axios';
import { WAMessageContent, WAMessageKey } from 'baileys';
import { ExtendedIMessageKey } from '../../channel/whatsapp/whatsapp.baileys.service';
import dayjs from 'dayjs';
import FormData from 'form-data';
import { Jimp, JimpMime } from 'jimp';
Expand All @@ -41,6 +42,11 @@ interface ChatwootMessage {
isRead?: boolean;
}

interface MessageBodyWithExtendedKey {
key: ExtendedIMessageKey;
[key: string]: any;
}

export class ChatwootService {
private readonly logger = new Logger('ChatwootService');

Expand Down Expand Up @@ -629,7 +635,7 @@ export class ChatwootService {
return filterPayload;
}

public async createConversation(instance: InstanceDto, body: any) {
public async createConversation(instance: InstanceDto, body: MessageBodyWithExtendedKey) {
const isLid = body.key.addressingMode === 'lid';
const isGroup = body.key.remoteJid.endsWith('@g.us');
const phoneNumber = isLid && !isGroup ? body.key.remoteJidAlt : body.key.remoteJid;
Expand Down