mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
feat: Created automation for creating instances in the chatwoot bot with the command #inbox_whatsapp:<INSTANCE_NAME>
This commit is contained in:
parent
71a3e75ae2
commit
0cb87e6ed9
@ -4,6 +4,7 @@
|
||||
|
||||
* Added messages.delete event
|
||||
* Added restart instance endpoint
|
||||
* Created automation for creating instances in the chatwoot bot with the command #inbox_whatsapp:<INSTANCE_NAME>
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -90,7 +90,7 @@ export class ChatwootController {
|
||||
logger.verbose(
|
||||
'requested receiveWebhook from ' + instance.instanceName + ' instance',
|
||||
);
|
||||
const chatwootService = new ChatwootService(waMonitor);
|
||||
const chatwootService = new ChatwootService(waMonitor, this.configService);
|
||||
|
||||
return chatwootService.receiveWebhook(instance, data);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import mimeTypes from 'mime-types';
|
||||
import { SendAudioDto } from '../dto/sendMessage.dto';
|
||||
import { SendMediaDto } from '../dto/sendMessage.dto';
|
||||
import { ROOT_DIR } from '../../config/path.config';
|
||||
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||
|
||||
export class ChatwootService {
|
||||
private messageCacheFile: string;
|
||||
@ -21,7 +22,10 @@ export class ChatwootService {
|
||||
|
||||
private provider: any;
|
||||
|
||||
constructor(private readonly waMonitor: WAMonitoringService) {
|
||||
constructor(
|
||||
private readonly waMonitor: WAMonitoringService,
|
||||
private readonly configService: ConfigService,
|
||||
) {
|
||||
this.messageCache = new Set();
|
||||
}
|
||||
|
||||
@ -981,6 +985,39 @@ export class ChatwootService {
|
||||
await waInstance?.client?.logout('Log out instance: ' + instance.instanceName);
|
||||
await waInstance?.client?.ws?.close();
|
||||
}
|
||||
|
||||
if (command.includes('#inbox_whatsapp')) {
|
||||
console.log('command include #inbox_whatsapp');
|
||||
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
||||
|
||||
console.log('url server: ' + urlServer);
|
||||
console.log('api key: ' + apiKey);
|
||||
const data = {
|
||||
instanceName: command.split(':')[1],
|
||||
qrcode: true,
|
||||
chatwoot_account_id: this.provider.account_id,
|
||||
chatwoot_token: this.provider.token,
|
||||
chatwoot_url: this.provider.url,
|
||||
chatwoot_sign_msg: this.provider.sign_msg,
|
||||
};
|
||||
|
||||
const config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: `${urlServer}/instance/create`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
apikey: apiKey,
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
|
||||
const { data: response } = await axios.request(config);
|
||||
|
||||
console.log(response);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -149,7 +149,7 @@ export class WAStartupService {
|
||||
private endSession = false;
|
||||
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
|
||||
|
||||
private chatwootService = new ChatwootService(waMonitor);
|
||||
private chatwootService = new ChatwootService(waMonitor, this.configService);
|
||||
|
||||
public set instanceName(name: string) {
|
||||
this.logger.verbose(`Initializing instance '${name}'`);
|
||||
|
@ -72,7 +72,7 @@ const webhookService = new WebhookService(waMonitor);
|
||||
|
||||
export const webhookController = new WebhookController(webhookService);
|
||||
|
||||
const chatwootService = new ChatwootService(waMonitor);
|
||||
const chatwootService = new ChatwootService(waMonitor, configService);
|
||||
|
||||
export const chatwootController = new ChatwootController(chatwootService, configService);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user