mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-17 04:32:53 -06:00
Merge pull request #803 from stenioanibal/v2.0.0
Improvements for events management and Chatwoot integration - V2.0.0
This commit is contained in:
commit
e0ac6ab5d5
@ -151,6 +151,8 @@ CHATWOOT_ENABLED=false
|
||||
CHATWOOT_MESSAGE_READ=true
|
||||
# If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp.
|
||||
CHATWOOT_MESSAGE_DELETE=true
|
||||
# If you leave this option as true, a contact will be created on Chatwoot to provide the QR Code and update messages about the instance.
|
||||
CHATWOOT_BOT_CONTACT=true
|
||||
# This db connection is used to import messages from whatsapp to chatwoot database
|
||||
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgresql://user:passwprd@host:5432/chatwoot?sslmode=disable
|
||||
CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE=true
|
||||
|
@ -52,6 +52,8 @@ export class InstanceController {
|
||||
|
||||
const instanceId = v4();
|
||||
|
||||
instanceData.instanceId = instanceId;
|
||||
|
||||
let hash: string;
|
||||
|
||||
if (!instanceData.token) hash = v4().toUpperCase();
|
||||
@ -75,16 +77,16 @@ export class InstanceController {
|
||||
businessId: instanceData.businessId,
|
||||
});
|
||||
|
||||
instance.sendDataWebhook(Events.INSTANCE_CREATE, {
|
||||
instanceName: instanceData.instanceName,
|
||||
instanceId: instanceId,
|
||||
});
|
||||
|
||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
||||
this.waMonitor.delInstanceTime(instance.instanceName);
|
||||
|
||||
// set events
|
||||
eventController.setInstance(instance.instanceName, instanceData);
|
||||
await eventController.setInstance(instance.instanceName, instanceData);
|
||||
|
||||
instance.sendDataWebhook(Events.INSTANCE_CREATE, {
|
||||
instanceName: instanceData.instanceName,
|
||||
instanceId: instanceId,
|
||||
});
|
||||
|
||||
if (instanceData.proxyHost && instanceData.proxyPort && instanceData.proxyProtocol) {
|
||||
const testProxy = await this.proxyService.testProxy({
|
||||
|
@ -215,7 +215,13 @@ export class ChatwootService {
|
||||
|
||||
inboxId = inbox.id;
|
||||
}
|
||||
this.logger.log(`Inox created - inboxId: ${inboxId}`);
|
||||
this.logger.log(`Inbox created - inboxId: ${inboxId}`);
|
||||
|
||||
if (!this.configService.get<Chatwoot>('CHATWOOT').BOT_CONTACT) {
|
||||
this.logger.log('Chatwoot bot contact is disabled');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
this.logger.log('Creating chatwoot bot contact');
|
||||
const contact =
|
||||
@ -826,6 +832,12 @@ export class ChatwootService {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.configService.get<Chatwoot>('CHATWOOT').BOT_CONTACT) {
|
||||
this.logger.log('Chatwoot bot contact is disabled');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const contact = await this.findContact(instance, '123456');
|
||||
|
||||
if (!contact) {
|
||||
@ -940,6 +952,12 @@ export class ChatwootService {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.configService.get<Chatwoot>('CHATWOOT').BOT_CONTACT) {
|
||||
this.logger.log('Chatwoot bot contact is disabled');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const contact = await this.findContact(instance, '123456');
|
||||
|
||||
if (!contact) {
|
||||
@ -1159,7 +1177,9 @@ export class ChatwootService {
|
||||
return { message: 'bot' };
|
||||
}
|
||||
|
||||
if (chatId === '123456' && body.message_type === 'outgoing') {
|
||||
const cwBotContact = this.configService.get<Chatwoot>('CHATWOOT').BOT_CONTACT;
|
||||
|
||||
if (cwBotContact && chatId === '123456' && body.message_type === 'outgoing') {
|
||||
const command = messageReceived.replace('/', '');
|
||||
|
||||
if (command.includes('init') || command.includes('iniciar')) {
|
||||
|
@ -106,7 +106,7 @@ export class RabbitmqController extends EventController implements EventControll
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return null;
|
||||
throw new NotFoundException('Instance rabbitmq not found');
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -91,7 +91,7 @@ export class SqsController extends EventController implements EventControllerInt
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return null;
|
||||
throw new NotFoundException('Instance SQS not found');
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -63,7 +63,7 @@ export class WebhookController extends EventController implements EventControlle
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return null;
|
||||
throw new NotFoundException('Instance webhook not found');
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -102,7 +102,7 @@ export class WebsocketController extends EventController implements EventControl
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return null;
|
||||
throw new NotFoundException('Instance websocket not found');
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -58,11 +58,6 @@ export class ChannelStartupService {
|
||||
this.instance.token = instance.token;
|
||||
this.instance.businessId = instance.businessId;
|
||||
|
||||
this.sendDataWebhook(Events.STATUS_INSTANCE, {
|
||||
instance: this.instance.name,
|
||||
status: 'created',
|
||||
});
|
||||
|
||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||
this.chatwootService.eventWhatsapp(
|
||||
Events.STATUS_INSTANCE,
|
||||
|
@ -181,6 +181,7 @@ export type Chatwoot = {
|
||||
ENABLED: boolean;
|
||||
MESSAGE_DELETE: boolean;
|
||||
MESSAGE_READ: boolean;
|
||||
BOT_CONTACT: boolean;
|
||||
IMPORT: {
|
||||
DATABASE: {
|
||||
CONNECTION: {
|
||||
@ -426,6 +427,7 @@ export class ConfigService {
|
||||
ENABLED: process.env?.CHATWOOT_ENABLED === 'true',
|
||||
MESSAGE_DELETE: process.env.CHATWOOT_MESSAGE_DELETE === 'true',
|
||||
MESSAGE_READ: process.env.CHATWOOT_MESSAGE_READ === 'true',
|
||||
BOT_CONTACT: process.env.CHATWOOT_BOT_CONTACT === 'true',
|
||||
IMPORT: {
|
||||
DATABASE: {
|
||||
CONNECTION: {
|
||||
|
Loading…
Reference in New Issue
Block a user