mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-19 17:59:12 -06:00
fix: For compatibility reasons, container mode has been removed
This commit is contained in:
parent
091b920a22
commit
19039aa281
@ -7,6 +7,7 @@
|
|||||||
* Adjustments to search endpoint for contacts, chats, messages and Status messages
|
* Adjustments to search endpoint for contacts, chats, messages and Status messages
|
||||||
* Now when deleting the instance, the data referring to it in mongodb is also deleted
|
* Now when deleting the instance, the data referring to it in mongodb is also deleted
|
||||||
* It is now validated if the instance name contains uppercase and special characters
|
* It is now validated if the instance name contains uppercase and special characters
|
||||||
|
* For compatibility reasons, container mode has been removed
|
||||||
|
|
||||||
# 1.3.1 (2023-07-20 07:48)
|
# 1.3.1 (2023-07-20 07:48)
|
||||||
|
|
||||||
|
@ -97,13 +97,3 @@ AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
|
|||||||
# seconds - 3600s ===1h | zero (0) - never expires
|
# seconds - 3600s ===1h | zero (0) - never expires
|
||||||
AUTHENTICATION_JWT_EXPIRIN_IN=0
|
AUTHENTICATION_JWT_EXPIRIN_IN=0
|
||||||
AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
|
AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
|
||||||
# Set the instance name and webhook url to create an instance in init the application
|
|
||||||
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
|
|
||||||
# container or server
|
|
||||||
AUTHENTICATION_INSTANCE_MODE=server
|
|
||||||
# if you are using container mode, set the container name and the webhook url to default instance
|
|
||||||
AUTHENTICATION_INSTANCE_NAME=evolution
|
|
||||||
AUTHENTICATION_INSTANCE_WEBHOOK_URL=''
|
|
||||||
AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
|
|
||||||
AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
|
|
||||||
AUTHENTICATION_INSTANCE_CHATWOOT_URL=''
|
|
||||||
|
@ -94,20 +94,12 @@ export type EventsWebhook = {
|
|||||||
|
|
||||||
export type ApiKey = { KEY: string };
|
export type ApiKey = { KEY: string };
|
||||||
export type Jwt = { EXPIRIN_IN: number; SECRET: string };
|
export type Jwt = { EXPIRIN_IN: number; SECRET: string };
|
||||||
export type Instance = {
|
|
||||||
NAME: string;
|
|
||||||
WEBHOOK_URL: string;
|
|
||||||
MODE: string;
|
|
||||||
CHATWOOT_ACCOUNT_ID: string;
|
|
||||||
CHATWOOT_TOKEN: string;
|
|
||||||
CHATWOOT_URL: string;
|
|
||||||
};
|
|
||||||
export type Auth = {
|
export type Auth = {
|
||||||
API_KEY: ApiKey;
|
API_KEY: ApiKey;
|
||||||
EXPOSE_IN_FETCH_INSTANCES: boolean;
|
EXPOSE_IN_FETCH_INSTANCES: boolean;
|
||||||
JWT: Jwt;
|
JWT: Jwt;
|
||||||
TYPE: 'jwt' | 'apikey';
|
TYPE: 'jwt' | 'apikey';
|
||||||
INSTANCE: Instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DelInstance = number | boolean;
|
export type DelInstance = number | boolean;
|
||||||
@ -276,15 +268,6 @@ export class ConfigService {
|
|||||||
: 3600,
|
: 3600,
|
||||||
SECRET: process.env.AUTHENTICATION_JWT_SECRET,
|
SECRET: process.env.AUTHENTICATION_JWT_SECRET,
|
||||||
},
|
},
|
||||||
INSTANCE: {
|
|
||||||
NAME: process.env.AUTHENTICATION_INSTANCE_NAME,
|
|
||||||
WEBHOOK_URL: process.env.AUTHENTICATION_INSTANCE_WEBHOOK_URL,
|
|
||||||
MODE: process.env.AUTHENTICATION_INSTANCE_MODE,
|
|
||||||
CHATWOOT_ACCOUNT_ID:
|
|
||||||
process.env.AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID || '',
|
|
||||||
CHATWOOT_TOKEN: process.env.AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN || '',
|
|
||||||
CHATWOOT_URL: process.env.AUTHENTICATION_INSTANCE_CHATWOOT_URL || '',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -137,13 +137,3 @@ AUTHENTICATION:
|
|||||||
JWT:
|
JWT:
|
||||||
EXPIRIN_IN: 0 # seconds - 3600s === 1h | zero (0) - never expires
|
EXPIRIN_IN: 0 # seconds - 3600s === 1h | zero (0) - never expires
|
||||||
SECRET: L=0YWt]b2w[WF>#>:&E`
|
SECRET: L=0YWt]b2w[WF>#>:&E`
|
||||||
# Set the instance name and webhook url to create an instance in init the application
|
|
||||||
INSTANCE:
|
|
||||||
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
|
|
||||||
MODE: server # container or server
|
|
||||||
# if you are using container mode, set the container name and the webhook url to default instance
|
|
||||||
NAME: evolution
|
|
||||||
WEBHOOK_URL: <url>
|
|
||||||
CHATWOOT_ACCOUNT_ID: 1
|
|
||||||
CHATWOOT_TOKEN: 123456
|
|
||||||
CHATWOOT_URL: <url>
|
|
||||||
|
@ -48,273 +48,80 @@ export class InstanceController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
this.logger.verbose('checking duplicate token');
|
||||||
|
await this.authService.checkDuplicateToken(token);
|
||||||
|
|
||||||
if (mode === 'container') {
|
this.logger.verbose('creating instance');
|
||||||
this.logger.verbose('container mode');
|
const instance = new WAStartupService(
|
||||||
|
this.configService,
|
||||||
|
this.eventEmitter,
|
||||||
|
this.repository,
|
||||||
|
this.cache,
|
||||||
|
);
|
||||||
|
instance.instanceName = instanceName
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]/g, '')
|
||||||
|
.replace(' ', '');
|
||||||
|
|
||||||
if (Object.keys(this.waMonitor.waInstances).length > 0) {
|
this.logger.verbose('instance: ' + instance.instanceName + ' created');
|
||||||
throw new BadRequestException([
|
|
||||||
'Instance already created',
|
this.waMonitor.waInstances[instance.instanceName] = instance;
|
||||||
'Only one instance can be created',
|
this.waMonitor.delInstanceTime(instance.instanceName);
|
||||||
]);
|
|
||||||
|
this.logger.verbose('generating hash');
|
||||||
|
const hash = await this.authService.generateHash(
|
||||||
|
{
|
||||||
|
instanceName: instance.instanceName,
|
||||||
|
},
|
||||||
|
token,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.logger.verbose('hash: ' + hash + ' generated');
|
||||||
|
|
||||||
|
let getEvents: string[];
|
||||||
|
|
||||||
|
if (webhook) {
|
||||||
|
if (!isURL(webhook, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in webhook');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('checking duplicate token');
|
this.logger.verbose('creating webhook');
|
||||||
await this.authService.checkDuplicateToken(token);
|
|
||||||
|
|
||||||
this.logger.verbose('creating instance');
|
|
||||||
const instance = new WAStartupService(
|
|
||||||
this.configService,
|
|
||||||
this.eventEmitter,
|
|
||||||
this.repository,
|
|
||||||
this.cache,
|
|
||||||
);
|
|
||||||
instance.instanceName = instanceName
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/[^a-z0-9]/g, '')
|
|
||||||
.replace(' ', '');
|
|
||||||
this.logger.verbose('instance: ' + instance.instanceName + ' created');
|
|
||||||
|
|
||||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
|
||||||
this.waMonitor.delInstanceTime(instance.instanceName);
|
|
||||||
|
|
||||||
this.logger.verbose('generating hash');
|
|
||||||
const hash = await this.authService.generateHash(
|
|
||||||
{
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
},
|
|
||||||
token,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.logger.verbose('hash: ' + hash + ' generated');
|
|
||||||
|
|
||||||
let getEvents: string[];
|
|
||||||
|
|
||||||
if (webhook) {
|
|
||||||
if (!isURL(webhook, { require_tld: false })) {
|
|
||||||
throw new BadRequestException('Invalid "url" property in webhook');
|
|
||||||
}
|
|
||||||
this.logger.verbose('creating webhook');
|
|
||||||
try {
|
|
||||||
this.webhookService.create(instance, {
|
|
||||||
enabled: true,
|
|
||||||
url: webhook,
|
|
||||||
events,
|
|
||||||
webhook_by_events,
|
|
||||||
});
|
|
||||||
|
|
||||||
getEvents = (await this.webhookService.find(instance)).events;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
|
||||||
this.logger.verbose('instance created');
|
|
||||||
this.logger.verbose({
|
|
||||||
instance: {
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
status: 'created',
|
|
||||||
},
|
|
||||||
hash,
|
|
||||||
webhook,
|
|
||||||
events: getEvents,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
instance: {
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
status: 'created',
|
|
||||||
},
|
|
||||||
hash,
|
|
||||||
webhook,
|
|
||||||
events: getEvents,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_account_id) {
|
|
||||||
throw new BadRequestException('account_id is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_token) {
|
|
||||||
throw new BadRequestException('token is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_url) {
|
|
||||||
throw new BadRequestException('url is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isURL(chatwoot_url, { require_tld: false })) {
|
|
||||||
throw new BadRequestException('Invalid "url" property in chatwoot');
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.chatwootService.create(instance, {
|
this.webhookService.create(instance, {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
account_id: chatwoot_account_id,
|
url: webhook,
|
||||||
token: chatwoot_token,
|
events,
|
||||||
url: chatwoot_url,
|
webhook_by_events,
|
||||||
sign_msg: chatwoot_sign_msg || false,
|
|
||||||
name_inbox: instance.instanceName,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chatwootService.initInstanceChatwoot(
|
getEvents = (await this.webhookService.find(instance)).events;
|
||||||
instance,
|
|
||||||
instance.instanceName,
|
|
||||||
`${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
|
||||||
qrcode,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.log(error);
|
this.logger.log(error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
||||||
|
let getQrcode: wa.QrCode;
|
||||||
|
|
||||||
|
if (qrcode) {
|
||||||
|
this.logger.verbose('creating qrcode');
|
||||||
|
await instance.connectToWhatsapp();
|
||||||
|
await delay(2000);
|
||||||
|
getQrcode = instance.qrCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('instance created');
|
||||||
|
this.logger.verbose({
|
||||||
instance: {
|
instance: {
|
||||||
instanceName: instance.instanceName,
|
instanceName: instance.instanceName,
|
||||||
status: 'created',
|
status: 'created',
|
||||||
},
|
},
|
||||||
hash,
|
hash,
|
||||||
chatwoot: {
|
webhook,
|
||||||
enabled: true,
|
webhook_by_events,
|
||||||
account_id: chatwoot_account_id,
|
events: getEvents,
|
||||||
token: chatwoot_token,
|
qrcode: getQrcode,
|
||||||
url: chatwoot_url,
|
});
|
||||||
sign_msg: chatwoot_sign_msg || false,
|
|
||||||
name_inbox: instance.instanceName,
|
|
||||||
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
this.logger.verbose('server mode');
|
|
||||||
|
|
||||||
this.logger.verbose('checking duplicate token');
|
|
||||||
await this.authService.checkDuplicateToken(token);
|
|
||||||
|
|
||||||
this.logger.verbose('creating instance');
|
|
||||||
const instance = new WAStartupService(
|
|
||||||
this.configService,
|
|
||||||
this.eventEmitter,
|
|
||||||
this.repository,
|
|
||||||
this.cache,
|
|
||||||
);
|
|
||||||
instance.instanceName = instanceName
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/[^a-z0-9]/g, '')
|
|
||||||
.replace(' ', '');
|
|
||||||
|
|
||||||
this.logger.verbose('instance: ' + instance.instanceName + ' created');
|
|
||||||
|
|
||||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
|
||||||
this.waMonitor.delInstanceTime(instance.instanceName);
|
|
||||||
|
|
||||||
this.logger.verbose('generating hash');
|
|
||||||
const hash = await this.authService.generateHash(
|
|
||||||
{
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
},
|
|
||||||
token,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.logger.verbose('hash: ' + hash + ' generated');
|
|
||||||
|
|
||||||
let getEvents: string[];
|
|
||||||
|
|
||||||
if (webhook) {
|
|
||||||
if (!isURL(webhook, { require_tld: false })) {
|
|
||||||
throw new BadRequestException('Invalid "url" property in webhook');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.verbose('creating webhook');
|
|
||||||
try {
|
|
||||||
this.webhookService.create(instance, {
|
|
||||||
enabled: true,
|
|
||||||
url: webhook,
|
|
||||||
events,
|
|
||||||
webhook_by_events,
|
|
||||||
});
|
|
||||||
|
|
||||||
getEvents = (await this.webhookService.find(instance)).events;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
|
||||||
let getQrcode: wa.QrCode;
|
|
||||||
|
|
||||||
if (qrcode) {
|
|
||||||
this.logger.verbose('creating qrcode');
|
|
||||||
await instance.connectToWhatsapp();
|
|
||||||
await delay(2000);
|
|
||||||
getQrcode = instance.qrCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.verbose('instance created');
|
|
||||||
this.logger.verbose({
|
|
||||||
instance: {
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
status: 'created',
|
|
||||||
},
|
|
||||||
hash,
|
|
||||||
webhook,
|
|
||||||
webhook_by_events,
|
|
||||||
events: getEvents,
|
|
||||||
qrcode: getQrcode,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
instance: {
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
status: 'created',
|
|
||||||
},
|
|
||||||
hash,
|
|
||||||
webhook,
|
|
||||||
webhook_by_events,
|
|
||||||
events: getEvents,
|
|
||||||
qrcode: getQrcode,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_account_id) {
|
|
||||||
throw new BadRequestException('account_id is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_token) {
|
|
||||||
throw new BadRequestException('token is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chatwoot_url) {
|
|
||||||
throw new BadRequestException('url is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isURL(chatwoot_url, { require_tld: false })) {
|
|
||||||
throw new BadRequestException('Invalid "url" property in chatwoot');
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.chatwootService.create(instance, {
|
|
||||||
enabled: true,
|
|
||||||
account_id: chatwoot_account_id,
|
|
||||||
token: chatwoot_token,
|
|
||||||
url: chatwoot_url,
|
|
||||||
sign_msg: chatwoot_sign_msg || false,
|
|
||||||
name_inbox: instance.instanceName,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.chatwootService.initInstanceChatwoot(
|
|
||||||
instance,
|
|
||||||
instance.instanceName,
|
|
||||||
`${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
|
||||||
qrcode,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
instance: {
|
instance: {
|
||||||
@ -325,17 +132,67 @@ export class InstanceController {
|
|||||||
webhook,
|
webhook,
|
||||||
webhook_by_events,
|
webhook_by_events,
|
||||||
events: getEvents,
|
events: getEvents,
|
||||||
chatwoot: {
|
qrcode: getQrcode,
|
||||||
enabled: true,
|
|
||||||
account_id: chatwoot_account_id,
|
|
||||||
token: chatwoot_token,
|
|
||||||
url: chatwoot_url,
|
|
||||||
sign_msg: chatwoot_sign_msg || false,
|
|
||||||
name_inbox: instance.instanceName,
|
|
||||||
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!chatwoot_account_id) {
|
||||||
|
throw new BadRequestException('account_id is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chatwoot_token) {
|
||||||
|
throw new BadRequestException('token is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chatwoot_url) {
|
||||||
|
throw new BadRequestException('url is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isURL(chatwoot_url, { require_tld: false })) {
|
||||||
|
throw new BadRequestException('Invalid "url" property in chatwoot');
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.chatwootService.create(instance, {
|
||||||
|
enabled: true,
|
||||||
|
account_id: chatwoot_account_id,
|
||||||
|
token: chatwoot_token,
|
||||||
|
url: chatwoot_url,
|
||||||
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
|
name_inbox: instance.instanceName,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.chatwootService.initInstanceChatwoot(
|
||||||
|
instance,
|
||||||
|
instance.instanceName,
|
||||||
|
`${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||||
|
qrcode,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.log(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
instance: {
|
||||||
|
instanceName: instance.instanceName,
|
||||||
|
status: 'created',
|
||||||
|
},
|
||||||
|
hash,
|
||||||
|
webhook,
|
||||||
|
webhook_by_events,
|
||||||
|
events: getEvents,
|
||||||
|
chatwoot: {
|
||||||
|
enabled: true,
|
||||||
|
account_id: chatwoot_account_id,
|
||||||
|
token: chatwoot_token,
|
||||||
|
url: chatwoot_url,
|
||||||
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
|
name_inbox: instance.instanceName,
|
||||||
|
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async connectToWhatsapp({ instanceName }: InstanceDto) {
|
public async connectToWhatsapp({ instanceName }: InstanceDto) {
|
||||||
|
@ -15,7 +15,6 @@ import {
|
|||||||
import { RepositoryBroker } from '../repository/repository.manager';
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
import { NotFoundException } from '../../exceptions';
|
import { NotFoundException } from '../../exceptions';
|
||||||
import { Db } from 'mongodb';
|
import { Db } from 'mongodb';
|
||||||
import { initInstance } from '../whatsapp.module';
|
|
||||||
import { RedisCache } from '../../db/redis.client';
|
import { RedisCache } from '../../db/redis.client';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { dbserver } from '../../db/db.connect';
|
import { dbserver } from '../../db/db.connect';
|
||||||
@ -287,7 +286,6 @@ export class WAMonitoringService {
|
|||||||
keys.forEach(async (k) => await set(k.split(':')[1]));
|
keys.forEach(async (k) => await set(k.split(':')[1]));
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('no instance keys found');
|
this.logger.verbose('no instance keys found');
|
||||||
initInstance();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -303,7 +301,6 @@ export class WAMonitoringService {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('no collections found');
|
this.logger.verbose('no collections found');
|
||||||
initInstance();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -324,7 +321,6 @@ export class WAMonitoringService {
|
|||||||
await set(dirent.name);
|
await set(dirent.name);
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('no instance files found');
|
this.logger.verbose('no instance files found');
|
||||||
initInstance();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -346,7 +346,6 @@ export class WAStartupService {
|
|||||||
const serverUrl = this.configService.get<HttpServer>('SERVER').URL;
|
const serverUrl = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
const we = event.replace(/[\.-]/gm, '_').toUpperCase();
|
const we = event.replace(/[\.-]/gm, '_').toUpperCase();
|
||||||
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
const transformedWe = we.replace(/_/gm, '-').toLowerCase();
|
||||||
const instance = this.configService.get<Auth>('AUTHENTICATION').INSTANCE;
|
|
||||||
|
|
||||||
const expose =
|
const expose =
|
||||||
this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES;
|
this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES;
|
||||||
@ -355,7 +354,7 @@ export class WAStartupService {
|
|||||||
|
|
||||||
const globalApiKey = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
|
const globalApiKey = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
|
||||||
|
|
||||||
if (local && instance.MODE !== 'container') {
|
if (local) {
|
||||||
if (Array.isArray(webhookLocal) && webhookLocal.includes(we)) {
|
if (Array.isArray(webhookLocal) && webhookLocal.includes(we)) {
|
||||||
this.logger.verbose('Sending data to webhook local');
|
this.logger.verbose('Sending data to webhook local');
|
||||||
let baseURL;
|
let baseURL;
|
||||||
@ -432,13 +431,7 @@ export class WAStartupService {
|
|||||||
globalURL = globalWebhook.URL;
|
globalURL = globalWebhook.URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
let localUrl;
|
const localUrl = this.localWebhook.url;
|
||||||
|
|
||||||
if (instance.MODE === 'container') {
|
|
||||||
localUrl = instance.WEBHOOK_URL;
|
|
||||||
} else {
|
|
||||||
localUrl = this.localWebhook.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
|
@ -91,111 +91,4 @@ export const sendMessageController = new SendMessageController(waMonitor);
|
|||||||
export const chatController = new ChatController(waMonitor);
|
export const chatController = new ChatController(waMonitor);
|
||||||
export const groupController = new GroupController(waMonitor);
|
export const groupController = new GroupController(waMonitor);
|
||||||
|
|
||||||
export async function initInstance() {
|
|
||||||
const instance = new WAStartupService(configService, eventEmitter, repository, cache);
|
|
||||||
|
|
||||||
const mode = configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
|
||||||
|
|
||||||
logger.verbose('Sending data webhook for event: ' + Events.APPLICATION_STARTUP);
|
|
||||||
instance.sendDataWebhook(
|
|
||||||
Events.APPLICATION_STARTUP,
|
|
||||||
{
|
|
||||||
message: 'Application startup',
|
|
||||||
mode,
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (mode === 'container') {
|
|
||||||
logger.verbose('Application startup in container mode');
|
|
||||||
|
|
||||||
const instanceName = configService.get<Auth>('AUTHENTICATION').INSTANCE.NAME;
|
|
||||||
logger.verbose('Instance name: ' + instanceName);
|
|
||||||
|
|
||||||
const instanceWebhook =
|
|
||||||
configService.get<Auth>('AUTHENTICATION').INSTANCE.WEBHOOK_URL;
|
|
||||||
logger.verbose('Instance webhook: ' + instanceWebhook);
|
|
||||||
|
|
||||||
// const chatwootAccountId =
|
|
||||||
// configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_ACCOUNT_ID;
|
|
||||||
// logger.verbose('Chatwoot account id: ' + chatwootAccountId);
|
|
||||||
|
|
||||||
// const chatwootToken =
|
|
||||||
// configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_TOKEN;
|
|
||||||
// logger.verbose('Chatwoot token: ' + chatwootToken);
|
|
||||||
|
|
||||||
// const chatwootUrl = configService.get<Auth>('AUTHENTICATION').INSTANCE.CHATWOOT_URL;
|
|
||||||
// logger.verbose('Chatwoot url: ' + chatwootUrl);
|
|
||||||
|
|
||||||
instance.instanceName = instanceName;
|
|
||||||
|
|
||||||
waMonitor.waInstances[instance.instanceName] = instance;
|
|
||||||
waMonitor.delInstanceTime(instance.instanceName);
|
|
||||||
|
|
||||||
const hash = await authService.generateHash({
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
token: configService.get<Auth>('AUTHENTICATION').API_KEY.KEY,
|
|
||||||
});
|
|
||||||
logger.verbose('Hash generated: ' + hash);
|
|
||||||
|
|
||||||
if (instanceWebhook) {
|
|
||||||
logger.verbose('Creating webhook for instance: ' + instanceName);
|
|
||||||
try {
|
|
||||||
webhookService.create(instance, { enabled: true, url: instanceWebhook });
|
|
||||||
logger.verbose('Webhook created');
|
|
||||||
} catch (error) {
|
|
||||||
logger.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (chatwootUrl && chatwootToken && chatwootAccountId) {
|
|
||||||
// logger.verbose('Creating chatwoot for instance: ' + instanceName);
|
|
||||||
// try {
|
|
||||||
// chatwootService.create(instance, {
|
|
||||||
// enabled: true,
|
|
||||||
// url: chatwootUrl,
|
|
||||||
// token: chatwootToken,
|
|
||||||
// account_id: chatwootAccountId,
|
|
||||||
// sign_msg: false,
|
|
||||||
// });
|
|
||||||
// logger.verbose('Chatwoot created');
|
|
||||||
// } catch (error) {
|
|
||||||
// logger.log(error);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
try {
|
|
||||||
const state = instance.connectionStatus?.state;
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case 'close':
|
|
||||||
await instance.connectToWhatsapp();
|
|
||||||
await delay(2000);
|
|
||||||
return instance.qrCode;
|
|
||||||
case 'connecting':
|
|
||||||
return instance.qrCode;
|
|
||||||
default:
|
|
||||||
return await this.connectionState({ instanceName });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
instance: {
|
|
||||||
instanceName: instance.instanceName,
|
|
||||||
status: 'created',
|
|
||||||
},
|
|
||||||
hash,
|
|
||||||
webhook: instanceWebhook,
|
|
||||||
};
|
|
||||||
|
|
||||||
logger.info(result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Module - ON');
|
logger.info('Module - ON');
|
||||||
|
Loading…
Reference in New Issue
Block a user