Skip to content

Commit d344e51

Browse files
committed
Merge branch 'release/1.4.7'
2 parents 2cadafd + 9af7f67 commit d344e51

File tree

8 files changed

+85
-97
lines changed

8 files changed

+85
-97
lines changed

.DS_Store

0 Bytes
Binary file not shown.

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 1.4.7 (2023-07-27 08:47)
2+
3+
### Fixed
4+
5+
* Fixed error return bug
6+
* Fixed problem of getting message when deleting message in chatwoot
7+
* Change in error return pattern
8+
19
# 1.4.6 (2023-07-26 17:54)
210

311
### Fixed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evolution-api",
3-
"version": "1.4.6",
3+
"version": "1.4.7",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {
@@ -46,7 +46,7 @@
4646
"@figuro/chatwoot-sdk": "^1.1.14",
4747
"@hapi/boom": "^10.0.1",
4848
"@sentry/node": "^7.59.2",
49-
"@whiskeysockets/baileys": "^6.4.0",
49+
"@whiskeysockets/baileys": "github:EvolutionAPI/Baileys",
5050
"axios": "^1.3.5",
5151
"class-validator": "^0.13.2",
5252
"compression": "^1.7.4",

src/main.ts

Lines changed: 68 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'express-async-errors';
22

3-
// import * as Sentry from '@sentry/node';
43
import compression from 'compression';
54
import cors from 'cors';
65
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
@@ -15,94 +14,77 @@ import { HttpStatus, router } from './whatsapp/routers/index.router';
1514
import { waMonitor } from './whatsapp/whatsapp.module';
1615

1716
function initWA() {
18-
waMonitor.loadInstance();
17+
waMonitor.loadInstance();
1918
}
2019

2120
function bootstrap() {
22-
const logger = new Logger('SERVER');
23-
const app = express();
24-
25-
// Sentry.init({
26-
// dsn: '',
27-
// integrations: [
28-
// // enable HTTP calls tracing
29-
// new Sentry.Integrations.Http({ tracing: true }),
30-
// // enable Express.js middleware tracing
31-
// new Sentry.Integrations.Express({ app }),
32-
// // Automatically instrument Node.js libraries and frameworks
33-
// ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
34-
// ],
35-
36-
// // Set tracesSampleRate to 1.0 to capture 100%
37-
// // of transactions for performance monitoring.
38-
// // We recommend adjusting this value in production
39-
// tracesSampleRate: 1.0,
40-
// });
41-
42-
// app.use(Sentry.Handlers.requestHandler());
43-
44-
// app.use(Sentry.Handlers.tracingHandler());
45-
46-
app.use(
47-
cors({
48-
origin(requestOrigin, callback) {
49-
const { ORIGIN } = configService.get<Cors>('CORS');
50-
!requestOrigin ? (requestOrigin = '*') : undefined;
51-
if (ORIGIN.indexOf(requestOrigin) !== -1) {
52-
return callback(null, true);
53-
}
54-
return callback(new Error('Not allowed by CORS'));
55-
},
56-
methods: [...configService.get<Cors>('CORS').METHODS],
57-
credentials: configService.get<Cors>('CORS').CREDENTIALS,
58-
}),
59-
urlencoded({ extended: true, limit: '136mb' }),
60-
json({ limit: '136mb' }),
61-
compression(),
62-
);
63-
64-
app.set('view engine', 'hbs');
65-
app.set('views', join(ROOT_DIR, 'views'));
66-
app.use(express.static(join(ROOT_DIR, 'public')));
67-
68-
app.use('/', router);
69-
70-
// app.use(Sentry.Handlers.errorHandler());
71-
72-
// app.use(function onError(err, req, res, next) {
73-
// res.statusCode = 500;
74-
// res.end(res.sentry + '\n');
75-
// });
76-
77-
app.use(
78-
(err: Error, req: Request, res: Response) => {
79-
if (err) {
80-
return res.status(err['status'] || 500).json(err);
81-
}
82-
},
83-
(req: Request, res: Response, next: NextFunction) => {
84-
const { method, url } = req;
85-
86-
res.status(HttpStatus.NOT_FOUND).json({
87-
status: HttpStatus.NOT_FOUND,
88-
message: `Cannot ${method.toUpperCase()} ${url}`,
89-
error: 'Not Found',
90-
});
91-
92-
next();
93-
},
94-
);
95-
96-
const httpServer = configService.get<HttpServer>('SERVER');
97-
98-
ServerUP.app = app;
99-
const server = ServerUP[httpServer.TYPE];
100-
101-
server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT));
102-
103-
initWA();
104-
105-
onUnexpectedError();
21+
const logger = new Logger('SERVER');
22+
const app = express();
23+
24+
app.use(
25+
cors({
26+
origin(requestOrigin, callback) {
27+
const { ORIGIN } = configService.get<Cors>('CORS');
28+
!requestOrigin ? (requestOrigin = '*') : undefined;
29+
if (ORIGIN.indexOf(requestOrigin) !== -1) {
30+
return callback(null, true);
31+
}
32+
return callback(new Error('Not allowed by CORS'));
33+
},
34+
methods: [...configService.get<Cors>('CORS').METHODS],
35+
credentials: configService.get<Cors>('CORS').CREDENTIALS,
36+
}),
37+
urlencoded({ extended: true, limit: '136mb' }),
38+
json({ limit: '136mb' }),
39+
compression(),
40+
);
41+
42+
app.set('view engine', 'hbs');
43+
app.set('views', join(ROOT_DIR, 'views'));
44+
app.use(express.static(join(ROOT_DIR, 'public')));
45+
46+
app.use('/', router);
47+
48+
app.use(
49+
(err: Error, req: Request, res: Response, next: NextFunction) => {
50+
if (err) {
51+
return res.status(err['status'] || 500).json({
52+
status: 'ERROR',
53+
error: err['error'] || 'Internal Server Error',
54+
response: {
55+
message: err['message'] || 'Internal Server Error',
56+
},
57+
}
58+
);
59+
}
60+
61+
next();
62+
},
63+
(req: Request, res: Response, next: NextFunction) => {
64+
const { method, url } = req;
65+
66+
res.status(HttpStatus.NOT_FOUND).json({
67+
status: HttpStatus.NOT_FOUND,
68+
error: 'Not Found',
69+
response: {
70+
message: `Cannot ${method.toUpperCase()} ${url}`,
71+
},
72+
});
73+
74+
next();
75+
},
76+
);
77+
78+
const httpServer = configService.get<HttpServer>('SERVER');
79+
80+
ServerUP.app = app;
81+
const server = ServerUP[httpServer.TYPE];
82+
83+
server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT));
84+
85+
initWA();
86+
87+
onUnexpectedError();
10688
}
10789

