mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
wip
This commit is contained in:
parent
0a851b935e
commit
dc3d59bae1
@ -4,7 +4,7 @@ module.exports = {
|
|||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
printWidth: 120,
|
printWidth: 120,
|
||||||
arrowParens: 'always',
|
arrowParens: 'always',
|
||||||
tabWidth: 4,
|
tabWidth: 2,
|
||||||
useTabs: false,
|
useTabs: false,
|
||||||
bracketSameLine: false,
|
bracketSameLine: false,
|
||||||
bracketSpacing: true,
|
bracketSpacing: true,
|
||||||
|
@ -104,10 +104,7 @@ export abstract class RouterBroker {
|
|||||||
const groupJid = request.query as unknown as GroupJid;
|
const groupJid = request.query as unknown as GroupJid;
|
||||||
|
|
||||||
if (!groupJid?.groupJid) {
|
if (!groupJid?.groupJid) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException('The group id needs to be informed in the query', 'ex: "groupJid=120362@g.us"');
|
||||||
'The group id needs to be informed in the query',
|
|
||||||
'ex: "groupJid=120362@g.us"',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = request.params as unknown as InstanceDto;
|
const instance = request.params as unknown as InstanceDto;
|
||||||
|
@ -39,9 +39,7 @@ export class SendMessageController {
|
|||||||
throw new BadRequestException('For base64 the file name must be informed.');
|
throw new BadRequestException('For base64 the file name must be informed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.verbose(
|
logger.verbose('isURL: ' + isURL(data?.mediaMessage?.media) + ', isBase64: ' + isBase64(data?.mediaMessage?.media));
|
||||||
'isURL: ' + isURL(data?.mediaMessage?.media) + ', isBase64: ' + isBase64(data?.mediaMessage?.media),
|
|
||||||
);
|
|
||||||
if (isURL(data?.mediaMessage?.media) || isBase64(data?.mediaMessage?.media)) {
|
if (isURL(data?.mediaMessage?.media) || isBase64(data?.mediaMessage?.media)) {
|
||||||
return await this.waMonitor.waInstances[instanceName].mediaMessage(data);
|
return await this.waMonitor.waInstances[instanceName].mediaMessage(data);
|
||||||
}
|
}
|
||||||
@ -63,9 +61,7 @@ export class SendMessageController {
|
|||||||
public async sendWhatsAppAudio({ instanceName }: InstanceDto, data: SendAudioDto) {
|
public async sendWhatsAppAudio({ instanceName }: InstanceDto, data: SendAudioDto) {
|
||||||
logger.verbose('requested sendWhatsAppAudio from ' + instanceName + ' instance');
|
logger.verbose('requested sendWhatsAppAudio from ' + instanceName + ' instance');
|
||||||
|
|
||||||
logger.verbose(
|
logger.verbose('isURL: ' + isURL(data?.audioMessage?.audio) + ', isBase64: ' + isBase64(data?.audioMessage?.audio));
|
||||||
'isURL: ' + isURL(data?.audioMessage?.audio) + ', isBase64: ' + isBase64(data?.audioMessage?.audio),
|
|
||||||
);
|
|
||||||
if (isURL(data.audioMessage.audio) || isBase64(data.audioMessage.audio)) {
|
if (isURL(data.audioMessage.audio) || isBase64(data.audioMessage.audio)) {
|
||||||
return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data);
|
return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data);
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,7 @@ async function jwtGuard(req: Request, res: Response, next: NextFunction) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if ((req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) && !key) {
|
||||||
(req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) &&
|
|
||||||
!key
|
|
||||||
) {
|
|
||||||
throw new ForbiddenException('Missing global api key', 'The global api key must be set');
|
throw new ForbiddenException('Missing global api key', 'The global api key must be set');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,10 +63,7 @@ async function apikey(req: Request, res: Response, next: NextFunction) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if ((req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) && !key) {
|
||||||
(req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) &&
|
|
||||||
!key
|
|
||||||
) {
|
|
||||||
throw new ForbiddenException('Missing global api key', 'The global api key must be set');
|
throw new ForbiddenException('Missing global api key', 'The global api key must be set');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ export class ChatwootRepository extends Repository {
|
|||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.verbose(
|
this.logger.verbose('chatwoot saved to store in path: ' + join(this.storePath, 'chatwoot') + '/' + instance);
|
||||||
'chatwoot saved to store in path: ' + join(this.storePath, 'chatwoot') + '/' + instance,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.logger.verbose('chatwoot created');
|
this.logger.verbose('chatwoot created');
|
||||||
return { insertCount: 1 };
|
return { insertCount: 1 };
|
||||||
|
@ -48,10 +48,7 @@ export class ContactRepository extends Repository {
|
|||||||
data: contact,
|
data: contact,
|
||||||
});
|
});
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
'contacts saved to store in path: ' +
|
'contacts saved to store in path: ' + join(this.storePath, 'contacts', instanceName) + '/' + contact.id,
|
||||||
join(this.storePath, 'contacts', instanceName) +
|
|
||||||
'/' +
|
|
||||||
contact.id,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -109,10 +106,7 @@ export class ContactRepository extends Repository {
|
|||||||
data: contact,
|
data: contact,
|
||||||
});
|
});
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
'contacts updated in store in path: ' +
|
'contacts updated in store in path: ' + join(this.storePath, 'contacts', instanceName) + '/' + contact.id,
|
||||||
join(this.storePath, 'contacts', instanceName) +
|
|
||||||
'/' +
|
|
||||||
contact.id,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -68,10 +68,7 @@ export class MessageRepository extends Repository {
|
|||||||
data: message,
|
data: message,
|
||||||
});
|
});
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
'messages saved to store in path: ' +
|
'messages saved to store in path: ' + join(this.storePath, 'messages', instanceName) + '/' + message.key.id,
|
||||||
join(this.storePath, 'messages', instanceName) +
|
|
||||||
'/' +
|
|
||||||
message.key.id,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -113,10 +110,9 @@ export class MessageRepository extends Repository {
|
|||||||
this.logger.verbose('finding messages in store by id');
|
this.logger.verbose('finding messages in store by id');
|
||||||
messages.push(
|
messages.push(
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
readFileSync(
|
readFileSync(join(this.storePath, 'messages', query.where.owner, query.where.key.id + '.json'), {
|
||||||
join(this.storePath, 'messages', query.where.owner, query.where.key.id + '.json'),
|
encoding: 'utf-8',
|
||||||
{ encoding: 'utf-8' },
|
}),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -48,10 +48,7 @@ export class MessageUpRepository extends Repository {
|
|||||||
data: update,
|
data: update,
|
||||||
});
|
});
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
'message up saved to store in path: ' +
|
'message up saved to store in path: ' + join(this.storePath, 'message-up', instanceName) + '/' + update.id,
|
||||||
join(this.storePath, 'message-up', instanceName) +
|
|
||||||
'/' +
|
|
||||||
update.id,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ export class SettingsRepository extends Repository {
|
|||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.verbose(
|
this.logger.verbose('settings saved to store in path: ' + join(this.storePath, 'settings') + '/' + instance);
|
||||||
'settings saved to store in path: ' + join(this.storePath, 'settings') + '/' + instance,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.logger.verbose('settings created');
|
this.logger.verbose('settings created');
|
||||||
return { insertCount: 1 };
|
return { insertCount: 1 };
|
||||||
|
@ -167,9 +167,7 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({ error: true, message: 'Database is not enabled' });
|
||||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
||||||
.json({ error: true, message: 'Database is not enabled' });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,9 +507,7 @@ export class ChatwootService {
|
|||||||
if (contactConversations) {
|
if (contactConversations) {
|
||||||
let conversation: any;
|
let conversation: any;
|
||||||
if (this.provider.reopen_conversation) {
|
if (this.provider.reopen_conversation) {
|
||||||
conversation = contactConversations.payload.find(
|
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
|
||||||
(conversation) => conversation.inbox_id == filterInbox.id,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
conversation = contactConversations.payload.find(
|
conversation = contactConversations.payload.find(
|
||||||
(conversation) => conversation.status !== 'resolved' && conversation.inbox_id == filterInbox.id,
|
(conversation) => conversation.status !== 'resolved' && conversation.inbox_id == filterInbox.id,
|
||||||
@ -937,8 +935,7 @@ export class ChatwootService {
|
|||||||
|
|
||||||
this.logger.verbose('check if is group');
|
this.logger.verbose('check if is group');
|
||||||
const chatId =
|
const chatId =
|
||||||
body.conversation.meta.sender?.phone_number?.replace('+', '') ||
|
body.conversation.meta.sender?.phone_number?.replace('+', '') || body.conversation.meta.sender?.identifier;
|
||||||
body.conversation.meta.sender?.identifier;
|
|
||||||
const messageReceived = body.content;
|
const messageReceived = body.content;
|
||||||
const senderName = body?.sender?.name;
|
const senderName = body?.sender?.name;
|
||||||
const waInstance = this.waMonitor.waInstances[instance.instanceName];
|
const waInstance = this.waMonitor.waInstances[instance.instanceName];
|
||||||
@ -958,11 +955,7 @@ export class ChatwootService {
|
|||||||
await waInstance.connectToWhatsapp(number);
|
await waInstance.connectToWhatsapp(number);
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose('whatsapp already connected');
|
this.logger.verbose('whatsapp already connected');
|
||||||
await this.createBotMessage(
|
await this.createBotMessage(instance, `🚨 ${body.inbox.name} instance is connected.`, 'incoming');
|
||||||
instance,
|
|
||||||
`🚨 ${body.inbox.name} instance is connected.`,
|
|
||||||
'incoming',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,11 +971,7 @@ export class ChatwootService {
|
|||||||
|
|
||||||
if (state) {
|
if (state) {
|
||||||
this.logger.verbose('state: ' + state + ' found');
|
this.logger.verbose('state: ' + state + ' found');
|
||||||
await this.createBotMessage(
|
await this.createBotMessage(instance, `⚠️ ${body.inbox.name} instance status: *${state}*`, 'incoming');
|
||||||
instance,
|
|
||||||
`⚠️ ${body.inbox.name} instance status: *${state}*`,
|
|
||||||
'incoming',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1356,12 +1345,7 @@ export class ChatwootService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageCacheFile = path.join(
|
this.messageCacheFile = path.join(ROOT_DIR, 'store', 'chatwoot', `${instance.instanceName}_cache.txt`);
|
||||||
ROOT_DIR,
|
|
||||||
'store',
|
|
||||||
'chatwoot',
|
|
||||||
`${instance.instanceName}_cache.txt`,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.messageCache = this.loadMessageCache();
|
this.messageCache = this.loadMessageCache();
|
||||||
|
|
||||||
@ -1382,12 +1366,7 @@ export class ChatwootService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageCacheFile = path.join(
|
this.messageCacheFile = path.join(ROOT_DIR, 'store', 'chatwoot', `${instance.instanceName}_cache.txt`);
|
||||||
ROOT_DIR,
|
|
||||||
'store',
|
|
||||||
'chatwoot',
|
|
||||||
`${instance.instanceName}_cache.txt`,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.messageCache = this.loadMessageCache();
|
this.messageCache = this.loadMessageCache();
|
||||||
|
|
||||||
@ -1423,12 +1402,7 @@ export class ChatwootService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageCacheFile = path.join(
|
this.messageCacheFile = path.join(ROOT_DIR, 'store', 'chatwoot', `${instance.instanceName}_cache.txt`);
|
||||||
ROOT_DIR,
|
|
||||||
'store',
|
|
||||||
'chatwoot',
|
|
||||||
`${instance.instanceName}_cache.txt`,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.messageCache = this.loadMessageCache();
|
this.messageCache = this.loadMessageCache();
|
||||||
|
|
||||||
@ -1449,12 +1423,7 @@ export class ChatwootService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageCacheFile = path.join(
|
this.messageCacheFile = path.join(ROOT_DIR, 'store', 'chatwoot', `${instance.instanceName}_cache.txt`);
|
||||||
ROOT_DIR,
|
|
||||||
'store',
|
|
||||||
'chatwoot',
|
|
||||||
`${instance.instanceName}_cache.txt`,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.messageCache = this.loadMessageCache();
|
this.messageCache = this.loadMessageCache();
|
||||||
|
|
||||||
@ -1521,10 +1490,10 @@ export class ChatwootService {
|
|||||||
if (body?.qrcode?.pairingCode) {
|
if (body?.qrcode?.pairingCode) {
|
||||||
msgQrCode =
|
msgQrCode =
|
||||||
msgQrCode +
|
msgQrCode +
|
||||||
`\n\n*Pairing Code:* ${body.qrcode.pairingCode.substring(
|
`\n\n*Pairing Code:* ${body.qrcode.pairingCode.substring(0, 4)}-${body.qrcode.pairingCode.substring(
|
||||||
0,
|
|
||||||
4,
|
4,
|
||||||
)}-${body.qrcode.pairingCode.substring(4, 8)}`;
|
8,
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('send message to chatwoot');
|
this.logger.verbose('send message to chatwoot');
|
||||||
|
@ -787,18 +787,10 @@ export class WAStartupService {
|
|||||||
for (const [key, value] of Object.entries(cleanStore)) {
|
for (const [key, value] of Object.entries(cleanStore)) {
|
||||||
if (value === true) {
|
if (value === true) {
|
||||||
execSync(
|
execSync(
|
||||||
`rm -rf ${join(
|
`rm -rf ${join(this.storePath, key.toLowerCase().replace('_', '-'), this.instance.name)}/*.json`,
|
||||||
this.storePath,
|
|
||||||
key.toLowerCase().replace('_', '-'),
|
|
||||||
this.instance.name,
|
|
||||||
)}/*.json`,
|
|
||||||
);
|
);
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
`Cleaned ${join(
|
`Cleaned ${join(this.storePath, key.toLowerCase().replace('_', '-'), this.instance.name)}/*.json`,
|
||||||
this.storePath,
|
|
||||||
key.toLowerCase().replace('_', '-'),
|
|
||||||
this.instance.name,
|
|
||||||
)}/*.json`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1271,11 +1263,7 @@ export class WAStartupService {
|
|||||||
await this.sendDataWebhook(Events.MESSAGES_UPDATE, message);
|
await this.sendDataWebhook(Events.MESSAGES_UPDATE, message);
|
||||||
|
|
||||||
this.logger.verbose('Inserting message in database');
|
this.logger.verbose('Inserting message in database');
|
||||||
await this.repository.messageUpdate.insert(
|
await this.repository.messageUpdate.insert([message], this.instance.name, database.SAVE_DATA.MESSAGE_UPDATE);
|
||||||
[message],
|
|
||||||
this.instance.name,
|
|
||||||
database.SAVE_DATA.MESSAGE_UPDATE,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2271,8 +2259,7 @@ export class WAStartupService {
|
|||||||
contact.wuid = this.createJid(contact.phoneNumber);
|
contact.wuid = this.createJid(contact.phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
result +=
|
result += `item1.TEL;waid=${contact.wuid}:${contact.phoneNumber}\n` + 'item1.X-ABLabel:Celular\n' + 'END:VCARD';
|
||||||
`item1.TEL;waid=${contact.wuid}:${contact.phoneNumber}\n` + 'item1.X-ABLabel:Celular\n' + 'END:VCARD';
|
|
||||||
|
|
||||||
this.logger.verbose('Vcard created');
|
this.logger.verbose('Vcard created');
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user