mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-20 12:22:21 -06:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee755d5a6c | ||
|
|
65e2ecf88e | ||
|
|
332ec69ee8 | ||
|
|
38409d9336 | ||
|
|
d344e513c4 | ||
|
|
9af7f67930 | ||
|
|
f95d938fb6 | ||
|
|
f74a7e87bd | ||
|
|
d3fce5fc89 | ||
|
|
14f3f3d2ac | ||
|
|
127d5b97c4 | ||
|
|
7ef1c097e8 | ||
|
|
80e3116cd8 | ||
|
|
46bac55bb3 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
|||||||
|
# 1.4.8 (2023-07-27 10:27)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed error return bug
|
||||||
|
|
||||||
|
# 1.4.7 (2023-07-27 08:47)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed error return bug
|
||||||
|
* Fixed problem of getting message when deleting message in chatwoot
|
||||||
|
* Change in error return pattern
|
||||||
|
|
||||||
# 1.4.6 (2023-07-26 17:54)
|
# 1.4.6 (2023-07-26 17:54)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.4.6",
|
"version": "1.4.8",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "./dist/src/main.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"@figuro/chatwoot-sdk": "^1.1.14",
|
"@figuro/chatwoot-sdk": "^1.1.14",
|
||||||
"@hapi/boom": "^10.0.1",
|
"@hapi/boom": "^10.0.1",
|
||||||
"@sentry/node": "^7.59.2",
|
"@sentry/node": "^7.59.2",
|
||||||
"@whiskeysockets/baileys": "^6.4.0",
|
"@whiskeysockets/baileys": "github:EvolutionAPI/Baileys",
|
||||||
"axios": "^1.3.5",
|
"axios": "^1.3.5",
|
||||||
"class-validator": "^0.13.2",
|
"class-validator": "^0.13.2",
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export class UnauthorizedException {
|
|||||||
throw {
|
throw {
|
||||||
status: HttpStatus.UNAUTHORIZED,
|
status: HttpStatus.UNAUTHORIZED,
|
||||||
error: 'Unauthorized',
|
error: 'Unauthorized',
|
||||||
message: objectError.length > 0 ? objectError : undefined,
|
message: objectError.length > 0 ? objectError : 'Unauthorized',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/main.ts
45
src/main.ts
@@ -1,6 +1,5 @@
|
|||||||
import 'express-async-errors';
|
import 'express-async-errors';
|
||||||
|
|
||||||
// import * as Sentry from '@sentry/node';
|
|
||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
||||||
@@ -22,27 +21,6 @@ function bootstrap() {
|
|||||||
const logger = new Logger('SERVER');
|
const logger = new Logger('SERVER');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// Sentry.init({
|
|
||||||
// dsn: '',
|
|
||||||
// integrations: [
|
|
||||||
// // enable HTTP calls tracing
|
|
||||||
// new Sentry.Integrations.Http({ tracing: true }),
|
|
||||||
// // enable Express.js middleware tracing
|
|
||||||
// new Sentry.Integrations.Express({ app }),
|
|
||||||
// // Automatically instrument Node.js libraries and frameworks
|
|
||||||
// ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// // Set tracesSampleRate to 1.0 to capture 100%
|
|
||||||
// // of transactions for performance monitoring.
|
|
||||||
// // We recommend adjusting this value in production
|
|
||||||
// tracesSampleRate: 1.0,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.use(Sentry.Handlers.requestHandler());
|
|
||||||
|
|
||||||
// app.use(Sentry.Handlers.tracingHandler());
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin(requestOrigin, callback) {
|
origin(requestOrigin, callback) {
|
||||||
@@ -67,26 +45,29 @@ function bootstrap() {
|
|||||||
|
|
||||||
app.use('/', router);
|
app.use('/', router);
|
||||||
|
|
||||||
// app.use(Sentry.Handlers.errorHandler());
|
|
||||||
|
|
||||||
// app.use(function onError(err, req, res, next) {
|
|
||||||
// res.statusCode = 500;
|
|
||||||
// res.end(res.sentry + '\n');
|
|
||||||
// });
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
(err: Error, req: Request, res: Response) => {
|
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(err['status'] || 500).json(err);
|
return res.status(err['status'] || 500).json({
|
||||||
|
status: err['status'] || 500,
|
||||||
|
error: err['error'] || 'Internal Server Error',
|
||||||
|
response: {
|
||||||
|
message: err['message'] || 'Internal Server Error',
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
},
|
},
|
||||||
(req: Request, res: Response, next: NextFunction) => {
|
(req: Request, res: Response, next: NextFunction) => {
|
||||||
const { method, url } = req;
|
const { method, url } = req;
|
||||||
|
|
||||||
res.status(HttpStatus.NOT_FOUND).json({
|
res.status(HttpStatus.NOT_FOUND).json({
|
||||||
status: HttpStatus.NOT_FOUND,
|
status: HttpStatus.NOT_FOUND,
|
||||||
message: `Cannot ${method.toUpperCase()} ${url}`,
|
|
||||||
error: 'Not Found',
|
error: 'Not Found',
|
||||||
|
response: {
|
||||||
|
message: [`Cannot ${method.toUpperCase()} ${url}`],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { validate } from 'jsonschema';
|
|||||||
|
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { BadRequestException } from '../../exceptions';
|
import { BadRequestException } from '../../exceptions';
|
||||||
import { GetParticipant, GroupInvite, GroupJid } from '../dto/group.dto';
|
import { GetParticipant, GroupInvite } from '../dto/group.dto';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
|
|
||||||
type DataValidate<T> = {
|
type DataValidate<T> = {
|
||||||
@@ -48,20 +48,21 @@ export abstract class RouterBroker {
|
|||||||
const v = schema ? validate(ref, schema) : { valid: true, errors: [] };
|
const v = schema ? validate(ref, schema) : { valid: true, errors: [] };
|
||||||
|
|
||||||
if (!v.valid) {
|
if (!v.valid) {
|
||||||
const message: any[] = v.errors.map(({ property, stack, schema }) => {
|
const message: any[] = v.errors.map(({ stack, schema }) => {
|
||||||
let message: string;
|
let message: string;
|
||||||
if (schema['description']) {
|
if (schema['description']) {
|
||||||
message = schema['description'];
|
message = schema['description'];
|
||||||
} else {
|
} else {
|
||||||
message = stack.replace('instance.', '');
|
message = stack.replace('instance.', '');
|
||||||
}
|
}
|
||||||
return {
|
return message;
|
||||||
property: property.replace('instance.', ''),
|
// return {
|
||||||
message,
|
// property: property.replace('instance.', ''),
|
||||||
};
|
// message,
|
||||||
|
// };
|
||||||
});
|
});
|
||||||
logger.error([...message]);
|
logger.error(message);
|
||||||
throw new BadRequestException(...message);
|
throw new BadRequestException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await execute(instance, ref);
|
return await execute(instance, ref);
|
||||||
@@ -105,7 +106,7 @@ export abstract class RouterBroker {
|
|||||||
const body = request.body;
|
const body = request.body;
|
||||||
|
|
||||||
let groupJid = body?.groupJid;
|
let groupJid = body?.groupJid;
|
||||||
|
|
||||||
if (!groupJid) {
|
if (!groupJid) {
|
||||||
if (request.query?.groupJid) {
|
if (request.query?.groupJid) {
|
||||||
groupJid = request.query.groupJid;
|
groupJid = request.query.groupJid;
|
||||||
@@ -113,15 +114,15 @@ export abstract class RouterBroker {
|
|||||||
throw new BadRequestException('The group id needs to be informed in the query', 'ex: "groupJid=120362@g.us"');
|
throw new BadRequestException('The group id needs to be informed in the query', 'ex: "groupJid=120362@g.us"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!groupJid.endsWith('@g.us')) {
|
if (!groupJid.endsWith('@g.us')) {
|
||||||
groupJid = groupJid + '@g.us';
|
groupJid = groupJid + '@g.us';
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(body, {
|
Object.assign(body, {
|
||||||
groupJid: groupJid
|
groupJid: groupJid,
|
||||||
});
|
});
|
||||||
|
|
||||||
const ref = new ClassRef();
|
const ref = new ClassRef();
|
||||||
|
|
||||||
Object.assign(ref, body);
|
Object.assign(ref, body);
|
||||||
|
|||||||
@@ -220,8 +220,8 @@ export class InstanceController {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
this.logger.error(error.message[0]);
|
||||||
return { error: true, message: error.toString() };
|
throw new BadRequestException(error.message[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ export class InstanceController {
|
|||||||
this.logger.verbose('logging out instance: ' + instanceName);
|
this.logger.verbose('logging out instance: ' + instanceName);
|
||||||
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
||||||
|
|
||||||
return { error: false, message: 'Instance restarted' };
|
return { status: 'SUCCESS', error: false, response: { message: 'Instance restarted' } };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
@@ -310,7 +310,7 @@ export class InstanceController {
|
|||||||
this.logger.verbose('close connection instance: ' + instanceName);
|
this.logger.verbose('close connection instance: ' + instanceName);
|
||||||
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
this.waMonitor.waInstances[instanceName]?.client?.ws?.close();
|
||||||
|
|
||||||
return { error: false, message: 'Instance logged out' };
|
return { status: 'SUCCESS', error: false, response: { message: 'Instance logged out' } };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new InternalServerErrorException(error.toString());
|
throw new InternalServerErrorException(error.toString());
|
||||||
}
|
}
|
||||||
@@ -329,13 +329,13 @@ export class InstanceController {
|
|||||||
|
|
||||||
await this.logout({ instanceName });
|
await this.logout({ instanceName });
|
||||||
delete this.waMonitor.waInstances[instanceName];
|
delete this.waMonitor.waInstances[instanceName];
|
||||||
return { error: false, message: 'Instance deleted' };
|
return { status: 'SUCCESS', error: false, response: { message: 'Instance deleted' } };
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('deleting instance: ' + instanceName);
|
this.logger.verbose('deleting instance: ' + instanceName);
|
||||||
|
|
||||||
delete this.waMonitor.waInstances[instanceName];
|
delete this.waMonitor.waInstances[instanceName];
|
||||||
this.eventEmitter.emit('remove.instance', instanceName, 'inner');
|
this.eventEmitter.emit('remove.instance', instanceName, 'inner');
|
||||||
return { error: false, message: 'Instance deleted' };
|
return { status: 'SUCCESS', error: false, response: { message: 'Instance deleted' } };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new BadRequestException(error.toString());
|
throw new BadRequestException(error.toString());
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export class SettingsController {
|
|||||||
constructor(private readonly settingsService: SettingsService) {}
|
constructor(private readonly settingsService: SettingsService) {}
|
||||||
|
|
||||||
public async createSettings(instance: InstanceDto, data: SettingsDto) {
|
public async createSettings(instance: InstanceDto, data: SettingsDto) {
|
||||||
|
|
||||||
logger.verbose('requested createSettings from ' + instance.instanceName + ' instance');
|
logger.verbose('requested createSettings from ' + instance.instanceName + ' instance');
|
||||||
|
|
||||||
return this.settingsService.create(instance, data);
|
return this.settingsService.create(instance, data);
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ export class RepositoryBroker {
|
|||||||
this.logger.verbose('creating temp dir: ' + tempDir);
|
this.logger.verbose('creating temp dir: ' + tempDir);
|
||||||
fs.mkdirSync(tempDir, { recursive: true });
|
fs.mkdirSync(tempDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,7 +161,9 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
if (db.ENABLED) {
|
if (db.ENABLED) {
|
||||||
try {
|
try {
|
||||||
await dbserver.dropDatabase();
|
await dbserver.dropDatabase();
|
||||||
return res.status(HttpStatus.CREATED).json({ error: false, message: 'Database deleted' });
|
return res
|
||||||
|
.status(HttpStatus.CREATED)
|
||||||
|
.json({ status: 'SUCCESS', error: false, response: { message: 'database deleted' } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({ error: true, message: error.message });
|
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({ error: true, message: error.message });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -940,7 +940,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('check if is bot');
|
this.logger.verbose('check if is bot');
|
||||||
if (!body?.conversation || body.private) return { message: 'bot' };
|
if (!body?.conversation || body.private || body.event === 'message_updated') return { message: 'bot' };
|
||||||
|
|
||||||
this.logger.verbose('check if is group');
|
this.logger.verbose('check if is group');
|
||||||
const chatId =
|
const chatId =
|
||||||
|
|||||||
Reference in New Issue
Block a user