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