mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
feat: New instance manager in /manager route
This commit is contained in:
parent
cffcca9722
commit
66d06afaf7
@ -1,5 +1,9 @@
|
|||||||
# 1.5.0 (homolog)
|
# 1.5.0 (homolog)
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
|
||||||
|
* New instance manager in /manager route
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* Solved problem when disconnecting from the instance the instance was deleted
|
* Solved problem when disconnecting from the instance the instance was deleted
|
||||||
|
@ -1,24 +1,15 @@
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
|
|
||||||
import { Auth, ConfigService } from '../../config/env.config';
|
import { ConfigService } from '../../config/env.config';
|
||||||
import { BadRequestException } from '../../exceptions';
|
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
|
||||||
import { HttpStatus } from '../routers/index.router';
|
import { HttpStatus } from '../routers/index.router';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
|
|
||||||
export class ViewsController {
|
export class ViewsController {
|
||||||
constructor(private readonly waMonit: WAMonitoringService, private readonly configService: ConfigService) {}
|
constructor(private readonly waMonit: WAMonitoringService, private readonly configService: ConfigService) {}
|
||||||
|
|
||||||
public async qrcode(request: Request, response: Response) {
|
public async manager(request: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
const param = request.params as unknown as InstanceDto;
|
return response.status(HttpStatus.OK).render('manager');
|
||||||
const instance = this.waMonit.waInstances[param.instanceName];
|
|
||||||
if (instance.connectionStatus.state === 'open') {
|
|
||||||
throw new BadRequestException('The instance is already connected');
|
|
||||||
}
|
|
||||||
const type = this.configService.get<Auth>('AUTHENTICATION').TYPE;
|
|
||||||
|
|
||||||
return response.status(HttpStatus.OK).render('qrcode', { type, ...param });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('ERROR: ', error);
|
console.log('ERROR: ', error);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ router
|
|||||||
version: packageJson.version,
|
version: packageJson.version,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.use('/instance', new InstanceRouter(configService, ...guards).router, new ViewsRouter(instanceExistsGuard).router)
|
.use('/instance', new InstanceRouter(configService, ...guards).router)
|
||||||
|
.use('/manager', new ViewsRouter().router)
|
||||||
.use('/message', new MessageRouter(...guards).router)
|
.use('/message', new MessageRouter(...guards).router)
|
||||||
.use('/chat', new ChatRouter(...guards).router)
|
.use('/chat', new ChatRouter(...guards).router)
|
||||||
.use('/group', new GroupRouter(...guards).router)
|
.use('/group', new GroupRouter(...guards).router)
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import { viewsController } from '../whatsapp.module';
|
import { viewsController } from '../whatsapp.module';
|
||||||
|
|
||||||
export class ViewsRouter extends RouterBroker {
|
export class ViewsRouter extends RouterBroker {
|
||||||
constructor(...guards: RequestHandler[]) {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.router.get(this.routerPath('qrcode'), ...guards, (req, res) => {
|
this.router.get('/', (req, res) => {
|
||||||
return viewsController.qrcode(req, res);
|
return viewsController.manager(req, res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
views/manager.hbs
Normal file
30
views/manager.hbs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pt-br">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||||
|
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" 'unsafe-inline' crossorigin="anonymous">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
|
||||||
|
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<link rel="shortcut icon" href="/images/atendai-logo.png" type="image/x-icon">
|
||||||
|
<style>
|
||||||
|
code {
|
||||||
|
padding: 10px;
|
||||||
|
background-color: whitesmoke;
|
||||||
|
color: rgb(104, 104, 104);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<title>Instance Manager</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<iframe src="https://app.smith.dgcode.com.br/app/evolutionapi/page1-64c53a7a7ea84639bf879f23?embed=true" frameborder="0" style="width: 100%; height: 100vh;"></iframe>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -1,82 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="pt-br">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
|
||||||
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" 'unsafe-inline' crossorigin="anonymous">
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
|
|
||||||
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
<link rel="shortcut icon" href="/images/atendai-logo.png" type="image/x-icon">
|
|
||||||
<style>
|
|
||||||
code {
|
|
||||||
padding: 10px;
|
|
||||||
background-color: whitesmoke;
|
|
||||||
color: rgb(104, 104, 104);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<title>Generate QRCode</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div id="root" class="container mt-5 mb-5 w-50">
|
|
||||||
|
|
||||||
<div id="display-qrcode">
|
|
||||||
<h2 class="mb-3 text-secondary">Connect to whatsapp</h2>
|
|
||||||
<div class="input-group mb-3">
|
|
||||||
<input id="input-auth" type="text" class="form-control" aria-describedby="btn-qr-g" value="" placeholder="{{type}}">
|
|
||||||
<input id="input-session" type="text" class="form-control" aria-describedby="btn-qr-g" disabled
|
|
||||||
value="{{instanceName}}">
|
|
||||||
<button id="gen-qrcode" class="btn btn-info text-light" type="submit">Generate qrcode</button>
|
|
||||||
</div>
|
|
||||||
<div id="qrcode-img"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
|
|
||||||
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
|
||||||
<script type="module">
|
|
||||||
|
|
||||||
const log = (...data) => console.log(data);
|
|
||||||
|
|
||||||
$('#gen-qrcode').click(() => {
|
|
||||||
|
|
||||||
const keyAuth = '{{type}}' === 'jwt'? 'authorization': 'apikey';
|
|
||||||
const valueAuth = '{{type}}' === 'jwt'? `Bearer ${$('#input-auth').val()}`: $('#input-auth').val()
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: `/instance/connect/{{instanceName}}`,
|
|
||||||
headers: { [keyAuth]: valueAuth },
|
|
||||||
type: 'GET',
|
|
||||||
success: (qrcode, status) => {
|
|
||||||
$(`#update-qrcode`).remove();
|
|
||||||
$('#qrcode-img')
|
|
||||||
.append(
|
|
||||||
`<div id="update-qrcode" class="card mb-2">
|
|
||||||
<h5 class="card-title text-center text-secondary mt-3">{{name}}</h5>
|
|
||||||
<div class="card-body container d-flex justify-content-center">
|
|
||||||
<img class="img-thumbnail mt-2 w-50" alt="qrcode.png"
|
|
||||||
src="${qrcode.base64}">
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<code class="text-card d-block">${JSON.stringify({ code: qrcode.code })}</code>
|
|
||||||
</div>
|
|
||||||
</div>`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
error: (error) => console.log(error),
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user