mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
fix: reorganize imports and improve message handling in BaileysStartupService
This commit is contained in:
parent
bbf60e30b0
commit
c7a2aa51ee
@ -76,19 +76,20 @@ import {
|
||||
S3,
|
||||
} from '@config/env.config';
|
||||
import { BadRequestException, InternalServerErrorException, NotFoundException } from '@exceptions';
|
||||
import { AuthStateProvider } from '@utils/use-multi-file-auth-state-provider-files';
|
||||
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
|
||||
import { Boom } from '@hapi/boom';
|
||||
import { createId as cuid } from '@paralleldrive/cuid2';
|
||||
import { Instance, Message } from '@prisma/client';
|
||||
import { createJid } from '@utils/createJid';
|
||||
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
|
||||
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
|
||||
import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent';
|
||||
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
|
||||
import { status } from '@utils/renderStatus';
|
||||
import { sendTelemetry } from '@utils/sendTelemetry';
|
||||
import useMultiFileAuthStatePrisma from '@utils/use-multi-file-auth-state-prisma';
|
||||
import { AuthStateProvider } from '@utils/use-multi-file-auth-state-provider-files';
|
||||
import { useMultiFileAuthStateRedisDb } from '@utils/use-multi-file-auth-state-redis-db';
|
||||
|
||||
import { BaileysMessageProcessor } from './baileysMessage.processor';
|
||||
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';
|
||||
|
||||
import axios from 'axios';
|
||||
import makeWASocket, {
|
||||
AnyMessageContent,
|
||||
BufferedEventData,
|
||||
@ -98,8 +99,8 @@ import makeWASocket, {
|
||||
Chat,
|
||||
ConnectionState,
|
||||
Contact,
|
||||
delay,
|
||||
decryptPollVote,
|
||||
delay,
|
||||
DisconnectReason,
|
||||
downloadContentFromMessage,
|
||||
downloadMediaMessage,
|
||||
@ -132,20 +133,16 @@ import makeWASocket, {
|
||||
} from 'baileys';
|
||||
import { Label } from 'baileys/lib/Types/Label';
|
||||
import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
|
||||
import { createId as cuid } from '@paralleldrive/cuid2';
|
||||
import { Instance, Message } from '@prisma/client';
|
||||
import axios from 'axios';
|
||||
import { spawn } from 'child_process';
|
||||
import { isArray, isBase64, isURL } from 'class-validator';
|
||||
import { createHash } from 'crypto';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
|
||||
import FormData from 'form-data';
|
||||
import { Boom } from '@hapi/boom';
|
||||
import Long from 'long';
|
||||
import mimeTypes from 'mime-types';
|
||||
import cron from 'node-cron';
|
||||
import NodeCache from 'node-cache';
|
||||
import cron from 'node-cron';
|
||||
import { release } from 'os';
|
||||
import { join } from 'path';
|
||||
import P from 'pino';
|
||||
@ -153,9 +150,11 @@ import qrcode, { QRCodeToDataURLOptions } from 'qrcode';
|
||||
import qrcodeTerminal from 'qrcode-terminal';
|
||||
import sharp from 'sharp';
|
||||
import { PassThrough, Readable } from 'stream';
|
||||
import { spawn } from 'child_process';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { BaileysMessageProcessor } from './baileysMessage.processor';
|
||||
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';
|
||||
|
||||
export interface ExtendedIMessageKey extends proto.IMessageKey {
|
||||
remoteJidAlt?: string;
|
||||
participantAlt?: string;
|
||||
@ -1250,9 +1249,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const uniqueCreators = [
|
||||
...new Set(creatorCandidates.filter(Boolean).map((id) => jidNormalizedUser(id))),
|
||||
];
|
||||
const uniqueVoters = [
|
||||
...new Set(voterCandidates.filter(Boolean).map((id) => jidNormalizedUser(id)))
|
||||
];
|
||||
const uniqueVoters = [...new Set(voterCandidates.filter(Boolean).map((id) => jidNormalizedUser(id)))];
|
||||
|
||||
let decryptedVote;
|
||||
|
||||
@ -1269,7 +1266,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
successfulVoterJid = voter;
|
||||
break;
|
||||
}
|
||||
} catch (_err) {
|
||||
} catch {
|
||||
// Continue trying
|
||||
}
|
||||
}
|
||||
@ -1350,7 +1347,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
}
|
||||
|
||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
|
||||
const { _pollUpdates, ...messageData } = messageRaw;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { pollUpdates, ...messageData } = messageRaw;
|
||||
const msg = await this.prismaRepository.message.create({ data: messageData });
|
||||
|
||||
const { remoteJid } = received.key;
|
||||
@ -1561,6 +1559,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const cached = await this.baileysCache.get(updateKey);
|
||||
|
||||
const secondsSinceEpoch = Math.floor(Date.now() / 1000);
|
||||
console.log('CACHE:', { cached, updateKey, messageTimestamp: update.messageTimestamp, secondsSinceEpoch });
|
||||
|
||||
if (
|
||||
(update.messageTimestamp && update.messageTimestamp === cached) ||
|
||||
@ -1692,7 +1691,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
this.sendDataWebhook(Events.MESSAGES_UPDATE, message);
|
||||
|
||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE) {
|
||||
const { message: __msg, ...messageData } = message;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { message: _msg, ...messageData } = message;
|
||||
await this.prismaRepository.messageUpdate.create({ data: messageData });
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user