mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -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*
|
yarn-error.log*
|
||||||
lerna-debug.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
|
/docker-compose-data
|
||||||
|
|
||||||
# Package
|
# Package
|
||||||
@ -41,5 +32,6 @@ lerna-debug.log*
|
|||||||
!/instances/.gitkeep
|
!/instances/.gitkeep
|
||||||
/test/
|
/test/
|
||||||
/src/env.yml
|
/src/env.yml
|
||||||
|
/store
|
||||||
|
|
||||||
/temp/*
|
/temp/*
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
FROM node:16.18-alpine
|
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 && \
|
RUN apk update && apk upgrade && \
|
||||||
apk add --no-cache git
|
apk add --no-cache git
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.2.0",
|
"version": "1.1.3",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "index.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "ts-node --files --transpile-only ./src/main.ts",
|
"start": "ts-node --files --transpile-only ./src/main.ts",
|
||||||
|
@ -160,7 +160,9 @@ export class ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private envYaml(): Env {
|
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 {
|
private envProcess(): Env {
|
||||||
|
@ -5,6 +5,9 @@ import { MessageUpRepository } from './messageUp.repository';
|
|||||||
import { MongoClient } from 'mongodb';
|
import { MongoClient } from 'mongodb';
|
||||||
import { WebhookRepository } from './webhook.repository';
|
import { WebhookRepository } from './webhook.repository';
|
||||||
import { AuthRepository } from './auth.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 {
|
export class RepositoryBroker {
|
||||||
constructor(
|
constructor(
|
||||||
@ -14,9 +17,11 @@ export class RepositoryBroker {
|
|||||||
public readonly messageUpdate: MessageUpRepository,
|
public readonly messageUpdate: MessageUpRepository,
|
||||||
public readonly webhook: WebhookRepository,
|
public readonly webhook: WebhookRepository,
|
||||||
public readonly auth: AuthRepository,
|
public readonly auth: AuthRepository,
|
||||||
|
private configService: ConfigService,
|
||||||
dbServer?: MongoClient,
|
dbServer?: MongoClient,
|
||||||
) {
|
) {
|
||||||
this.dbClient = dbServer;
|
this.dbClient = dbServer;
|
||||||
|
this.__init_repo_without_db__();
|
||||||
}
|
}
|
||||||
|
|
||||||
private dbClient?: MongoClient;
|
private dbClient?: MongoClient;
|
||||||
@ -24,4 +29,22 @@ export class RepositoryBroker {
|
|||||||
public get dbServer() {
|
public get dbServer() {
|
||||||
return this.dbClient;
|
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,
|
WAMessageUpdate,
|
||||||
WASocket,
|
WASocket,
|
||||||
getAggregateVotesInPollMessage,
|
getAggregateVotesInPollMessage,
|
||||||
makeInMemoryStore,
|
|
||||||
} from '@whiskeysockets/baileys';
|
} from '@whiskeysockets/baileys';
|
||||||
import {
|
import {
|
||||||
Auth,
|
Auth,
|
||||||
@ -141,7 +140,6 @@ export class WAStartupService {
|
|||||||
private readonly userDevicesCache: CacheStore = new NodeCache();
|
private readonly userDevicesCache: CacheStore = new NodeCache();
|
||||||
private endSession = false;
|
private endSession = false;
|
||||||
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
|
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
|
||||||
private store = makeInMemoryStore({ logger: P({ level: this.logBaileys }) });
|
|
||||||
|
|
||||||
public set instanceName(name: string) {
|
public set instanceName(name: string) {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
@ -481,21 +479,30 @@ export class WAStartupService {
|
|||||||
if (full) {
|
if (full) {
|
||||||
return webMessageInfo[0];
|
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;
|
return webMessageInfo[0].message;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { conversation: '' };
|
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() {
|
private cleanStore() {
|
||||||
const cleanStore = this.configService.get<CleanStoreConf>('CLEAN_STORE');
|
const cleanStore = this.configService.get<CleanStoreConf>('CLEAN_STORE');
|
||||||
const database = this.configService.get<Database>('DATABASE');
|
const database = this.configService.get<Database>('DATABASE');
|
||||||
@ -551,12 +558,6 @@ export class WAStartupService {
|
|||||||
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
||||||
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
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 = {
|
const socketConfig: UserFacingSocketConfig = {
|
||||||
auth: {
|
auth: {
|
||||||
creds: this.instance.authState.state.creds,
|
creds: this.instance.authState.state.creds,
|
||||||
@ -574,7 +575,7 @@ export class WAStartupService {
|
|||||||
emitOwnEvents: false,
|
emitOwnEvents: false,
|
||||||
msgRetryCounterCache: this.msgRetryCounterCache,
|
msgRetryCounterCache: this.msgRetryCounterCache,
|
||||||
getMessage: async (key) =>
|
getMessage: async (key) =>
|
||||||
(await this.getMessageStore(key)) as Promise<proto.IMessage>,
|
(await this.getMessage(key)) as Promise<proto.IMessage>,
|
||||||
generateHighQualityLinkPreview: true,
|
generateHighQualityLinkPreview: true,
|
||||||
syncFullHistory: true,
|
syncFullHistory: true,
|
||||||
userDevicesCache: this.userDevicesCache,
|
userDevicesCache: this.userDevicesCache,
|
||||||
@ -607,8 +608,6 @@ export class WAStartupService {
|
|||||||
|
|
||||||
this.client = makeWASocket(socketConfig);
|
this.client = makeWASocket(socketConfig);
|
||||||
|
|
||||||
this.store?.bind(this.client.ev);
|
|
||||||
|
|
||||||
this.eventHandler();
|
this.eventHandler();
|
||||||
|
|
||||||
return this.client;
|
return this.client;
|
||||||
@ -824,7 +823,7 @@ export class WAStartupService {
|
|||||||
) {
|
) {
|
||||||
let pollUpdates: any;
|
let pollUpdates: any;
|
||||||
if (update.pollUpdates) {
|
if (update.pollUpdates) {
|
||||||
const pollCreation = await this.getMessageStore(key);
|
const pollCreation = await this.getMessage(key);
|
||||||
if (pollCreation) {
|
if (pollCreation) {
|
||||||
pollUpdates = getAggregateVotesInPollMessage({
|
pollUpdates = getAggregateVotesInPollMessage({
|
||||||
message: pollCreation as proto.IMessage,
|
message: pollCreation as proto.IMessage,
|
||||||
@ -1598,7 +1597,6 @@ export class WAStartupService {
|
|||||||
);
|
);
|
||||||
const typeMessage = getContentType(msg.message);
|
const typeMessage = getContentType(msg.message);
|
||||||
|
|
||||||
// if for audioMessage converte para mp3
|
|
||||||
if (convertToMp4 && typeMessage === 'audioMessage') {
|
if (convertToMp4 && typeMessage === 'audioMessage') {
|
||||||
const number = msg.key.remoteJid.split('@')[0];
|
const number = msg.key.remoteJid.split('@')[0];
|
||||||
const convert = await this.processAudio(buffer.toString('base64'), number);
|
const convert = await this.processAudio(buffer.toString('base64'), number);
|
||||||
|
@ -47,6 +47,7 @@ export const repository = new RepositoryBroker(
|
|||||||
messageUpdateRepository,
|
messageUpdateRepository,
|
||||||
webhookRepository,
|
webhookRepository,
|
||||||
authRepository,
|
authRepository,
|
||||||
|
configService,
|
||||||
dbserver?.getClient(),
|
dbserver?.getClient(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user