refactor: integration folders and fix manager bugs

This commit is contained in:
Davidson Gomes 2024-08-23 13:46:51 -03:00
parent beafc62403
commit 6a62ae85fc
17 changed files with 122 additions and 122 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<link rel="icon" type="image/png" href="/assets/images/evolution-logo.png" /> <link rel="icon" type="image/png" href="/assets/images/evolution-logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Evolution Manager</title> <title>Evolution Manager</title>
<script type="module" crossorigin src="/assets/index-C6xnilvd.js"></script> <script type="module" crossorigin src="/assets/index-TzDLYu1M.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BJ9JMAl_.css"> <link rel="stylesheet" crossorigin href="/assets/index-BJ9JMAl_.css">
</head> </head>
<body> <body>

View File

@ -17,7 +17,7 @@ export class ProxyController {
throw new NotFoundException(`The "${instance.instanceName}" instance does not exist`); throw new NotFoundException(`The "${instance.instanceName}" instance does not exist`);
} }
if (!data.enabled) { if (!data?.enabled) {
data.host = ''; data.host = '';
data.port = ''; data.port = '';
data.protocol = ''; data.protocol = '';

View File

@ -141,7 +141,7 @@ export class EvolutionStartupService extends ChannelStartupService {
pushName: messageRaw.pushName, pushName: messageRaw.pushName,
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
const chatwootSentMessage = await this.chatwootService.eventWhatsapp( const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
Events.MESSAGES_UPSERT, Events.MESSAGES_UPSERT,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -182,7 +182,7 @@ export class EvolutionStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw); this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
await this.chatwootService.eventWhatsapp( await this.chatwootService.eventWhatsapp(
Events.CONTACTS_UPDATE, Events.CONTACTS_UPDATE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -246,7 +246,7 @@ export class EvolutionStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw); this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isIntegration) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.SEND_MESSAGE, Events.SEND_MESSAGE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -254,7 +254,7 @@ export class EvolutionStartupService extends ChannelStartupService {
); );
} }
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && isIntegration) if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && isIntegration)
await chatbotController.emit({ await chatbotController.emit({
instance: { instanceName: this.instance.name, instanceId: this.instanceId }, instance: { instanceName: this.instance.name, instanceId: this.instanceId },
remoteJid: messageRaw.key.remoteJid, remoteJid: messageRaw.key.remoteJid,

View File

@ -482,7 +482,7 @@ export class BusinessStartupService extends ChannelStartupService {
pushName: messageRaw.pushName, pushName: messageRaw.pushName,
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
const chatwootSentMessage = await this.chatwootService.eventWhatsapp( const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
Events.MESSAGES_UPSERT, Events.MESSAGES_UPSERT,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -525,7 +525,7 @@ export class BusinessStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw); this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
await this.chatwootService.eventWhatsapp( await this.chatwootService.eventWhatsapp(
Events.CONTACTS_UPDATE, Events.CONTACTS_UPDATE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -588,7 +588,7 @@ export class BusinessStartupService extends ChannelStartupService {
data: message, data: message,
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.MESSAGES_DELETE, Events.MESSAGES_DELETE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -908,7 +908,7 @@ export class BusinessStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw); this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isIntegration) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.SEND_MESSAGE, Events.SEND_MESSAGE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -916,7 +916,7 @@ export class BusinessStartupService extends ChannelStartupService {
); );
} }
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && isIntegration) if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && isIntegration)
await chatbotController.emit({ await chatbotController.emit({
instance: { instanceName: this.instance.name, instanceId: this.instanceId }, instance: { instanceName: this.instance.name, instanceId: this.instanceId },
remoteJid: messageRaw.key.remoteJid, remoteJid: messageRaw.key.remoteJid,

View File

@ -221,7 +221,7 @@ export class BaileysStartupService extends ChannelStartupService {
statusCode: DisconnectReason.badSession, statusCode: DisconnectReason.badSession,
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.QRCODE_UPDATED, Events.QRCODE_UPDATED,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -279,7 +279,7 @@ export class BaileysStartupService extends ChannelStartupService {
}, },
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.QRCODE_UPDATED, Events.QRCODE_UPDATED,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -347,7 +347,7 @@ export class BaileysStartupService extends ChannelStartupService {
}, },
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.STATUS_INSTANCE, Events.STATUS_INSTANCE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -392,7 +392,7 @@ export class BaileysStartupService extends ChannelStartupService {
}, },
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.CONNECTION_UPDATE, Events.CONNECTION_UPDATE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -499,7 +499,7 @@ export class BaileysStartupService extends ChannelStartupService {
let options; let options;
if (this.localProxy.enabled) { if (this.localProxy?.enabled) {
this.logger.info('Proxy enabled: ' + this.localProxy?.host); this.logger.info('Proxy enabled: ' + this.localProxy?.host);
if (this.localProxy?.host?.includes('proxyscrape')) { if (this.localProxy?.host?.includes('proxyscrape')) {
@ -694,7 +694,7 @@ export class BaileysStartupService extends ChannelStartupService {
if ( if (
this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.configService.get<Chatwoot>('CHATWOOT').ENABLED &&
this.localChatwoot.enabled && this.localChatwoot?.enabled &&
this.localChatwoot.importContacts && this.localChatwoot.importContacts &&
contactsRaw.length contactsRaw.length
) { ) {
@ -810,7 +810,7 @@ export class BaileysStartupService extends ChannelStartupService {
let timestampLimitToImport = null; let timestampLimitToImport = null;
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) {
const daysLimitToImport = this.localChatwoot.enabled ? this.localChatwoot.daysLimitImportMessages : 1000; const daysLimitToImport = this.localChatwoot?.enabled ? this.localChatwoot.daysLimitImportMessages : 1000;
const date = new Date(); const date = new Date();
timestampLimitToImport = new Date(date.setDate(date.getDate() - daysLimitToImport)).getTime() / 1000; timestampLimitToImport = new Date(date.setDate(date.getDate() - daysLimitToImport)).getTime() / 1000;
@ -918,7 +918,7 @@ export class BaileysStartupService extends ChannelStartupService {
if ( if (
this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.configService.get<Chatwoot>('CHATWOOT').ENABLED &&
this.localChatwoot.enabled && this.localChatwoot?.enabled &&
this.localChatwoot.importMessages && this.localChatwoot.importMessages &&
messagesRaw.length > 0 messagesRaw.length > 0
) { ) {
@ -979,7 +979,7 @@ export class BaileysStartupService extends ChannelStartupService {
const editedMessage = const editedMessage =
received.message?.protocolMessage || received.message?.editedMessage?.message?.protocolMessage; received.message?.protocolMessage || received.message?.editedMessage?.message?.protocolMessage;
if (editedMessage) { if (editedMessage) {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled)
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
'messages.edit', 'messages.edit',
{ instanceName: this.instance.name, instanceId: this.instance.id }, { instanceName: this.instance.name, instanceId: this.instance.id },
@ -1055,7 +1055,7 @@ export class BaileysStartupService extends ChannelStartupService {
if ( if (
this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.configService.get<Chatwoot>('CHATWOOT').ENABLED &&
this.localChatwoot.enabled && this.localChatwoot?.enabled &&
!received.key.id.includes('@broadcast') !received.key.id.includes('@broadcast')
) { ) {
const chatwootSentMessage = await this.chatwootService.eventWhatsapp( const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
@ -1192,7 +1192,7 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw); this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
await this.chatwootService.eventWhatsapp( await this.chatwootService.eventWhatsapp(
Events.CONTACTS_UPDATE, Events.CONTACTS_UPDATE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -1242,7 +1242,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
if (status[update.status] === 'READ' && key.fromMe) { if (status[update.status] === 'READ' && key.fromMe) {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
'messages.read', 'messages.read',
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -1298,7 +1298,7 @@ export class BaileysStartupService extends ChannelStartupService {
data: message, data: message,
}); });
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.MESSAGES_DELETE, Events.MESSAGES_DELETE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -1554,7 +1554,7 @@ export class BaileysStartupService extends ChannelStartupService {
if ( if (
this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.configService.get<Chatwoot>('CHATWOOT').ENABLED &&
this.localChatwoot.enabled && this.localChatwoot?.enabled &&
this.localChatwoot.importMessages && this.localChatwoot.importMessages &&
this.isSyncNotificationFromUsedSyncType(msg) this.isSyncNotificationFromUsedSyncType(msg)
) { ) {
@ -1809,7 +1809,7 @@ export class BaileysStartupService extends ChannelStartupService {
const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift(); const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift();
if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) { if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
const body = { const body = {
key: { remoteJid: isWA.jid }, key: { remoteJid: isWA.jid },
}; };
@ -1941,7 +1941,7 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw); this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isIntegration) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.SEND_MESSAGE, Events.SEND_MESSAGE,
{ instanceName: this.instance.name, instanceId: this.instanceId }, { instanceName: this.instance.name, instanceId: this.instanceId },
@ -1949,7 +1949,7 @@ export class BaileysStartupService extends ChannelStartupService {
); );
} }
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && isIntegration) if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled && isIntegration)
await chatbotController.emit({ await chatbotController.emit({
instance: { instanceName: this.instance.name, instanceId: this.instanceId }, instance: { instanceName: this.instance.name, instanceId: this.instanceId },
remoteJid: messageRaw.key.remoteJid, remoteJid: messageRaw.key.remoteJid,
@ -2226,7 +2226,7 @@ export class BaileysStartupService extends ChannelStartupService {
responseType: 'arraybuffer', responseType: 'arraybuffer',
}; };
if (this.localProxy.enabled) { if (this.localProxy?.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent({ httpsAgent: makeProxyAgent({
@ -2283,7 +2283,7 @@ export class BaileysStartupService extends ChannelStartupService {
responseType: 'arraybuffer', responseType: 'arraybuffer',
}; };
if (this.localProxy.enabled) { if (this.localProxy?.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent({ httpsAgent: makeProxyAgent({
@ -3016,7 +3016,7 @@ export class BaileysStartupService extends ChannelStartupService {
responseType: 'arraybuffer', responseType: 'arraybuffer',
}; };
if (this.localProxy.enabled) { if (this.localProxy?.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent({ httpsAgent: makeProxyAgent({
@ -3264,7 +3264,7 @@ export class BaileysStartupService extends ChannelStartupService {
responseType: 'arraybuffer', responseType: 'arraybuffer',
}; };
if (this.localProxy.enabled) { if (this.localProxy?.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent({ httpsAgent: makeProxyAgent({

View File

@ -19,7 +19,7 @@ export class ChatwootController {
public async createChatwoot(instance: InstanceDto, data: ChatwootDto) { public async createChatwoot(instance: InstanceDto, data: ChatwootDto) {
if (!this.configService.get<Chatwoot>('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is disabled'); if (!this.configService.get<Chatwoot>('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is disabled');
if (data.enabled) { if (data?.enabled) {
if (!isURL(data.url, { require_tld: false })) { if (!isURL(data.url, { require_tld: false })) {
throw new BadRequestException('url is not valid'); throw new BadRequestException('url is not valid');
} }

View File

@ -150,7 +150,7 @@ export class DifyController extends ChatbotController implements ChatbotControll
try { try {
const bot = await this.botRepository.create({ const bot = await this.botRepository.create({
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
description: data.description, description: data.description,
botType: data.botType, botType: data.botType,
apiUrl: data.apiUrl, apiUrl: data.apiUrl,
@ -331,7 +331,7 @@ export class DifyController extends ChatbotController implements ChatbotControll
id: botId, id: botId,
}, },
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
botType: data.botType, botType: data.botType,
apiUrl: data.apiUrl, apiUrl: data.apiUrl,
apiKey: data.apiKey, apiKey: data.apiKey,

View File

@ -145,7 +145,7 @@ export class FlowiseController extends ChatbotController implements ChatbotContr
try { try {
const bot = await this.botRepository.create({ const bot = await this.botRepository.create({
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
description: data.description, description: data.description,
apiUrl: data.apiUrl, apiUrl: data.apiUrl,
apiKey: data.apiKey, apiKey: data.apiKey,
@ -318,7 +318,7 @@ export class FlowiseController extends ChatbotController implements ChatbotContr
id: botId, id: botId,
}, },
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
apiUrl: data.apiUrl, apiUrl: data.apiUrl,
apiKey: data.apiKey, apiKey: data.apiKey,
expire: data.expire, expire: data.expire,

View File

@ -145,7 +145,7 @@ export class GenericController extends ChatbotController implements ChatbotContr
try { try {
const bot = await this.botRepository.create({ const bot = await this.botRepository.create({
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
description: data.description, description: data.description,
apiUrl: data.apiUrl, apiUrl: data.apiUrl,
apiKey: data.apiKey, apiKey: data.apiKey,
@ -318,7 +318,7 @@ export class GenericController extends ChatbotController implements ChatbotContr
id: botId, id: botId,
}, },
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
apiUrl: data.apiUrl, apiUrl: data.apiUrl,
apiKey: data.apiKey, apiKey: data.apiKey,
expire: data.expire, expire: data.expire,

View File

@ -314,7 +314,7 @@ export class OpenaiController extends ChatbotController implements ChatbotContro
try { try {
const bot = await this.botRepository.create({ const bot = await this.botRepository.create({
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
description: data.description, description: data.description,
openaiCredsId: data.openaiCredsId, openaiCredsId: data.openaiCredsId,
botType: data.botType, botType: data.botType,
@ -528,7 +528,7 @@ export class OpenaiController extends ChatbotController implements ChatbotContro
id: botId, id: botId,
}, },
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
openaiCredsId: data.openaiCredsId, openaiCredsId: data.openaiCredsId,
botType: data.botType, botType: data.botType,
assistantId: data.assistantId, assistantId: data.assistantId,

View File

@ -151,7 +151,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
try { try {
const bot = await this.botRepository.create({ const bot = await this.botRepository.create({
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
description: data.description, description: data.description,
url: data.url, url: data.url,
typebot: data.typebot, typebot: data.typebot,
@ -334,7 +334,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
id: botId, id: botId,
}, },
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
url: data.url, url: data.url,
typebot: data.typebot, typebot: data.typebot,
expire: data.expire, expire: data.expire,

View File

@ -382,7 +382,7 @@ export class TypebotService {
} }
const data = await this.createNewSession(instance, { const data = await this.createNewSession(instance, {
enabled: findTypebot.enabled, enabled: findTypebot?.enabled,
url: url, url: url,
typebot: typebot, typebot: typebot,
expire: expire, expire: expire,

View File

@ -76,7 +76,7 @@ export class EventController {
return; return;
} }
if (!data[this.name].enabled) { if (!data[this.name]?.enabled) {
data[this.name].events = []; data[this.name].events = [];
} else { } else {
if (0 === data[this.name].events.length) { if (0 === data[this.name].events.length) {
@ -92,7 +92,7 @@ export class EventController {
...data, ...data,
}, },
create: { create: {
enabled: data[this.name].enabled, enabled: data[this.name]?.enabled,
events: data[this.name].events, events: data[this.name].events,
instanceId: this.monitor.waInstances[instanceName].instanceId, instanceId: this.monitor.waInstances[instanceName].instanceId,
}, },

View File

@ -22,7 +22,7 @@ export class WebhookController extends EventController implements EventControlle
throw new BadRequestException('Invalid "url" property'); throw new BadRequestException('Invalid "url" property');
} }
if (!data.webhook.enabled) { if (!data.webhook?.enabled) {
data.webhook.events = []; data.webhook.events = [];
} else { } else {
if (0 === data.webhook.events.length) { if (0 === data.webhook.events.length) {
@ -38,7 +38,7 @@ export class WebhookController extends EventController implements EventControlle
...data.webhook, ...data.webhook,
}, },
create: { create: {
enabled: data.webhook.enabled, enabled: data.webhook?.enabled,
events: data.webhook.events, events: data.webhook.events,
instanceId: this.monitor.waInstances[instanceName].instanceId, instanceId: this.monitor.waInstances[instanceName].instanceId,
url: data.webhook.url, url: data.webhook.url,
@ -61,7 +61,7 @@ export class WebhookController extends EventController implements EventControlle
}: EmitData): Promise<void> { }: EmitData): Promise<void> {
const instance = (await this.get(instanceName)) as EventDto; const instance = (await this.get(instanceName)) as EventDto;
if (!instance || !instance.webhook.enabled) { if (!instance || !instance.webhook?.enabled) {
return; return;
} }

View File

@ -97,7 +97,7 @@ export class WebsocketController extends EventController implements EventControl
try { try {
const instance = (await this.get(instanceName)) as EventDto; const instance = (await this.get(instanceName)) as EventDto;
if (!instance?.websocket.enabled) { if (!instance?.websocket?.enabled) {
return; return;
} }

View File

@ -58,7 +58,7 @@ export class ChannelStartupService {
this.instance.token = instance.token; this.instance.token = instance.token;
this.instance.businessId = instance.businessId; this.instance.businessId = instance.businessId;
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) { if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp( this.chatwootService.eventWhatsapp(
Events.STATUS_INSTANCE, Events.STATUS_INSTANCE,
{ instanceName: this.instance.name }, { instanceName: this.instance.name },
@ -241,7 +241,7 @@ export class ChannelStartupService {
instanceId: this.instanceId, instanceId: this.instanceId,
}, },
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
accountId: data.accountId, accountId: data.accountId,
token: data.token, token: data.token,
url: data.url, url: data.url,
@ -269,7 +269,7 @@ export class ChannelStartupService {
await this.prismaRepository.chatwoot.create({ await this.prismaRepository.chatwoot.create({
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
accountId: data.accountId, accountId: data.accountId,
token: data.token, token: data.token,
url: data.url, url: data.url,
@ -312,7 +312,7 @@ export class ChannelStartupService {
const ignoreJidsArray = Array.isArray(data.ignoreJids) ? data.ignoreJids.map((event) => String(event)) : []; const ignoreJidsArray = Array.isArray(data.ignoreJids) ? data.ignoreJids.map((event) => String(event)) : [];
return { return {
enabled: data.enabled, enabled: data?.enabled,
accountId: data.accountId, accountId: data.accountId,
token: data.token, token: data.token,
url: data.url, url: data.url,
@ -332,7 +332,7 @@ export class ChannelStartupService {
} }
public clearCacheChatwoot() { public clearCacheChatwoot() {
if (this.localChatwoot.enabled) { if (this.localChatwoot?.enabled) {
this.chatwootService.getCache()?.deleteAll(this.instanceName); this.chatwootService.getCache()?.deleteAll(this.instanceName);
} }
} }
@ -355,7 +355,7 @@ export class ChannelStartupService {
public async setProxy(data: ProxyDto) { public async setProxy(data: ProxyDto) {
await this.prismaRepository.proxy.create({ await this.prismaRepository.proxy.create({
data: { data: {
enabled: data.enabled, enabled: data?.enabled,
host: data.host, host: data.host,
port: data.port, port: data.port,
protocol: data.protocol, protocol: data.protocol,