fix: fixed bugs in the frontend, on the event screens

This commit is contained in:
Davidson Gomes 2024-09-03 13:09:42 -03:00
parent 5f86f01e3a
commit acd4100b23
9 changed files with 504 additions and 437 deletions

View File

@ -3,10 +3,13 @@
### Features
* Define a global proxy to be used if the instance does not have one
* Save is on whatsapp on the database
### Fixed
* Validate if cache exists before accessing it
* Missing autoCreate chatwoot in instance create
* Fixed bugs in the frontend, on the event screens
# 2.1.0 (2024-08-26 15:33)

381
manager/dist/assets/index-7AslllZb.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<link rel="icon" type="image/png" href="/assets/images/evolution-logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Evolution Manager</title>
<script type="module" crossorigin src="/assets/index-efsrmrux.js"></script>
<script type="module" crossorigin src="/assets/index-7AslllZb.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DNOCacL_.css">
</head>
<body>

View File

@ -1,6 +1,6 @@
{
"name": "evolution-api",
"version": "2.1.0",
"version": "2.1.1",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/main.js",
"type": "commonjs",

View File

@ -159,48 +159,10 @@ export class EvolutionStartupService extends ChannelStartupService {
data: messageRaw,
});
const contact = await this.prismaRepository.contact.findFirst({
where: { instanceId: this.instanceId, remoteJid: key.remoteJid },
});
const contactRaw: any = {
await this.updateContact({
remoteJid: messageRaw.key.remoteJid,
pushName: received.pushName,
instanceId: this.instanceId,
};
if (contactRaw.remoteJid === 'status@broadcast') {
return;
}
if (contact) {
const contactRaw: any = {
remoteJid: messageRaw.key.remoteJid,
pushName: received.pushName,
instanceId: this.instanceId,
};
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
await this.chatwootService.eventWhatsapp(
Events.CONTACTS_UPDATE,
{ instanceName: this.instance.name, instanceId: this.instanceId },
contactRaw,
);
}
await this.prismaRepository.contact.updateMany({
where: { remoteJid: contact.remoteJid },
data: contactRaw,
});
return;
}
this.sendDataWebhook(Events.CONTACTS_UPSERT, contactRaw);
this.prismaRepository.contact.create({
data: contactRaw,
pushName: messageRaw.pushName,
profilePicUrl: null,
});
}
} catch (error) {
@ -208,6 +170,79 @@ export class EvolutionStartupService extends ChannelStartupService {
}
}
private async updateContact(data: { remoteJid: string; pushName?: string; profilePicUrl?: string }) {
const contact = await this.prismaRepository.contact.findFirst({
where: { instanceId: this.instanceId, remoteJid: data.remoteJid },
});
if (contact) {
const contactRaw: any = {
remoteJid: data.remoteJid,
pushName: data?.pushName,
instanceId: this.instanceId,
profilePicUrl: data?.profilePicUrl,
};
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
await this.chatwootService.eventWhatsapp(
Events.CONTACTS_UPDATE,
{ instanceName: this.instance.name, instanceId: this.instanceId },
contactRaw,
);
}
await this.prismaRepository.contact.updateMany({
where: { remoteJid: contact.remoteJid },
data: contactRaw,
});
return;
}
const contactRaw: any = {
remoteJid: data.remoteJid,
pushName: data?.pushName,
instanceId: this.instanceId,
profilePicUrl: data?.profilePicUrl,
};
this.sendDataWebhook(Events.CONTACTS_UPSERT, contactRaw);
await this.prismaRepository.contact.create({
data: contactRaw,
});
const chat = await this.prismaRepository.chat.findFirst({
where: { instanceId: this.instanceId, remoteJid: data.remoteJid },
});
if (chat) {
const chatRaw: any = {
remoteJid: data.remoteJid,
instanceId: this.instanceId,
};
this.sendDataWebhook(Events.CHATS_UPDATE, chatRaw);
await this.prismaRepository.chat.updateMany({
where: { remoteJid: chat.remoteJid },
data: chatRaw,
});
}
const chatRaw: any = {
remoteJid: data.remoteJid,
instanceId: this.instanceId,
};
this.sendDataWebhook(Events.CHATS_UPSERT, chatRaw);
await this.prismaRepository.chat.create({
data: chatRaw,
});
}
protected async sendMessageWithTyping(number: string, message: any, options?: Options, isIntegration = false) {
try {
let quoted: any;
@ -225,12 +260,16 @@ export class EvolutionStartupService extends ChannelStartupService {
quoted = msg;
}
if (options.delay) {
await new Promise((resolve) => setTimeout(resolve, options.delay));
}
if (options?.webhookUrl) {
webhookUrl = options.webhookUrl;
}
const messageRaw: any = {
key: { fromMe: true, id: 'ID', remoteJid: this.createJid(number) },
key: { fromMe: true, id: 'ID', remoteJid: number },
message: {
...message,
quoted,

View File

@ -1130,6 +1130,11 @@ export class BaileysStartupService extends ChannelStartupService {
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
await this.prismaRepository.message.update({
where: { id: msg.id },
data: messageRaw,
});
} catch (error) {
this.logger.error('line 1181');
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
@ -2034,6 +2039,11 @@ export class BaileysStartupService extends ChannelStartupService {
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
await this.prismaRepository.message.update({
where: { id: msg.id },
data: messageRaw,
});
} catch (error) {
this.logger.error('line 1181');
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);

View File

@ -36,5 +36,6 @@ export function ChatwootInstanceMixin<TBase extends Constructor>(Base: TBase) {
chatwootNameInbox?: string;
chatwootOrganization?: string;
chatwootLogo?: string;
chatwootAutoCreate?: boolean;
};
}

View File

@ -527,12 +527,6 @@ export class ChannelStartupService {
participants?: string;
};
const remoteJid = keyFilters?.remoteJid
? keyFilters?.remoteJid.includes('@')
? keyFilters?.remoteJid
: this.createJid(keyFilters?.remoteJid)
: null;
const count = await this.prismaRepository.message.count({
where: {
instanceId: this.instanceId,
@ -542,7 +536,7 @@ export class ChannelStartupService {
AND: [
keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {},
keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {},
remoteJid ? { key: { path: ['remoteJid'], equals: remoteJid } } : {},
keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {},
keyFilters?.participants ? { key: { path: ['participants'], equals: keyFilters?.participants } } : {},
],
},
@ -565,7 +559,7 @@ export class ChannelStartupService {
AND: [
keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {},
keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {},
remoteJid ? { key: { path: ['remoteJid'], equals: remoteJid } } : {},
keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {},
keyFilters?.participants ? { key: { path: ['participants'], equals: keyFilters?.participants } } : {},
],
},
@ -623,7 +617,7 @@ export class ChannelStartupService {
let result;
if (remoteJid) {
result = await this.prismaRepository.$queryRaw`
SELECT
SELECT
"Chat"."id",
"Chat"."remoteJid",
"Chat"."name",
@ -633,14 +627,24 @@ export class ChannelStartupService {
"Contact"."pushName",
"Contact"."profilePicUrl"
FROM "Chat"
INNER JOIN "Message" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid'
LEFT JOIN "Contact" ON "Chat"."remoteJid" = "Contact"."remoteJid"
WHERE "Chat"."instanceId" = ${this.instanceId}
AND "Chat"."remoteJid" = ${remoteJid}
ORDER BY "Chat"."updatedAt" DESC
GROUP BY
"Chat"."id",
"Chat"."remoteJid",
"Chat"."name",
"Chat"."labels",
"Chat"."createdAt",
"Chat"."updatedAt",
"Contact"."pushName",
"Contact"."profilePicUrl"
ORDER BY "Chat"."updatedAt" DESC;
`;
} else {
result = await this.prismaRepository.$queryRaw`
SELECT
SELECT
"Chat"."id",
"Chat"."remoteJid",
"Chat"."name",
@ -650,9 +654,19 @@ export class ChannelStartupService {
"Contact"."pushName",
"Contact"."profilePicUrl"
FROM "Chat"
INNER JOIN "Message" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid'
LEFT JOIN "Contact" ON "Chat"."remoteJid" = "Contact"."remoteJid"
WHERE "Chat"."instanceId" = ${this.instanceId}
ORDER BY "Chat"."updatedAt" DESC
GROUP BY
"Chat"."id",
"Chat"."remoteJid",
"Chat"."name",
"Chat"."labels",
"Chat"."createdAt",
"Chat"."updatedAt",
"Contact"."pushName",
"Contact"."profilePicUrl"
ORDER BY "Chat"."updatedAt" DESC;
`;
}