mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-15 19:52:54 -06:00
fix: command to create new instances set to /new_instance:<NAME>:<NUMBER>
This commit is contained in:
parent
7103a95305
commit
fff420b652
@ -16,6 +16,7 @@
|
|||||||
* Fixed issue where it was not possible to open a conversation when sent at first by me on my cell phone in chatwoot
|
* Fixed issue where it was not possible to open a conversation when sent at first by me on my cell phone in chatwoot
|
||||||
* Now it only updates the contact name if it is the same as the phone number in chatwoot
|
* Now it only updates the contact name if it is the same as the phone number in chatwoot
|
||||||
* Now accepts all chatwoot inbox templates
|
* Now accepts all chatwoot inbox templates
|
||||||
|
* Command to create new instances set to /new_instance:<NAME>:<NUMBER>
|
||||||
|
|
||||||
### Integrations
|
### Integrations
|
||||||
|
|
||||||
|
@ -94,4 +94,10 @@ export class ChatwootController {
|
|||||||
|
|
||||||
return chatwootService.receiveWebhook(instance, data);
|
return chatwootService.receiveWebhook(instance, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async newInstance(data: any) {
|
||||||
|
const chatwootService = new ChatwootService(waMonitor, this.configService);
|
||||||
|
|
||||||
|
return chatwootService.newInstance(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import { SendAudioDto } from '../dto/sendMessage.dto';
|
|||||||
import { SendMediaDto } from '../dto/sendMessage.dto';
|
import { SendMediaDto } from '../dto/sendMessage.dto';
|
||||||
import { ROOT_DIR } from '../../config/path.config';
|
import { ROOT_DIR } from '../../config/path.config';
|
||||||
import { ConfigService, HttpServer } from '../../config/env.config';
|
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||||
import { delay } from '@whiskeysockets/baileys';
|
|
||||||
|
|
||||||
export class ChatwootService {
|
export class ChatwootService {
|
||||||
private messageCacheFile: string;
|
private messageCacheFile: string;
|
||||||
@ -1017,7 +1016,7 @@ export class ChatwootService {
|
|||||||
await waInstance?.client?.ws?.close();
|
await waInstance?.client?.ws?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.includes('#inbox_whatsapp')) {
|
if (command.includes('new_instance')) {
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
||||||
|
|
||||||
@ -1030,6 +1029,10 @@ export class ChatwootService {
|
|||||||
chatwoot_sign_msg: this.provider.sign_msg,
|
chatwoot_sign_msg: this.provider.sign_msg,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (command.split(':')[2]) {
|
||||||
|
data['number'] = command.split(':')[2];
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
maxBodyLength: Infinity,
|
maxBodyLength: Infinity,
|
||||||
@ -1585,4 +1588,53 @@ export class ChatwootService {
|
|||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async newInstance(data: any) {
|
||||||
|
try {
|
||||||
|
const instanceName = data.instanceName;
|
||||||
|
const qrcode = true;
|
||||||
|
const number = data.number;
|
||||||
|
const accountId = data.accountId;
|
||||||
|
const chatwootToken = data.token;
|
||||||
|
const chatwootUrl = data.url;
|
||||||
|
const signMsg = true;
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
||||||
|
|
||||||
|
console.log('data: ', data);
|
||||||
|
|
||||||
|
const requestData = {
|
||||||
|
instanceName,
|
||||||
|
qrcode,
|
||||||
|
chatwoot_account_id: accountId,
|
||||||
|
chatwoot_token: chatwootToken,
|
||||||
|
chatwoot_url: chatwootUrl,
|
||||||
|
chatwoot_sign_msg: signMsg,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (number) {
|
||||||
|
requestData['number'] = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('requestData: ', requestData);
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
method: 'post',
|
||||||
|
maxBodyLength: Infinity,
|
||||||
|
url: `${urlServer}/instance/create`,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
apikey: apiKey,
|
||||||
|
},
|
||||||
|
data: requestData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// await axios.request(config);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user