Skip to content

Commit c63da9c

Browse files
committed
feat: added option to generate qrcode as soon as the instance is created
1 parent 849d570 commit c63da9c

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Route to accept invite code
1313
* Added configuration of events by webhook of instances
1414
* Now the api key can be exposed in fetch instances if the EXPOSE_IN_FETCH_INSTANCES variable is set to true
15+
* Added option to generate qrcode as soon as the instance is created
1516

1617
### Fixed
1718

docker-compose.yaml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
ports:
1212
- 8080:8080
1313
volumes:
14-
- ./docker-data/instances:/evolution/instances
14+
- evolution_instances:/evolution/instances
1515
depends_on:
1616
- mongodb
1717
- redis
@@ -77,7 +77,7 @@ services:
7777
# OBS: This key must be inserted in the request header to create an instance.
7878
- AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
7979
# Expose the api key on return from fetch instances
80-
- AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false
80+
- AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
8181
# Set the secret key to encrypt and decrypt your token and its expiration time.
8282
- AUTHENTICATION_JWT_EXPIRIN_IN=0 # seconds - 3600s === 1h | zero (0) - never expires
8383
# Set the instance name and webhook url to create an instance in init the application
@@ -98,8 +98,8 @@ services:
9898
image: mongo
9999
restart: always
100100
volumes:
101-
- ./docker-data/mongodb/data:/data/db
102-
- ./docker-data/mongodb/configdb:/data/configdb
101+
- evolution_mongodb_data:/data/db
102+
- evolution_mongodb_configdb:/data/configdb
103103
ports:
104104
- 27017:27017
105105
environment:
@@ -112,10 +112,25 @@ services:
112112

113113
redis:
114114
image: redis:latest
115+
command: >
116+
redis-server
117+
--port 6379
118+
--appendonly yes
119+
--save 900 1
120+
--save 300 10
121+
--save 60 10000
122+
--appendfsync everysec
115123
volumes:
116-
- ./docker-data/redis:/data
124+
- evolution_redis:/data
117125
container_name: redis
118126
ports:
119127
- 6379:6379
120128
networks:
121-
- evolution-net
129+
- evolution-net
130+
131+
132+
volumes:
133+
evolution_instances:
134+
evolution_mongodb_data:
135+
evolution_mongodb_configdb:
136+
evolution_redis:

src/validate/validate.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const instanceNameSchema: JSONSchema7 = {
5555
],
5656
},
5757
},
58+
qrcode: { type: 'boolean', enum: [true, false] },
5859
},
5960
...isNotEmpty('instanceName'),
6061
};

src/whatsapp/controllers/instance.controller.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { WAMonitoringService } from '../services/monitor.service';
99
import { WAStartupService } from '../services/whatsapp.service';
1010
import { WebhookService } from '../services/webhook.service';
1111
import { Logger } from '../../config/logger.config';
12+
import { wa } from '../types/wa.types';
1213

1314
export class InstanceController {
1415
constructor(
@@ -22,7 +23,7 @@ export class InstanceController {
2223

2324
private readonly logger = new Logger(InstanceController.name);
2425

25-
public async createInstance({ instanceName, webhook, events }: InstanceDto) {
26+
public async createInstance({ instanceName, webhook, events, qrcode }: InstanceDto) {
2627
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
2728

2829
if (mode === 'container') {
@@ -46,9 +47,13 @@ export class InstanceController {
4647
instanceName: instance.instanceName,
4748
});
4849

50+
let getEvents: string[];
51+
4952
if (webhook) {
5053
try {
5154
this.webhookService.create(instance, { enabled: true, url: webhook, events });
55+
56+
getEvents = (await this.webhookService.find(instance)).events;
5257
} catch (error) {
5358
this.logger.log(error);
5459
}
@@ -61,6 +66,7 @@ export class InstanceController {
6166
},
6267
hash,
6368
webhook,
69+
events: getEvents,
6470
};
6571
} else {
6672
const instance = new WAStartupService(
@@ -76,21 +82,35 @@ export class InstanceController {
7682
instanceName: instance.instanceName,
7783
});
7884

85+
let getEvents: string[];
86+
7987
if (webhook) {
8088
try {
81-
this.webhookService.create(instance, { enabled: true, url: webhook });
89+
this.webhookService.create(instance, { enabled: true, url: webhook, events });
90+
91+
getEvents = (await this.webhookService.find(instance)).events;
8292
} catch (error) {
8393
this.logger.log(error);
8494
}
8595
}
8696

97+
let getQrcode: wa.QrCode;
98+
99+
if (qrcode) {
100+
await instance.connectToWhatsapp();
101+
await delay(2000);
102+
getQrcode = instance.qrCode;
103+
}
104+
87105
return {
88106
instance: {
89107
instanceName: instance.instanceName,
90108
status: 'created',
91109
},
92110
hash,
93111
webhook,
112+
events: getEvents,
113+
qrcode: getQrcode,
94114
};
95115
}
96116
}

src/whatsapp/dto/instance.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export class InstanceDto {
22
instanceName: string;
33
webhook?: string;
44
events?: string[];
5+
qrcode?: boolean;
56
}

0 commit comments

Comments
 (0)