mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
wip
This commit is contained in:
parent
cc91f2e5db
commit
e151eb85f0
11
.eslintrc.js
11
.eslintrc.js
@ -3,10 +3,14 @@ module.exports = {
|
||||
parserOptions: {
|
||||
sourceType: 'CommonJS',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
'simple-import-sort',
|
||||
'import'
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
'plugin:prettier/recommended'
|
||||
],
|
||||
globals: {
|
||||
@ -27,6 +31,9 @@ module.exports = {
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'import/first': 'error',
|
||||
'import/no-duplicates': 'error',
|
||||
'simple-import-sort/imports': 'error',
|
||||
'@typescript-eslint/ban-types': [
|
||||
'error',
|
||||
{
|
||||
|
13
package.json
13
package.json
@ -8,7 +8,8 @@
|
||||
"start": "ts-node --files --transpile-only ./src/main.ts",
|
||||
"start:prod": "bash start.sh",
|
||||
"dev:server": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts",
|
||||
"test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts"
|
||||
"test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts",
|
||||
"lint": "eslint --fix --ext .ts src"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -84,12 +85,14 @@
|
||||
"@types/qrcode": "^1.5.0",
|
||||
"@types/qrcode-terminal": "^0.12.0",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
||||
"@typescript-eslint/parser": "^5.57.1",
|
||||
"eslint": "^8.38.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"eslint": "^8.45.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"prettier": "^2.8.7",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { isBooleanString } from 'class-validator';
|
||||
import { readFileSync } from 'fs';
|
||||
import { load } from 'js-yaml';
|
||||
import { join } from 'path';
|
||||
import { isBooleanString } from 'class-validator';
|
||||
|
||||
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { configService, Log } from './env.config';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { configService, Log } from './env.config';
|
||||
|
||||
const formatDateLog = (timestamp: number) =>
|
||||
dayjs(timestamp)
|
||||
.toDate()
|
||||
|
@ -1,4 +1,5 @@
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import { configService, Database } from '../config/env.config';
|
||||
import { Logger } from '../config/logger.config';
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { createClient, RedisClientType } from '@redis/client';
|
||||
import { Logger } from '../config/logger.config';
|
||||
import { BufferJSON } from '@whiskeysockets/baileys';
|
||||
|
||||
import { Redis } from '../config/env.config';
|
||||
import { Logger } from '../config/logger.config';
|
||||
|
||||
export class RedisCache {
|
||||
constructor() {
|
||||
|
12
src/main.ts
12
src/main.ts
@ -1,16 +1,18 @@
|
||||
import 'express-async-errors';
|
||||
|
||||
// import * as Sentry from '@sentry/node';
|
||||
import compression from 'compression';
|
||||
import { configService, Cors, HttpServer } from './config/env.config';
|
||||
import cors from 'cors';
|
||||
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
||||
import { join } from 'path';
|
||||
|
||||
import { configService, Cors, HttpServer } from './config/env.config';
|
||||
import { onUnexpectedError } from './config/error.config';
|
||||
import { Logger } from './config/logger.config';
|
||||
import { ROOT_DIR } from './config/path.config';
|
||||
import { waMonitor } from './whatsapp/whatsapp.module';
|
||||
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
||||
import 'express-async-errors';
|
||||
import { ServerUP } from './utils/server-up';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
||||
import { waMonitor } from './whatsapp/whatsapp.module';
|
||||
|
||||
function initWA() {
|
||||
waMonitor.loadInstance();
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { Express } from 'express';
|
||||
import { readFileSync } from 'fs';
|
||||
import { configService, SslConf } from '../config/env.config';
|
||||
import * as https from 'https';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
|
||||
import { configService, SslConf } from '../config/env.config';
|
||||
|
||||
export class ServerUP {
|
||||
static #app: Express;
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
proto,
|
||||
SignalDataTypeMap,
|
||||
} from '@whiskeysockets/baileys';
|
||||
|
||||
import { configService, Database } from '../config/env.config';
|
||||
import { Logger } from '../config/logger.config';
|
||||
import { dbserver } from '../db/db.connect';
|
||||
@ -29,7 +30,9 @@ export async function useMultiFileAuthStateDb(
|
||||
JSON.parse(JSON.stringify(data, BufferJSON.replacer)),
|
||||
{ upsert: true },
|
||||
);
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const readData = async (key: string): Promise<any> => {
|
||||
@ -38,14 +41,18 @@ export async function useMultiFileAuthStateDb(
|
||||
const data = await collection.findOne({ _id: key });
|
||||
const creds = JSON.stringify(data);
|
||||
return JSON.parse(creds, BufferJSON.reviver);
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const removeData = async (key: string) => {
|
||||
try {
|
||||
await client.connect();
|
||||
return await collection.deleteOne({ _id: key });
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const creds: AuthenticationCreds = (await readData('creds')) || initAuthCreds();
|
||||
|
@ -5,9 +5,10 @@ import {
|
||||
proto,
|
||||
SignalDataTypeMap,
|
||||
} from '@whiskeysockets/baileys';
|
||||
import { RedisCache } from '../db/redis.client';
|
||||
import { Logger } from '../config/logger.config';
|
||||
|
||||
import { Redis } from '../config/env.config';
|
||||
import { Logger } from '../config/logger.config';
|
||||
import { RedisCache } from '../db/redis.client';
|
||||
|
||||
export async function useMultiFileAuthStateRedisDb(cache: RedisCache): Promise<{
|
||||
state: AuthenticationState;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService, Database } from '../../config/env.config';
|
||||
import { ROOT_DIR } from '../../config/path.config';
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { Request } from 'express';
|
||||
import { validate } from 'jsonschema';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import 'express-async-errors';
|
||||
|
||||
import { Request } from 'express';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { validate } from 'jsonschema';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { GetParticipant, GroupInvite, GroupJid } from '../dto/group.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
|
||||
type DataValidate<T> = {
|
||||
request: Request;
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { proto } from '@whiskeysockets/baileys';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import {
|
||||
ArchiveChatDto,
|
||||
DeleteMessage,
|
||||
getBase64FromMediaMessageDto,
|
||||
NumberDto,
|
||||
PrivacySettingDto,
|
||||
ProfileNameDto,
|
||||
@ -9,14 +12,12 @@ import {
|
||||
ProfileStatusDto,
|
||||
ReadMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
getBase64FromMediaMessageDto,
|
||||
} from '../dto/chat.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { ContactQuery } from '../repository/contact.repository';
|
||||
import { MessageQuery } from '../repository/message.repository';
|
||||
import { MessageUpQuery } from '../repository/messageUp.repository';
|
||||
import { WAMonitoringService } from '../services/monitor.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('ChatController');
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { isURL } from 'class-validator';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
import { ChatwootService } from '../services/chatwoot.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { waMonitor } from '../whatsapp.module';
|
||||
|
||||
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { ChatwootService } from '../services/chatwoot.service';
|
||||
import { waMonitor } from '../whatsapp.module';
|
||||
|
||||
const logger = new Logger('ChatwootController');
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import {
|
||||
CreateGroupDto,
|
||||
GetParticipant,
|
||||
@ -13,7 +14,6 @@ import {
|
||||
} from '../dto/group.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { WAMonitoringService } from '../services/monitor.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('ChatController');
|
||||
|
||||
|
@ -1,18 +1,19 @@
|
||||
import { delay } from '@whiskeysockets/baileys';
|
||||
import { isURL } from 'class-validator';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
|
||||
import { Auth, ConfigService, HttpServer } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { RepositoryBroker } from '../repository/repository.manager';
|
||||
import { AuthService, OldToken } from '../services/auth.service';
|
||||
import { WAMonitoringService } from '../services/monitor.service';
|
||||
import { WAStartupService } from '../services/whatsapp.service';
|
||||
import { WebhookService } from '../services/webhook.service';
|
||||
import { ChatwootService } from '../services/chatwoot.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { WAMonitoringService } from '../services/monitor.service';
|
||||
import { WebhookService } from '../services/webhook.service';
|
||||
import { WAStartupService } from '../services/whatsapp.service';
|
||||
import { wa } from '../types/wa.types';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { isURL } from 'class-validator';
|
||||
|
||||
export class InstanceController {
|
||||
constructor(
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { isBase64, isURL } from 'class-validator';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import {
|
||||
@ -16,8 +18,6 @@ import {
|
||||
} from '../dto/sendMessage.dto';
|
||||
import { WAMonitoringService } from '../services/monitor.service';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('MessageRouter');
|
||||
|
||||
export class SendMessageController {
|
||||
@ -109,7 +109,7 @@ export class SendMessageController {
|
||||
|
||||
public async sendReaction({ instanceName }: InstanceDto, data: SendReactionDto) {
|
||||
logger.verbose('requested sendReaction from ' + instanceName + ' instance');
|
||||
if (!data.reactionMessage.reaction.match(/[^\(\)\w\sà-ú"-\+]+/)) {
|
||||
if (!data.reactionMessage.reaction.match(/[^()\w\sà-ú"-+]+/)) {
|
||||
throw new BadRequestException('"reaction" must be an emoji');
|
||||
}
|
||||
return await this.waMonitor.waInstances[instanceName].reactionMessage(data);
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { isURL } from 'class-validator';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { SettingsDto } from '../dto/settings.dto';
|
||||
import { SettingsService } from '../services/settings.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('SettingsController');
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
import { Auth, ConfigService } from '../../config/env.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { isURL } from 'class-validator';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { WebhookDto } from '../dto/webhook.dto';
|
||||
import { WebhookService } from '../services/webhook.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('WebhookController');
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import {
|
||||
proto,
|
||||
WAPrivacyOnlineValue,
|
||||
WAPrivacyValue,
|
||||
WAReadReceiptsValue,
|
||||
proto,
|
||||
} from '@whiskeysockets/baileys';
|
||||
|
||||
export class OnWhatsAppDto {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { isJWT } from 'class-validator';
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
import { name } from '../../../package.json';
|
||||
import { Auth, configService } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { name } from '../../../package.json';
|
||||
import { ForbiddenException, UnauthorizedException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { JwtPayload } from '../services/auth.service';
|
||||
import { ForbiddenException, UnauthorizedException } from '../../exceptions';
|
||||
import { repository } from '../whatsapp.module';
|
||||
|
||||
const logger = new Logger('GUARD');
|
||||
@ -86,7 +87,9 @@ async function apikey(req: Request, res: Response, next: NextFunction) {
|
||||
if (instanceKey.apikey === key) {
|
||||
return next();
|
||||
}
|
||||
} catch (error) {}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
}
|
||||
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
import { existsSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { configService, Database, Redis } from '../../config/env.config';
|
||||
import { INSTANCE_DIR } from '../../config/path.config';
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import {
|
||||
@ -10,7 +12,6 @@ import {
|
||||
} from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { cache, waMonitor } from '../whatsapp.module';
|
||||
import { Database, Redis, configService } from '../../config/env.config';
|
||||
|
||||
async function getInstance(instanceName: string) {
|
||||
const db = configService.get<Database>('DATABASE');
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Schema } from 'mongoose';
|
||||
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
|
||||
export class AuthRaw {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Schema } from 'mongoose';
|
||||
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
|
||||
export class ChatRaw {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Schema } from 'mongoose';
|
||||
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
|
||||
export class ChatwootRaw {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Schema } from 'mongoose';
|
||||
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
|
||||
export class ContactRaw {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Schema } from 'mongoose';
|
||||
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import { wa } from '../types/wa.types';
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Schema } from 'mongoose';
|
||||
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
|
||||
export class SettingsRaw {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Schema } from 'mongoose';
|
||||
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
|
||||
export class WebhookRaw {
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { join } from 'path';
|
||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { IAuthModel, AuthRaw } from '../models';
|
||||
import { readFileSync } from 'fs';
|
||||
import { AUTH_DIR } from '../../config/path.config';
|
||||
import { join } from 'path';
|
||||
|
||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { AUTH_DIR } from '../../config/path.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { AuthRaw, IAuthModel } from '../models';
|
||||
|
||||
export class AuthRepository extends Repository {
|
||||
constructor(
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { join } from 'path';
|
||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { opendirSync, readFileSync, rmSync } from 'fs';
|
||||
import { ChatRaw, IChatModel } from '../models';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { ChatRaw, IChatModel } from '../models';
|
||||
|
||||
export class ChatQuery {
|
||||
where: ChatRaw;
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { ConfigService } from '../../config/env.config';
|
||||
import { join } from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { IChatwootModel, ChatwootRaw } from '../models';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { ChatwootRaw, IChatwootModel } from '../models';
|
||||
|
||||
export class ChatwootRepository extends Repository {
|
||||
constructor(
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { opendirSync, readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||
import { ContactRaw, IContactModel } from '../models';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { ContactRaw, IContactModel } from '../models';
|
||||
|
||||
export class ContactQuery {
|
||||
where: ContactRaw;
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||
import { join } from 'path';
|
||||
import { IMessageModel, MessageRaw } from '../models';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { opendirSync, readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { IMessageModel, MessageRaw } from '../models';
|
||||
|
||||
export class MessageQuery {
|
||||
where: MessageRaw;
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||
import { IMessageUpModel, MessageUpdateRaw } from '../models';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { join } from 'path';
|
||||
import { opendirSync, readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService, StoreConf } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { IMessageUpModel, MessageUpdateRaw } from '../models';
|
||||
|
||||
export class MessageUpQuery {
|
||||
where: MessageUpdateRaw;
|
||||
|
@ -1,17 +1,17 @@
|
||||
import { MessageRepository } from './message.repository';
|
||||
import { ChatRepository } from './chat.repository';
|
||||
import { ContactRepository } from './contact.repository';
|
||||
import { MessageUpRepository } from './messageUp.repository';
|
||||
import { MongoClient } from 'mongodb';
|
||||
import { WebhookRepository } from './webhook.repository';
|
||||
import { ChatwootRepository } from './chatwoot.repository';
|
||||
import { SettingsRepository } from './settings.repository';
|
||||
|
||||
import { AuthRepository } from './auth.repository';
|
||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||
import { join } from 'path';
|
||||
import fs from 'fs';
|
||||
import { MongoClient } from 'mongodb';
|
||||
import { join } from 'path';
|
||||
|
||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { AuthRepository } from './auth.repository';
|
||||
import { ChatRepository } from './chat.repository';
|
||||
import { ChatwootRepository } from './chatwoot.repository';
|
||||
import { ContactRepository } from './contact.repository';
|
||||
import { MessageRepository } from './message.repository';
|
||||
import { MessageUpRepository } from './messageUp.repository';
|
||||
import { SettingsRepository } from './settings.repository';
|
||||
import { WebhookRepository } from './webhook.repository';
|
||||
export class RepositoryBroker {
|
||||
constructor(
|
||||
public readonly message: MessageRepository,
|
||||
@ -97,17 +97,17 @@ export class RepositoryBroker {
|
||||
this.logger.error(error);
|
||||
}
|
||||
} else {
|
||||
const storePath = join(process.cwd(), 'store');
|
||||
|
||||
this.logger.verbose('creating store path: ' + storePath);
|
||||
|
||||
const tempDir = join(storePath, 'temp');
|
||||
|
||||
if (!fs.existsSync(tempDir)) {
|
||||
this.logger.verbose('creating temp dir: ' + tempDir);
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
}
|
||||
try {
|
||||
const storePath = join(process.cwd(), 'store');
|
||||
|
||||
this.logger.verbose('creating store path: ' + storePath);
|
||||
|
||||
const tempDir = join(storePath, 'temp');
|
||||
|
||||
if (!fs.existsSync(tempDir)) {
|
||||
this.logger.verbose('creating temp dir: ' + tempDir);
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { ConfigService } from '../../config/env.config';
|
||||
import { join } from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { ISettingsModel, SettingsRaw } from '../models';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { ISettingsModel, SettingsRaw } from '../models';
|
||||
|
||||
export class SettingsRepository extends Repository {
|
||||
constructor(
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { ConfigService } from '../../config/env.config';
|
||||
import { join } from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { IWebhookModel, WebhookRaw } from '../models';
|
||||
import { join } from 'path';
|
||||
|
||||
import { ConfigService } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { IInsert, Repository } from '../abstract/abstract.repository';
|
||||
import { IWebhookModel, WebhookRaw } from '../models';
|
||||
|
||||
export class WebhookRepository extends Repository {
|
||||
constructor(
|
||||
|
@ -1,4 +1,7 @@
|
||||
import { proto } from '@whiskeysockets/baileys';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import {
|
||||
archiveChatSchema,
|
||||
contactValidateSchema,
|
||||
@ -13,9 +16,11 @@ import {
|
||||
readMessageSchema,
|
||||
whatsappNumberSchema,
|
||||
} from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import {
|
||||
ArchiveChatDto,
|
||||
DeleteMessage,
|
||||
getBase64FromMediaMessageDto,
|
||||
NumberDto,
|
||||
PrivacySettingDto,
|
||||
ProfileNameDto,
|
||||
@ -23,17 +28,13 @@ import {
|
||||
ProfileStatusDto,
|
||||
ReadMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
getBase64FromMediaMessageDto,
|
||||
} from '../dto/chat.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { ContactQuery } from '../repository/contact.repository';
|
||||
import { MessageQuery } from '../repository/message.repository';
|
||||
import { chatController } from '../whatsapp.module';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { HttpStatus } from './index.router';
|
||||
import { MessageUpQuery } from '../repository/messageUp.repository';
|
||||
import { proto } from '@whiskeysockets/baileys';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { chatController } from '../whatsapp.module';
|
||||
import { HttpStatus } from './index.router';
|
||||
|
||||
const logger = new Logger('ChatRouter');
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
import { instanceNameSchema, chatwootSchema } from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
import { chatwootController } from '../whatsapp.module';
|
||||
import { ChatwootService } from '../services/chatwoot.service';
|
||||
import { HttpStatus } from './index.router';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { chatwootSchema, instanceNameSchema } from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { ChatwootService } from '../services/chatwoot.service';
|
||||
import { chatwootController } from '../whatsapp.module';
|
||||
import { HttpStatus } from './index.router';
|
||||
|
||||
const logger = new Logger('ChatwootRouter');
|
||||
|
||||
|
@ -1,34 +1,35 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import {
|
||||
createGroupSchema,
|
||||
getParticipantsSchema,
|
||||
groupInviteSchema,
|
||||
groupJidSchema,
|
||||
updateParticipantsSchema,
|
||||
updateSettingsSchema,
|
||||
groupSendInviteSchema,
|
||||
toggleEphemeralSchema,
|
||||
updateGroupDescriptionSchema,
|
||||
updateGroupPictureSchema,
|
||||
updateGroupSubjectSchema,
|
||||
updateGroupDescriptionSchema,
|
||||
groupInviteSchema,
|
||||
groupSendInviteSchema,
|
||||
getParticipantsSchema,
|
||||
updateParticipantsSchema,
|
||||
updateSettingsSchema,
|
||||
} from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import {
|
||||
CreateGroupDto,
|
||||
GetParticipant,
|
||||
GroupDescriptionDto,
|
||||
GroupInvite,
|
||||
GroupJid,
|
||||
GroupPictureDto,
|
||||
GroupSendInvite,
|
||||
GroupSubjectDto,
|
||||
GroupDescriptionDto,
|
||||
GroupToggleEphemeralDto,
|
||||
GroupUpdateParticipantDto,
|
||||
GroupUpdateSettingDto,
|
||||
GroupToggleEphemeralDto,
|
||||
GroupSendInvite,
|
||||
GetParticipant,
|
||||
} from '../dto/group.dto';
|
||||
import { groupController } from '../whatsapp.module';
|
||||
import { HttpStatus } from './index.router';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('GroupRouter');
|
||||
|
||||
|
@ -1,16 +1,17 @@
|
||||
import { Router } from 'express';
|
||||
import fs from 'fs';
|
||||
|
||||
import { Auth, configService } from '../../config/env.config';
|
||||
import { instanceExistsGuard, instanceLoggedGuard } from '../guards/instance.guard';
|
||||
import { authGuard } from '../guards/auth.guard';
|
||||
import { instanceExistsGuard, instanceLoggedGuard } from '../guards/instance.guard';
|
||||
import { ChatRouter } from './chat.router';
|
||||
import { ChatwootRouter } from './chatwoot.router';
|
||||
import { GroupRouter } from './group.router';
|
||||
import { InstanceRouter } from './instance.router';
|
||||
import { MessageRouter } from './sendMessage.router';
|
||||
import { SettingsRouter } from './settings.router';
|
||||
import { ViewsRouter } from './view.router';
|
||||
import { WebhookRouter } from './webhook.router';
|
||||
import { ChatwootRouter } from './chatwoot.router';
|
||||
import fs from 'fs';
|
||||
import { SettingsRouter } from './settings.router';
|
||||
|
||||
enum HttpStatus {
|
||||
OK = 200,
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
import { instanceNameSchema, oldTokenSchema } from '../../validate/validate.schema';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { instanceController } from '../whatsapp.module';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { HttpStatus } from './index.router';
|
||||
import { OldToken } from '../services/auth.service';
|
||||
|
||||
import { Auth, ConfigService, Database } from '../../config/env.config';
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import { instanceNameSchema, oldTokenSchema } from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { OldToken } from '../services/auth.service';
|
||||
import { instanceController } from '../whatsapp.module';
|
||||
import { HttpStatus } from './index.router';
|
||||
|
||||
const logger = new Logger('InstanceRouter');
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import {
|
||||
audioMessageSchema,
|
||||
buttonMessageSchema,
|
||||
@ -12,6 +14,7 @@ import {
|
||||
stickerMessageSchema,
|
||||
textMessageSchema,
|
||||
} from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import {
|
||||
SendAudioDto,
|
||||
SendButtonDto,
|
||||
@ -26,9 +29,7 @@ import {
|
||||
SendTextDto,
|
||||
} from '../dto/sendMessage.dto';
|
||||
import { sendMessageController } from '../whatsapp.module';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { HttpStatus } from './index.router';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('MessageRouter');
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { instanceNameSchema, settingsSchema } from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { SettingsDto } from '../dto/settings.dto';
|
||||
import { settingsController } from '../whatsapp.module';
|
||||
import { SettingsService } from '../services/settings.service';
|
||||
import { settingsController } from '../whatsapp.module';
|
||||
import { HttpStatus } from './index.router';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('SettingsRouter');
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { viewsController } from '../whatsapp.module';
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { instanceNameSchema, webhookSchema } from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { WebhookDto } from '../dto/webhook.dto';
|
||||
import { webhookController } from '../whatsapp.module';
|
||||
import { HttpStatus } from './index.router';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
const logger = new Logger('WebhookRouter');
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
import { Auth, ConfigService, Webhook } from '../../config/env.config';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { name as apiName } from '../../../package.json';
|
||||
import { verify, sign } from 'jsonwebtoken';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { v4 } from 'uuid';
|
||||
import { isJWT } from 'class-validator';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import axios from 'axios';
|
||||
import { WAMonitoringService } from './monitor.service';
|
||||
import { isJWT } from 'class-validator';
|
||||
import { sign, verify } from 'jsonwebtoken';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { name as apiName } from '../../../package.json';
|
||||
import { Auth, ConfigService, Webhook } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { RepositoryBroker } from '../repository/repository.manager';
|
||||
import { WAMonitoringService } from './monitor.service';
|
||||
|
||||
export type JwtPayload = {
|
||||
instanceName: string;
|
||||
|
@ -1,18 +1,17 @@
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import path from 'path';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
import { WAMonitoringService } from './monitor.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import ChatwootClient from '@figuro/chatwoot-sdk';
|
||||
import { createReadStream, readFileSync, unlinkSync, writeFileSync } from 'fs';
|
||||
import axios from 'axios';
|
||||
import FormData from 'form-data';
|
||||
import { SendTextDto } from '../dto/sendMessage.dto';
|
||||
import { createReadStream, readFileSync, unlinkSync, writeFileSync } from 'fs';
|
||||
import mimeTypes from 'mime-types';
|
||||
import { SendAudioDto } from '../dto/sendMessage.dto';
|
||||
import { SendMediaDto } from '../dto/sendMessage.dto';
|
||||
import { ROOT_DIR } from '../../config/path.config';
|
||||
import path from 'path';
|
||||
|
||||
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { ROOT_DIR } from '../../config/path.config';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { SendAudioDto, SendMediaDto, SendTextDto } from '../dto/sendMessage.dto';
|
||||
import { WAMonitoringService } from './monitor.service';
|
||||
|
||||
export class ChatwootService {
|
||||
private messageCacheFile: string;
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { opendirSync, readdirSync, rmSync } from 'fs';
|
||||
import { WAStartupService } from './whatsapp.service';
|
||||
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
|
||||
import { execSync } from 'child_process';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
import { opendirSync, readdirSync, rmSync } from 'fs';
|
||||
import { Db } from 'mongodb';
|
||||
import mongoose from 'mongoose';
|
||||
import { join } from 'path';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
import {
|
||||
Auth,
|
||||
ConfigService,
|
||||
@ -12,13 +13,11 @@ import {
|
||||
HttpServer,
|
||||
Redis,
|
||||
} from '../../config/env.config';
|
||||
import { RepositoryBroker } from '../repository/repository.manager';
|
||||
import { NotFoundException } from '../../exceptions';
|
||||
import { Db } from 'mongodb';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { execSync } from 'child_process';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import mongoose from 'mongoose';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { NotFoundException } from '../../exceptions';
|
||||
import {
|
||||
AuthModel,
|
||||
ChatwootModel,
|
||||
@ -28,6 +27,8 @@ import {
|
||||
SettingsModel,
|
||||
WebhookModel,
|
||||
} from '../models';
|
||||
import { RepositoryBroker } from '../repository/repository.manager';
|
||||
import { WAStartupService } from './whatsapp.service';
|
||||
|
||||
export class WAMonitoringService {
|
||||
constructor(
|
||||
@ -183,7 +184,7 @@ export class WAMonitoringService {
|
||||
});
|
||||
this.logger.verbose('instance files deleted: ' + name);
|
||||
});
|
||||
} else if (this.redis.ENABLED) {
|
||||
// } else if (this.redis.ENABLED) {
|
||||
} else {
|
||||
const dir = opendirSync(INSTANCE_DIR, { encoding: 'utf-8' });
|
||||
for await (const dirent of dir) {
|
||||
@ -337,7 +338,9 @@ export class WAMonitoringService {
|
||||
try {
|
||||
this.logger.verbose('instance: ' + instanceName + ' - removing from memory');
|
||||
this.waInstances[instanceName] = undefined;
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
|
||||
try {
|
||||
this.logger.verbose('request cleaning up instance: ' + instanceName);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { SettingsDto } from '../dto/settings.dto';
|
||||
import { WAMonitoringService } from './monitor.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
export class SettingsService {
|
||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { WebhookDto } from '../dto/webhook.dto';
|
||||
import { WAMonitoringService } from './monitor.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
|
||||
export class WebhookService {
|
||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
|
||||
import { Boom } from '@hapi/boom';
|
||||
import makeWASocket, {
|
||||
AnyMessageContent,
|
||||
BufferedEventData,
|
||||
BufferJSON,
|
||||
CacheStore,
|
||||
makeCacheableSignalKeyStore,
|
||||
Chat,
|
||||
ConnectionState,
|
||||
Contact,
|
||||
@ -12,11 +13,13 @@ import makeWASocket, {
|
||||
downloadMediaMessage,
|
||||
fetchLatestBaileysVersion,
|
||||
generateWAMessageFromContent,
|
||||
getAggregateVotesInPollMessage,
|
||||
getContentType,
|
||||
getDevice,
|
||||
GroupMetadata,
|
||||
isJidGroup,
|
||||
isJidUser,
|
||||
makeCacheableSignalKeyStore,
|
||||
MessageUpsertType,
|
||||
MiscMessageGenerationOptions,
|
||||
ParticipantAction,
|
||||
@ -29,8 +32,24 @@ import makeWASocket, {
|
||||
WAMessage,
|
||||
WAMessageUpdate,
|
||||
WASocket,
|
||||
getAggregateVotesInPollMessage,
|
||||
} from '@whiskeysockets/baileys';
|
||||
import axios from 'axios';
|
||||
import { exec, execSync } from 'child_process';
|
||||
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
import fs, { existsSync, readFileSync } from 'fs';
|
||||
import Long from 'long';
|
||||
import NodeCache from 'node-cache';
|
||||
import { getMIMEType } from 'node-mime-types';
|
||||
import { release } from 'os';
|
||||
import { join } from 'path';
|
||||
import P from 'pino';
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import qrcode, { QRCodeToDataURLOptions } from 'qrcode';
|
||||
import qrcodeTerminal from 'qrcode-terminal';
|
||||
import sharp from 'sharp';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import {
|
||||
Auth,
|
||||
CleanStoreConf,
|
||||
@ -38,31 +57,45 @@ import {
|
||||
ConfigSessionPhone,
|
||||
Database,
|
||||
HttpServer,
|
||||
Log,
|
||||
QrCode,
|
||||
Redis,
|
||||
Webhook,
|
||||
} from '../../config/env.config';
|
||||
import fs from 'fs';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { INSTANCE_DIR, ROOT_DIR } from '../../config/path.config';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import axios from 'axios';
|
||||
import { v4 } from 'uuid';
|
||||
import qrcode, { QRCodeToDataURLOptions } from 'qrcode';
|
||||
import qrcodeTerminal from 'qrcode-terminal';
|
||||
import { Events, TypeMediaMessage, wa, MessageSubtype } from '../types/wa.types';
|
||||
import { Boom } from '@hapi/boom';
|
||||
import EventEmitter2 from 'eventemitter2';
|
||||
import { release } from 'os';
|
||||
import P from 'pino';
|
||||
import { execSync, exec } from 'child_process';
|
||||
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
|
||||
import { RepositoryBroker } from '../repository/repository.manager';
|
||||
import { MessageRaw, MessageUpdateRaw } from '../models/message.model';
|
||||
import { ContactRaw } from '../models/contact.model';
|
||||
import { ChatRaw } from '../models/chat.model';
|
||||
import { getMIMEType } from 'node-mime-types';
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import {
|
||||
BadRequestException,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
} from '../../exceptions';
|
||||
import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db';
|
||||
import { useMultiFileAuthStateRedisDb } from '../../utils/use-multi-file-auth-state-redis-db';
|
||||
import {
|
||||
ArchiveChatDto,
|
||||
DeleteMessage,
|
||||
getBase64FromMediaMessageDto,
|
||||
NumberBusiness,
|
||||
OnWhatsAppDto,
|
||||
PrivacySettingDto,
|
||||
ReadMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
} from '../dto/chat.dto';
|
||||
import {
|
||||
CreateGroupDto,
|
||||
GetParticipant,
|
||||
GroupDescriptionDto,
|
||||
GroupInvite,
|
||||
GroupJid,
|
||||
GroupPictureDto,
|
||||
GroupSendInvite,
|
||||
GroupSubjectDto,
|
||||
GroupToggleEphemeralDto,
|
||||
GroupUpdateParticipantDto,
|
||||
GroupUpdateSettingDto,
|
||||
} from '../dto/group.dto';
|
||||
import {
|
||||
ContactMessage,
|
||||
MediaMessage,
|
||||
@ -73,59 +106,26 @@ import {
|
||||
SendListDto,
|
||||
SendLocationDto,
|
||||
SendMediaDto,
|
||||
SendReactionDto,
|
||||
SendTextDto,
|
||||
SendPollDto,
|
||||
SendStickerDto,
|
||||
SendReactionDto,
|
||||
SendStatusDto,
|
||||
SendStickerDto,
|
||||
SendTextDto,
|
||||
StatusMessage,
|
||||
} from '../dto/sendMessage.dto';
|
||||
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
||||
import {
|
||||
ArchiveChatDto,
|
||||
DeleteMessage,
|
||||
NumberBusiness,
|
||||
OnWhatsAppDto,
|
||||
PrivacySettingDto,
|
||||
ReadMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
getBase64FromMediaMessageDto,
|
||||
} from '../dto/chat.dto';
|
||||
import { MessageQuery } from '../repository/message.repository';
|
||||
import { ContactQuery } from '../repository/contact.repository';
|
||||
import {
|
||||
BadRequestException,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
} from '../../exceptions';
|
||||
import {
|
||||
CreateGroupDto,
|
||||
GroupInvite,
|
||||
GroupJid,
|
||||
GroupPictureDto,
|
||||
GroupUpdateParticipantDto,
|
||||
GroupUpdateSettingDto,
|
||||
GroupToggleEphemeralDto,
|
||||
GroupSubjectDto,
|
||||
GroupDescriptionDto,
|
||||
GroupSendInvite,
|
||||
GetParticipant,
|
||||
} from '../dto/group.dto';
|
||||
import { MessageUpQuery } from '../repository/messageUp.repository';
|
||||
import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db';
|
||||
import Long from 'long';
|
||||
import { WebhookRaw } from '../models/webhook.model';
|
||||
import { ChatwootRaw } from '../models/chatwoot.model';
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import NodeCache from 'node-cache';
|
||||
import { useMultiFileAuthStateRedisDb } from '../../utils/use-multi-file-auth-state-redis-db';
|
||||
import sharp from 'sharp';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
import { Log } from '../../config/env.config';
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import { ChatwootService } from './chatwoot.service';
|
||||
import { waMonitor } from '../whatsapp.module';
|
||||
import { SettingsRaw } from '../models';
|
||||
import { ChatRaw } from '../models/chat.model';
|
||||
import { ChatwootRaw } from '../models/chatwoot.model';
|
||||
import { ContactRaw } from '../models/contact.model';
|
||||
import { MessageRaw, MessageUpdateRaw } from '../models/message.model';
|
||||
import { WebhookRaw } from '../models/webhook.model';
|
||||
import { ContactQuery } from '../repository/contact.repository';
|
||||
import { MessageQuery } from '../repository/message.repository';
|
||||
import { MessageUpQuery } from '../repository/messageUp.repository';
|
||||
import { RepositoryBroker } from '../repository/repository.manager';
|
||||
import { Events, MessageSubtype, TypeMediaMessage, wa } from '../types/wa.types';
|
||||
import { waMonitor } from '../whatsapp.module';
|
||||
import { ChatwootService } from './chatwoot.service';
|
||||
|
||||
export class WAStartupService {
|
||||
constructor(
|
||||
@ -395,7 +395,7 @@ export class WAStartupService {
|
||||
const webhookGlobal = this.configService.get<Webhook>('WEBHOOK');
|
||||
const webhookLocal = this.localWebhook.events;
|
||||
const serverUrl = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const we = event.replace(/[\.-]/gm, '_').toUpperCase();
|
||||
const we = event.replace(/[.-]/gm, '_').toUpperCase();
|
||||
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
||||
|
||||
const expose =
|
||||
@ -796,7 +796,9 @@ export class WAStartupService {
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
}, (cleanStore?.CLEANING_INTERVAL ?? 3600) * 1000);
|
||||
}
|
||||
}
|
||||
@ -1514,7 +1516,7 @@ export class WAStartupService {
|
||||
.replace(/\+/g, '')
|
||||
.replace(/\(/g, '')
|
||||
.replace(/\)/g, '')
|
||||
.split(/\:/)[0]
|
||||
.split(':')[0]
|
||||
.split('@')[0];
|
||||
|
||||
if (number.length >= 18) {
|
||||
|
@ -1,43 +1,44 @@
|
||||
import { delay } from '@whiskeysockets/baileys';
|
||||
|
||||
import { Auth, configService } from '../config/env.config';
|
||||
import { Logger } from '../config/logger.config';
|
||||
import { eventEmitter } from '../config/event.config';
|
||||
import { MessageRepository } from './repository/message.repository';
|
||||
import { WAMonitoringService } from './services/monitor.service';
|
||||
import { ChatRepository } from './repository/chat.repository';
|
||||
import { ContactRepository } from './repository/contact.repository';
|
||||
import { MessageUpRepository } from './repository/messageUp.repository';
|
||||
import { Logger } from '../config/logger.config';
|
||||
import { dbserver } from '../db/db.connect';
|
||||
import { RedisCache } from '../db/redis.client';
|
||||
import { ChatController } from './controllers/chat.controller';
|
||||
import { ChatwootController } from './controllers/chatwoot.controller';
|
||||
import { GroupController } from './controllers/group.controller';
|
||||
import { InstanceController } from './controllers/instance.controller';
|
||||
import { SendMessageController } from './controllers/sendMessage.controller';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { GroupController } from './controllers/group.controller';
|
||||
import { SettingsController } from './controllers/settings.controller';
|
||||
import { ViewsController } from './controllers/views.controller';
|
||||
import { WebhookService } from './services/webhook.service';
|
||||
import { WebhookController } from './controllers/webhook.controller';
|
||||
import { ChatwootService } from './services/chatwoot.service';
|
||||
import { ChatwootController } from './controllers/chatwoot.controller';
|
||||
import { RepositoryBroker } from './repository/repository.manager';
|
||||
import {
|
||||
AuthModel,
|
||||
ChatModel,
|
||||
ChatwootModel,
|
||||
ContactModel,
|
||||
MessageModel,
|
||||
MessageUpModel,
|
||||
ChatwootModel,
|
||||
WebhookModel,
|
||||
SettingsModel,
|
||||
WebhookModel,
|
||||
} from './models';
|
||||
import { dbserver } from '../db/db.connect';
|
||||
import { WebhookRepository } from './repository/webhook.repository';
|
||||
import { ChatwootRepository } from './repository/chatwoot.repository';
|
||||
import { AuthRepository } from './repository/auth.repository';
|
||||
import { WAStartupService } from './services/whatsapp.service';
|
||||
import { delay } from '@whiskeysockets/baileys';
|
||||
import { Events } from './types/wa.types';
|
||||
import { RedisCache } from '../db/redis.client';
|
||||
import { ChatRepository } from './repository/chat.repository';
|
||||
import { ChatwootRepository } from './repository/chatwoot.repository';
|
||||
import { ContactRepository } from './repository/contact.repository';
|
||||
import { MessageRepository } from './repository/message.repository';
|
||||
import { MessageUpRepository } from './repository/messageUp.repository';
|
||||
import { RepositoryBroker } from './repository/repository.manager';
|
||||
import { SettingsRepository } from './repository/settings.repository';
|
||||
import { WebhookRepository } from './repository/webhook.repository';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { ChatwootService } from './services/chatwoot.service';
|
||||
import { WAMonitoringService } from './services/monitor.service';
|
||||
import { SettingsService } from './services/settings.service';
|
||||
import { SettingsController } from './controllers/settings.controller';
|
||||
import { WebhookService } from './services/webhook.service';
|
||||
import { WAStartupService } from './services/whatsapp.service';
|
||||
import { Events } from './types/wa.types';
|
||||
|
||||
const logger = new Logger('WA MODULE');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user