mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
feat: added option to generate qrcode as soon as the instance is created
This commit is contained in:
parent
849d570bcb
commit
c63da9cd6e
@ -12,6 +12,7 @@
|
||||
* Route to accept invite code
|
||||
* Added configuration of events by webhook of instances
|
||||
* Now the api key can be exposed in fetch instances if the EXPOSE_IN_FETCH_INSTANCES variable is set to true
|
||||
* Added option to generate qrcode as soon as the instance is created
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -11,7 +11,7 @@ services:
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- ./docker-data/instances:/evolution/instances
|
||||
- evolution_instances:/evolution/instances
|
||||
depends_on:
|
||||
- mongodb
|
||||
- redis
|
||||
@ -77,7 +77,7 @@ services:
|
||||
# OBS: This key must be inserted in the request header to create an instance.
|
||||
- AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
|
||||
# Expose the api key on return from fetch instances
|
||||
- AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false
|
||||
- AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
||||
# Set the secret key to encrypt and decrypt your token and its expiration time.
|
||||
- AUTHENTICATION_JWT_EXPIRIN_IN=0 # seconds - 3600s === 1h | zero (0) - never expires
|
||||
# Set the instance name and webhook url to create an instance in init the application
|
||||
@ -98,8 +98,8 @@ services:
|
||||
image: mongo
|
||||
restart: always
|
||||
volumes:
|
||||
- ./docker-data/mongodb/data:/data/db
|
||||
- ./docker-data/mongodb/configdb:/data/configdb
|
||||
- evolution_mongodb_data:/data/db
|
||||
- evolution_mongodb_configdb:/data/configdb
|
||||
ports:
|
||||
- 27017:27017
|
||||
environment:
|
||||
@ -112,10 +112,25 @@ services:
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
command: >
|
||||
redis-server
|
||||
--port 6379
|
||||
--appendonly yes
|
||||
--save 900 1
|
||||
--save 300 10
|
||||
--save 60 10000
|
||||
--appendfsync everysec
|
||||
volumes:
|
||||
- ./docker-data/redis:/data
|
||||
- evolution_redis:/data
|
||||
container_name: redis
|
||||
ports:
|
||||
- 6379:6379
|
||||
networks:
|
||||
- evolution-net
|
||||
- evolution-net
|
||||
|
||||
|
||||
volumes:
|
||||
evolution_instances:
|
||||
evolution_mongodb_data:
|
||||
evolution_mongodb_configdb:
|
||||
evolution_redis:
|
@ -55,6 +55,7 @@ export const instanceNameSchema: JSONSchema7 = {
|
||||
],
|
||||
},
|
||||
},
|
||||
qrcode: { type: 'boolean', enum: [true, false] },
|
||||
},
|
||||
...isNotEmpty('instanceName'),
|
||||
};
|
||||
|
@ -9,6 +9,7 @@ import { WAMonitoringService } from '../services/monitor.service';
|
||||
import { WAStartupService } from '../services/whatsapp.service';
|
||||
import { WebhookService } from '../services/webhook.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { wa } from '../types/wa.types';
|
||||
|
||||
export class InstanceController {
|
||||
constructor(
|
||||
@ -22,7 +23,7 @@ export class InstanceController {
|
||||
|
||||
private readonly logger = new Logger(InstanceController.name);
|
||||
|
||||
public async createInstance({ instanceName, webhook, events }: InstanceDto) {
|
||||
public async createInstance({ instanceName, webhook, events, qrcode }: InstanceDto) {
|
||||
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
||||
|
||||
if (mode === 'container') {
|
||||
@ -46,9 +47,13 @@ export class InstanceController {
|
||||
instanceName: instance.instanceName,
|
||||
});
|
||||
|
||||
let getEvents: string[];
|
||||
|
||||
if (webhook) {
|
||||
try {
|
||||
this.webhookService.create(instance, { enabled: true, url: webhook, events });
|
||||
|
||||
getEvents = (await this.webhookService.find(instance)).events;
|
||||
} catch (error) {
|
||||
this.logger.log(error);
|
||||
}
|
||||
@ -61,6 +66,7 @@ export class InstanceController {
|
||||
},
|
||||
hash,
|
||||
webhook,
|
||||
events: getEvents,
|
||||
};
|
||||
} else {
|
||||
const instance = new WAStartupService(
|
||||
@ -76,14 +82,26 @@ export class InstanceController {
|
||||
instanceName: instance.instanceName,
|
||||
});
|
||||
|
||||
let getEvents: string[];
|
||||
|
||||
if (webhook) {
|
||||
try {
|
||||
this.webhookService.create(instance, { enabled: true, url: webhook });
|
||||
this.webhookService.create(instance, { enabled: true, url: webhook, events });
|
||||
|
||||
getEvents = (await this.webhookService.find(instance)).events;
|
||||
} catch (error) {
|
||||
this.logger.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
let getQrcode: wa.QrCode;
|
||||
|
||||
if (qrcode) {
|
||||
await instance.connectToWhatsapp();
|
||||
await delay(2000);
|
||||
getQrcode = instance.qrCode;
|
||||
}
|
||||
|
||||
return {
|
||||
instance: {
|
||||
instanceName: instance.instanceName,
|
||||
@ -91,6 +109,8 @@ export class InstanceController {
|
||||
},
|
||||
hash,
|
||||
webhook,
|
||||
events: getEvents,
|
||||
qrcode: getQrcode,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,5 @@ export class InstanceDto {
|
||||
instanceName: string;
|
||||
webhook?: string;
|
||||
events?: string[];
|
||||
qrcode?: boolean;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user