10890
bootstrap();

src/whatsapp/abstract/abstract.router.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { validate } from 'jsonschema';
66

77
import { Logger } from '../../config/logger.config';
88
import { BadRequestException } from '../../exceptions';
9-
import { GetParticipant, GroupInvite, GroupJid } from '../dto/group.dto';
9+
import { GetParticipant, GroupInvite } from '../dto/group.dto';
1010
import { InstanceDto } from '../dto/instance.dto';
1111

1212
type DataValidate<T> = {
@@ -105,23 +105,23 @@ export abstract class RouterBroker {
105105
const body = request.body;
106106

107107
let groupJid = body?.groupJid;
108-
108+
109109
if (!groupJid) {
110110
if (request.query?.groupJid) {
111111
groupJid = request.query.groupJid;
112112
} else {
113113
throw new BadRequestException('The group id needs to be informed in the query', 'ex: "[email protected]"');
114114
}
115115
}
116-
116+
117117
if (!groupJid.endsWith('@g.us')) {
118118
groupJid = groupJid + '@g.us';
119119
}
120-
120+
121121
Object.assign(body, {
122-
groupJid: groupJid
122+
groupJid: groupJid,
123123
});
124-
124+
125125
const ref = new ClassRef();
126126

127127
Object.assign(ref, body);

src/whatsapp/controllers/settings.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class SettingsController {
1212
constructor(private readonly settingsService: SettingsService) {}
1313

1414
public async createSettings(instance: InstanceDto, data: SettingsDto) {
15-
1615
logger.verbose('requested createSettings from ' + instance.instanceName + ' instance');
1716

1817
return this.settingsService.create(instance, data);

src/whatsapp/repository/repository.manager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export class RepositoryBroker {
109109
this.logger.verbose('creating temp dir: ' + tempDir);
110110
fs.mkdirSync(tempDir, { recursive: true });
111111
}
112-
113112
} catch (error) {
114113
this.logger.error(error);
115114
}

src/whatsapp/services/chatwoot.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ export class ChatwootService {
940940
}
941941

942942
this.logger.verbose('check if is bot');
943-
if (!body?.conversation || body.private) return { message: 'bot' };
943+
if (!body?.conversation || body.private || body.event === 'message_updated') return { message: 'bot' };
944944

945945
this.logger.verbose('check if is group');
946946
const chatId =

0 commit comments

Comments
 (0)