mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
adjust in store files
This commit is contained in:
parent
db95de6731
commit
0a925df2a9
10
.gitignore
vendored
10
.gitignore
vendored
@ -11,15 +11,6 @@ yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
/store/auth/apikey/*
|
||||
/store/auth/jwt/*
|
||||
/store/baileys/*
|
||||
/store/chats/*
|
||||
/store/contacts/*
|
||||
/store/message-up/*
|
||||
/store/messages/*
|
||||
/store/webhook/*
|
||||
|
||||
/docker-compose-data
|
||||
|
||||
# Package
|
||||
@ -41,5 +32,6 @@ lerna-debug.log*
|
||||
!/instances/.gitkeep
|
||||
/test/
|
||||
/src/env.yml
|
||||
/store
|
||||
|
||||
/temp/*
|
||||
|
@ -1,5 +1,9 @@
|
||||
FROM node:16.18-alpine
|
||||
|
||||
LABEL version="1.1.3" description="Api to control whatsapp features through http requests."
|
||||
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
||||
LABEL contact="contato@agenciadgcode.com"
|
||||
|
||||
RUN apk update && apk upgrade && \
|
||||
apk add --no-cache git
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "evolution-api",
|
||||
"version": "1.2.0",
|
||||
"version": "1.1.3",
|
||||
"description": "Rest api for communication with WhatsApp",
|
||||
"main": "index.js",
|
||||
"main": "./dist/src/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "ts-node --files --transpile-only ./src/main.ts",
|
||||
|
@ -160,7 +160,9 @@ export class ConfigService {
|
||||
}
|
||||
|
||||
private envYaml(): Env {
|
||||
return load(readFileSync(join(SRC_DIR, 'env.yml'), { encoding: 'utf-8' })) as Env;
|
||||
return load(
|
||||
readFileSync(join(process.cwd(), 'src', 'env.yml'), { encoding: 'utf-8' }),
|
||||
) as Env;
|
||||
}
|
||||
|
||||
private envProcess(): Env {
|
||||
|
@ -5,6 +5,9 @@ import { MessageUpRepository } from './messageUp.repository';
|
||||
import { MongoClient } from 'mongodb';
|
||||
import { WebhookRepository } from './webhook.repository';
|
||||
import { AuthRepository } from './auth.repository';
|
||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||
import { execSync } from 'child_process';
|
||||
import { join } from 'path';
|
||||
|
||||
export class RepositoryBroker {
|
||||
constructor(
|
||||
@ -14,9 +17,11 @@ export class RepositoryBroker {
|
||||
public readonly messageUpdate: MessageUpRepository,
|
||||
public readonly webhook: WebhookRepository,
|
||||
public readonly auth: AuthRepository,
|
||||
private configService: ConfigService,
|
||||
dbServer?: MongoClient,
|
||||
) {
|
||||
this.dbClient = dbServer;
|
||||
this.__init_repo_without_db__();
|
||||
}
|
||||
|
||||
private dbClient?: MongoClient;
|
||||
@ -24,4 +29,22 @@ export class RepositoryBroker {
|
||||
public get dbServer() {
|
||||
return this.dbClient;
|
||||
}
|
||||
|
||||
private __init_repo_without_db__() {
|
||||
if (!this.configService.get<Database>('DATABASE').ENABLED) {
|
||||
const storePath = join(process.cwd(), 'store');
|
||||
execSync(
|
||||
`mkdir -p ${join(
|
||||
storePath,
|
||||
'auth',
|
||||
this.configService.get<Auth>('AUTHENTICATION').TYPE,
|
||||
)}`,
|
||||
);
|
||||
execSync(`mkdir -p ${join(storePath, 'chats')}`);
|
||||
execSync(`mkdir -p ${join(storePath, 'contacts')}`);
|
||||
execSync(`mkdir -p ${join(storePath, 'messages')}`);
|
||||
execSync(`mkdir -p ${join(storePath, 'message-up')}`);
|
||||
execSync(`mkdir -p ${join(storePath, 'webhook')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import makeWASocket, {
|
||||
WAMessageUpdate,
|
||||
WASocket,
|
||||
getAggregateVotesInPollMessage,
|
||||
makeInMemoryStore,
|
||||
} from '@whiskeysockets/baileys';
|
||||
import {
|
||||
Auth,
|
||||
@ -141,7 +140,6 @@ export class WAStartupService {
|
||||
private readonly userDevicesCache: CacheStore = new NodeCache();
|
||||
private endSession = false;
|
||||
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
|
||||
private store = makeInMemoryStore({ logger: P({ level: this.logBaileys }) });
|
||||
|
||||
public set instanceName(name: string) {
|
||||
if (!name) {
|
||||
@ -481,21 +479,30 @@ export class WAStartupService {
|
||||
if (full) {
|
||||
return webMessageInfo[0];
|
||||
}
|
||||
if (webMessageInfo[0].message?.pollCreationMessage) {
|
||||
const messageSecretBase64 =
|
||||
webMessageInfo[0].message?.messageContextInfo?.messageSecret;
|
||||
|
||||
if (typeof messageSecretBase64 === 'string') {
|
||||
const messageSecret = Buffer.from(messageSecretBase64, 'base64');
|
||||
|
||||
const msg = {
|
||||
messageContextInfo: {
|
||||
messageSecret,
|
||||
},
|
||||
pollCreationMessage: webMessageInfo[0].message?.pollCreationMessage,
|
||||
};
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
return webMessageInfo[0].message;
|
||||
} catch (error) {
|
||||
return { conversation: '' };
|
||||
}
|
||||
}
|
||||
|
||||
private async getMessageStore(key: proto.IMessageKey) {
|
||||
if (this.store) {
|
||||
const msg = await this.store.loadMessage(key.remoteJid, key.id);
|
||||
return msg?.message || undefined;
|
||||
}
|
||||
|
||||
return proto.Message.fromObject({});
|
||||
}
|
||||
|
||||
private cleanStore() {
|
||||
const cleanStore = this.configService.get<CleanStoreConf>('CLEAN_STORE');
|
||||
const database = this.configService.get<Database>('DATABASE');
|
||||
@ -551,12 +558,6 @@ export class WAStartupService {
|
||||
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
||||
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
||||
|
||||
this.store?.readFromFile(`${this.storePath}/baileys/store.json`);
|
||||
|
||||
setInterval(() => {
|
||||
this.store?.writeToFile(`${this.storePath}/baileys/store.json`);
|
||||
}, 10_000);
|
||||
|
||||
const socketConfig: UserFacingSocketConfig = {
|
||||
auth: {
|
||||
creds: this.instance.authState.state.creds,
|
||||
@ -574,7 +575,7 @@ export class WAStartupService {
|
||||
emitOwnEvents: false,
|
||||
msgRetryCounterCache: this.msgRetryCounterCache,
|
||||
getMessage: async (key) =>
|
||||
(await this.getMessageStore(key)) as Promise<proto.IMessage>,
|
||||
(await this.getMessage(key)) as Promise<proto.IMessage>,
|
||||
generateHighQualityLinkPreview: true,
|
||||
syncFullHistory: true,
|
||||
userDevicesCache: this.userDevicesCache,
|
||||
@ -607,8 +608,6 @@ export class WAStartupService {
|
||||
|
||||
this.client = makeWASocket(socketConfig);
|
||||
|
||||
this.store?.bind(this.client.ev);
|
||||
|
||||
this.eventHandler();
|
||||
|
||||
return this.client;
|
||||
@ -824,7 +823,7 @@ export class WAStartupService {
|
||||
) {
|
||||
let pollUpdates: any;
|
||||
if (update.pollUpdates) {
|
||||
const pollCreation = await this.getMessageStore(key);
|
||||
const pollCreation = await this.getMessage(key);
|
||||
if (pollCreation) {
|
||||
pollUpdates = getAggregateVotesInPollMessage({
|
||||
message: pollCreation as proto.IMessage,
|
||||
@ -1598,7 +1597,6 @@ export class WAStartupService {
|
||||
);
|
||||
const typeMessage = getContentType(msg.message);
|
||||
|
||||
// if for audioMessage converte para mp3
|
||||
if (convertToMp4 && typeMessage === 'audioMessage') {
|
||||
const number = msg.key.remoteJid.split('@')[0];
|
||||
const convert = await this.processAudio(buffer.toString('base64'), number);
|
||||
|
@ -47,6 +47,7 @@ export const repository = new RepositoryBroker(
|
||||
messageUpdateRepository,
|
||||
webhookRepository,
|
||||
authRepository,
|
||||
configService,
|
||||
dbserver?.getClient(),
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user