mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-25 22:57:44 -06:00
feat: chatwoot integration completed
This commit is contained in:
@@ -4,6 +4,7 @@ import { InstanceDto } from '../dto/instance.dto';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
import { ChatwootService } from '../services/chatwoot.service';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { waMonitor } from '../whatsapp.module';
|
||||
|
||||
const logger = new Logger('ChatwootController');
|
||||
|
||||
@@ -27,6 +28,10 @@ export class ChatwootController {
|
||||
if (!data.token) {
|
||||
throw new BadRequestException('token is required');
|
||||
}
|
||||
|
||||
if (!data.sign_msg) {
|
||||
throw new BadRequestException('sign_msg is required');
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.enabled) {
|
||||
@@ -34,22 +39,39 @@ export class ChatwootController {
|
||||
data.account_id = '';
|
||||
data.token = '';
|
||||
data.url = '';
|
||||
data.sign_msg = false;
|
||||
}
|
||||
|
||||
data.name_inbox = instance.instanceName;
|
||||
|
||||
return this.chatwootService.create(instance, data);
|
||||
const result = this.chatwootService.create(instance, data);
|
||||
|
||||
const response = {
|
||||
...result,
|
||||
webhook_url: `/chatwoot/webhook/${instance.instanceName}`,
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public async findChatwoot(instance: InstanceDto) {
|
||||
logger.verbose('requested findChatwoot from ' + instance.instanceName + ' instance');
|
||||
return this.chatwootService.find(instance);
|
||||
const result = this.chatwootService.find(instance);
|
||||
|
||||
const response = {
|
||||
...result,
|
||||
webhook_url: `/chatwoot/webhook/${instance.instanceName}`,
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public async receiveWebhook(instance: InstanceDto, data: any) {
|
||||
logger.verbose(
|
||||
'requested receiveWebhook from ' + instance.instanceName + ' instance',
|
||||
);
|
||||
return this.chatwootService.receiveWebhook(instance, data);
|
||||
const chatwootService = new ChatwootService(waMonitor);
|
||||
|
||||
return chatwootService.receiveWebhook(instance, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ export class InstanceController {
|
||||
chatwoot_account_id,
|
||||
chatwoot_token,
|
||||
chatwoot_url,
|
||||
chatwoot_sign_msg,
|
||||
}: InstanceDto) {
|
||||
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
|
||||
|
||||
@@ -78,7 +79,12 @@ export class InstanceController {
|
||||
|
||||
this.logger.verbose('hash: ' + hash + ' generated');
|
||||
|
||||
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
||||
if (
|
||||
!chatwoot_account_id ||
|
||||
!chatwoot_token ||
|
||||
!chatwoot_url ||
|
||||
!chatwoot_sign_msg
|
||||
) {
|
||||
let getEvents: string[];
|
||||
|
||||
if (webhook) {
|
||||
@@ -131,12 +137,17 @@ export class InstanceController {
|
||||
throw new BadRequestException('url is required');
|
||||
}
|
||||
|
||||
if (!chatwoot_sign_msg) {
|
||||
throw new BadRequestException('sign_msg is required');
|
||||
}
|
||||
|
||||
try {
|
||||
this.chatwootService.create(instance, {
|
||||
enabled: true,
|
||||
account_id: chatwoot_account_id,
|
||||
token: chatwoot_token,
|
||||
url: chatwoot_url,
|
||||
sign_msg: chatwoot_sign_msg,
|
||||
name_inbox: instance.instanceName,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -154,7 +165,9 @@ export class InstanceController {
|
||||
account_id: chatwoot_account_id,
|
||||
token: chatwoot_token,
|
||||
url: chatwoot_url,
|
||||
sign_msg: chatwoot_sign_msg,
|
||||
name_inbox: instance.instanceName,
|
||||
webhook_url: `/chatwoot/webhook/${instance.instanceName}`,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
@@ -187,7 +200,12 @@ export class InstanceController {
|
||||
|
||||
this.logger.verbose('hash: ' + hash + ' generated');
|
||||
|
||||
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
|
||||
if (
|
||||
!chatwoot_account_id ||
|
||||
!chatwoot_token ||
|
||||
!chatwoot_url ||
|
||||
!chatwoot_sign_msg
|
||||
) {
|
||||
let getEvents: string[];
|
||||
|
||||
if (webhook) {
|
||||
@@ -253,12 +271,17 @@ export class InstanceController {
|
||||
throw new BadRequestException('url is required');
|
||||
}
|
||||
|
||||
if (!chatwoot_sign_msg) {
|
||||
throw new BadRequestException('sign_msg is required');
|
||||
}
|
||||
|
||||
try {
|
||||
this.chatwootService.create(instance, {
|
||||
enabled: true,
|
||||
account_id: chatwoot_account_id,
|
||||
token: chatwoot_token,
|
||||
url: chatwoot_url,
|
||||
sign_msg: chatwoot_sign_msg,
|
||||
name_inbox: instance.instanceName,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -276,7 +299,9 @@ export class InstanceController {
|
||||
account_id: chatwoot_account_id,
|
||||
token: chatwoot_token,
|
||||
url: chatwoot_url,
|
||||
sign_msg: chatwoot_sign_msg,
|
||||
name_inbox: instance.instanceName,
|
||||
webhook_url: `/chatwoot/webhook/${instance.instanceName}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user