From ff829871446fcfd0f54e3bfc49ec9ef5a8bcd0a3 Mon Sep 17 00:00:00 2001 From: Gabriel Pastori <58153955+gabrielpastori1@users.noreply.github.com> Date: Fri, 15 Dec 2023 12:39:07 -0300 Subject: [PATCH] simple add keep open --- Docker/.env.example | 1 + src/config/env.config.ts | 3 ++- src/dev-env.yml | 1 + src/whatsapp/services/typebot.service.ts | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Docker/.env.example b/Docker/.env.example index fefd9456..2813117e 100644 --- a/Docker/.env.example +++ b/Docker/.env.example @@ -107,6 +107,7 @@ QRCODE_COLOR=#198754 # old | latest TYPEBOT_API_VERSION=latest +TYPEBOT_KEEP_OPEN=false # Defines an authentication type for the api # We recommend using the apikey because it will allow you to use a custom token, diff --git a/src/config/env.config.ts b/src/config/env.config.ts index e35e2dd8..45b8a5e1 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -130,7 +130,7 @@ export type SslConf = { PRIVKEY: string; FULLCHAIN: string }; export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook }; export type ConfigSessionPhone = { CLIENT: string; NAME: string }; export type QrCode = { LIMIT: number; COLOR: string }; -export type Typebot = { API_VERSION: string }; +export type Typebot = { API_VERSION: string; KEEP_OPEN: boolean }; export type Production = boolean; export interface Env { @@ -308,6 +308,7 @@ export class ConfigService { }, TYPEBOT: { API_VERSION: process.env?.TYPEBOT_API_VERSION || 'old', + KEEP_OPEN: process.env.TYPEBOT_KEEP_OPEN === 'true', }, AUTHENTICATION: { TYPE: process.env.AUTHENTICATION_TYPE as 'apikey', diff --git a/src/dev-env.yml b/src/dev-env.yml index 117226a2..01a5927f 100644 --- a/src/dev-env.yml +++ b/src/dev-env.yml @@ -148,6 +148,7 @@ QRCODE: TYPEBOT: API_VERSION: 'old' # old | latest + KEEP_OPEN: false # Defines an authentication type for the api # We recommend using the apikey because it will allow you to use a custom token, diff --git a/src/whatsapp/services/typebot.service.ts b/src/whatsapp/services/typebot.service.ts index 6959dfc7..dbba16ed 100644 --- a/src/whatsapp/services/typebot.service.ts +++ b/src/whatsapp/services/typebot.service.ts @@ -16,6 +16,9 @@ export class TypebotService { private readonly eventEmitter: EventEmitter2, ) { this.eventEmitter.on('typebot:end', async (data) => { + const keep_open = this.configService.get('TYPEBOT').KEEP_OPEN; + if (keep_open) return; + await this.clearSessions(data.instance, data.remoteJid); }); }