Skip to content

Commit

Permalink
Merge branch 'release/1.4.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Jul 27, 2023
2 parents 2cadafd + 9af7f67 commit d344e51
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 97 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 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)

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evolution-api",
"version": "1.4.6",
"version": "1.4.7",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js",
"scripts": {
Expand Down Expand Up @@ -46,7 +46,7 @@
"@figuro/chatwoot-sdk": "^1.1.14",
"@hapi/boom": "^10.0.1",
"@sentry/node": "^7.59.2",
"@whiskeysockets/baileys": "^6.4.0",
"@whiskeysockets/baileys": "github:EvolutionAPI/Baileys",
"axios": "^1.3.5",
"class-validator": "^0.13.2",
"compression": "^1.7.4",
Expand Down
154 changes: 68 additions & 86 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'express-async-errors';

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

function initWA() {
waMonitor.loadInstance();
waMonitor.loadInstance();
}

function bootstrap() {
const logger = new Logger('SERVER');
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(
cors({
origin(requestOrigin, callback) {
const { ORIGIN } = configService.get<Cors>('CORS');
!requestOrigin ? (requestOrigin = '*') : undefined;
if (ORIGIN.indexOf(requestOrigin) !== -1) {
return callback(null, true);
}
return callback(new Error('Not allowed by CORS'));
},
methods: [...configService.get<Cors>('CORS').METHODS],
credentials: configService.get<Cors>('CORS').CREDENTIALS,
}),
urlencoded({ extended: true, limit: '136mb' }),
json({ limit: '136mb' }),
compression(),
);

app.set('view engine', 'hbs');
app.set('views', join(ROOT_DIR, 'views'));
app.use(express.static(join(ROOT_DIR, 'public')));

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(
(err: Error, req: Request, res: Response) => {
if (err) {
return res.status(err['status'] || 500).json(err);
}
},
(req: Request, res: Response, next: NextFunction) => {
const { method, url } = req;

res.status(HttpStatus.NOT_FOUND).json({
status: HttpStatus.NOT_FOUND,
message: `Cannot ${method.toUpperCase()} ${url}`,
error: 'Not Found',
});

next();
},
);

const httpServer = configService.get<HttpServer>('SERVER');

ServerUP.app = app;
const server = ServerUP[httpServer.TYPE];

server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT));

initWA();

onUnexpectedError();
const logger = new Logger('SERVER');
const app = express();

app.use(
cors({
origin(requestOrigin, callback) {
const { ORIGIN } = configService.get<Cors>('CORS');
!requestOrigin ? (requestOrigin = '*') : undefined;
if (ORIGIN.indexOf(requestOrigin) !== -1) {
return callback(null, true);
}
return callback(new Error('Not allowed by CORS'));
},
methods: [...configService.get<Cors>('CORS').METHODS],
credentials: configService.get<Cors>('CORS').CREDENTIALS,
}),
urlencoded({ extended: true, limit: '136mb' }),
json({ limit: '136mb' }),
compression(),
);

app.set('view engine', 'hbs');
app.set('views', join(ROOT_DIR, 'views'));
app.use(express.static(join(ROOT_DIR, 'public')));

app.use('/', router);

app.use(
(err: Error, req: Request, res: Response, next: NextFunction) => {
if (err) {
return res.status(err['status'] || 500).json({
status: 'ERROR',
error: err['error'] || 'Internal Server Error',
response: {
message: err['message'] || 'Internal Server Error',
},
}
);
}

next();
},
(req: Request, res: Response, next: NextFunction) => {
const { method, url } = req;

res.status(HttpStatus.NOT_FOUND).json({
status: HttpStatus.NOT_FOUND,
error: 'Not Found',
response: {
message: `Cannot ${method.toUpperCase()} ${url}`,
},
});

next();
},
);

const httpServer = configService.get<HttpServer>('SERVER');

ServerUP.app = app;
const server = ServerUP[httpServer.TYPE];

server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT));

initWA();

onUnexpectedError();
}

bootstrap();
12 changes: 6 additions & 6 deletions src/whatsapp/abstract/abstract.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { validate } from 'jsonschema';

import { Logger } from '../../config/logger.config';
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';

type DataValidate<T> = {
Expand Down Expand Up @@ -105,23 +105,23 @@ export abstract class RouterBroker {
const body = request.body;

let groupJid = body?.groupJid;

if (!groupJid) {
if (request.query?.groupJid) {
groupJid = request.query.groupJid;
} else {
throw new BadRequestException('The group id needs to be informed in the query', 'ex: "[email protected]"');
}
}

if (!groupJid.endsWith('@g.us')) {
groupJid = groupJid + '@g.us';
}

Object.assign(body, {
groupJid: groupJid
groupJid: groupJid,
});

const ref = new ClassRef();

Object.assign(ref, body);
Expand Down
1 change: 0 additions & 1 deletion src/whatsapp/controllers/settings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class SettingsController {
constructor(private readonly settingsService: SettingsService) {}

public async createSettings(instance: InstanceDto, data: SettingsDto) {

logger.verbose('requested createSettings from ' + instance.instanceName + ' instance');

return this.settingsService.create(instance, data);
Expand Down
1 change: 0 additions & 1 deletion src/whatsapp/repository/repository.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export class RepositoryBroker {
this.logger.verbose('creating temp dir: ' + tempDir);
fs.mkdirSync(tempDir, { recursive: true });
}

} catch (error) {
this.logger.error(error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/whatsapp/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ export class ChatwootService {
}

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');
const chatId =
Expand Down

0 comments on commit d344e51

Please sign in to comment.