Skip to content

Commit 2198a86

Browse files
committed
Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop
2 parents 8a54efe + 4fadf64 commit 2198a86

File tree

11 files changed

+441
-89
lines changed

11 files changed

+441
-89
lines changed

package-lock.json

Lines changed: 86 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Chat` will be added. If there are existing duplicate values, this will fail.
5+
*/
6+
7+
-- AlterTable
8+
ALTER TABLE `Setting`
9+
ADD COLUMN IF NOT EXISTS `wavoipToken` VARCHAR(100);
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to alter the column `createdAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
5+
- You are about to alter the column `updatedAt` on the `Chat` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
6+
- You are about to alter the column `createdAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
7+
- You are about to alter the column `updatedAt` on the `Chatwoot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
8+
- You are about to alter the column `createdAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
9+
- You are about to alter the column `updatedAt` on the `Contact` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
10+
- You are about to alter the column `createdAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
11+
- You are about to alter the column `updatedAt` on the `Dify` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
12+
- You are about to alter the column `createdAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
13+
- You are about to alter the column `updatedAt` on the `DifySetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
14+
- You are about to alter the column `createdAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
15+
- You are about to alter the column `updatedAt` on the `EvolutionBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
16+
- You are about to alter the column `createdAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
17+
- You are about to alter the column `updatedAt` on the `EvolutionBotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
18+
- You are about to alter the column `createdAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
19+
- You are about to alter the column `updatedAt` on the `Flowise` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
20+
- You are about to alter the column `createdAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
21+
- You are about to alter the column `updatedAt` on the `FlowiseSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
22+
- You are about to alter the column `disconnectionAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
23+
- You are about to alter the column `createdAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
24+
- You are about to alter the column `updatedAt` on the `Instance` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
25+
- You are about to alter the column `createdAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
26+
- You are about to alter the column `updatedAt` on the `IntegrationSession` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
27+
- You are about to alter the column `createdAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
28+
- You are about to alter the column `updatedAt` on the `IsOnWhatsapp` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
29+
- You are about to alter the column `createdAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
30+
- You are about to alter the column `updatedAt` on the `Label` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
31+
- You are about to alter the column `createdAt` on the `Media` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
32+
- You are about to alter the column `createdAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
33+
- You are about to alter the column `updatedAt` on the `OpenaiBot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
34+
- You are about to alter the column `createdAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
35+
- You are about to alter the column `updatedAt` on the `OpenaiCreds` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
36+
- You are about to alter the column `createdAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
37+
- You are about to alter the column `updatedAt` on the `OpenaiSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
38+
- You are about to alter the column `createdAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
39+
- You are about to alter the column `updatedAt` on the `Proxy` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
40+
- You are about to alter the column `createdAt` on the `Pusher` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
41+
- You are about to alter the column `updatedAt` on the `Pusher` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
42+
- You are about to alter the column `createdAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
43+
- You are about to alter the column `updatedAt` on the `Rabbitmq` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
44+
- You are about to alter the column `createdAt` on the `Session` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
45+
- You are about to alter the column `createdAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
46+
- You are about to alter the column `updatedAt` on the `Setting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
47+
- You are about to alter the column `createdAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
48+
- You are about to alter the column `updatedAt` on the `Sqs` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
49+
- You are about to alter the column `createdAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
50+
- You are about to alter the column `updatedAt` on the `Template` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
51+
- You are about to alter the column `createdAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
52+
- You are about to alter the column `updatedAt` on the `Typebot` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
53+
- You are about to alter the column `createdAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
54+
- You are about to alter the column `updatedAt` on the `TypebotSetting` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
55+
- You are about to alter the column `createdAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
56+
- You are about to alter the column `updatedAt` on the `Webhook` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
57+
- You are about to alter the column `createdAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
58+
- You are about to alter the column `updatedAt` on the `Websocket` table. The data in that column could be lost. The data in that column will be cast from `Timestamp(0)` to `Timestamp`.
59+
- A unique constraint covering the columns `[instanceId,remoteJid]` on the table `Chat` will be added. If there are existing duplicate values, this will fail.
60+
61+
*/
62+
-- AlterTable
63+
ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
64+
MODIFY `updatedAt` TIMESTAMP NULL;
65+
66+
-- AlterTable
67+
ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
68+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
69+
70+
-- AlterTable
71+
ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
72+
MODIFY `updatedAt` TIMESTAMP NULL;
73+
74+
-- AlterTable
75+
ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
76+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
77+
78+
-- AlterTable
79+
ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
80+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
81+
82+
-- AlterTable
83+
ALTER TABLE `EvolutionBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
84+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
85+
86+
-- AlterTable
87+
ALTER TABLE `EvolutionBotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
88+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
89+
90+
-- AlterTable
91+
ALTER TABLE `Flowise` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
92+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
93+
94+
-- AlterTable
95+
ALTER TABLE `FlowiseSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
96+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
97+
98+
-- AlterTable
99+
ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL,
100+
MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
101+
MODIFY `updatedAt` TIMESTAMP NULL;
102+
103+
-- AlterTable
104+
ALTER TABLE `IntegrationSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
105+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
106+
107+
-- AlterTable
108+
ALTER TABLE `IsOnWhatsapp` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
109+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
110+
111+
-- AlterTable
112+
ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
113+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
114+
115+
-- AlterTable
116+
ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;
117+
118+
-- AlterTable
119+
ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
120+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
121+
122+
-- AlterTable
123+
ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
124+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
125+
126+
-- AlterTable
127+
ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
128+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
129+
130+
-- AlterTable
131+
ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
132+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
133+
134+
-- AlterTable
135+
ALTER TABLE `Pusher` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
136+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
137+
138+
-- AlterTable
139+
ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
140+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
141+
142+
-- AlterTable
143+
ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
144+
145+
-- AlterTable
146+
ALTER TABLE `Setting` ADD COLUMN `wavoipToken` VARCHAR(100) NULL,
147+
MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
148+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
149+
150+
-- AlterTable
151+
ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
152+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
153+
154+
-- AlterTable
155+
ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
156+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
157+
158+
-- AlterTable
159+
ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
160+
MODIFY `updatedAt` TIMESTAMP NULL;
161+
162+
-- AlterTable
163+
ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
164+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
165+
166+
-- AlterTable
167+
ALTER TABLE `Webhook` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
168+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
169+
170+
-- AlterTable
171+
ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
172+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
173+
174+
-- CreateIndex
175+
CREATE UNIQUE INDEX `Chat_instanceId_remoteJid_key` ON `Chat`(`instanceId`, `remoteJid`);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
2-
# It should be added in your version-control system (i.e. Git)
2+
# It should be added in your version-control system (e.g., Git)
33
provider = "mysql"

src/api/controllers/sendMessage.controller.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ import { WAMonitoringService } from '@api/services/monitor.service';
1818
import { BadRequestException } from '@exceptions';
1919
import { isBase64, isURL } from 'class-validator';
2020

21+
function isEmoji(str: string) {
22+
if (str === '') return true;
23+
24+
const emojiRegex =
25+
/^[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F000}-\u{1F02F}\u{1F0A0}-\u{1F0FF}\u{1F100}-\u{1F64F}\u{1F680}-\u{1F6FF}]$/u;
26+
return emojiRegex.test(str);
27+
}
28+
2129
export class SendMessageController {
2230
constructor(private readonly waMonitor: WAMonitoringService) {}
2331

@@ -81,8 +89,8 @@ export class SendMessageController {
8189
}
8290

8391
public async sendReaction({ instanceName }: InstanceDto, data: SendReactionDto) {
84-
if (!data.reaction.match(/[^()\w\sà-ú"-+]+/)) {
85-
throw new BadRequestException('"reaction" must be an emoji');
92+
if (!isEmoji(data.reaction)) {
93+
throw new BadRequestException('Reaction must be a single emoji or empty string');
8694
}
8795
return await this.waMonitor.waInstances[instanceName].reactionMessage(data);
8896
}

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,27 @@ export class BaileysStartupService extends ChannelStartupService {
11451145
);
11461146

11471147
await this.sendDataWebhook(Events.MESSAGES_EDITED, editedMessage);
1148+
const oldMessage = await this.getMessage(editedMessage.key, true);
1149+
if ((oldMessage as any)?.id) {
1150+
await this.prismaRepository.message.update({
1151+
where: { id: (oldMessage as any).id },
1152+
data: {
1153+
message: editedMessage.editedMessage as any,
1154+
messageTimestamp: (editedMessage.timestampMs as Long.Long).toNumber(),
1155+
status: 'EDITED',
1156+
},
1157+
});
1158+
await this.prismaRepository.messageUpdate.create({
1159+
data: {
1160+
fromMe: editedMessage.key.fromMe,
1161+
keyId: editedMessage.key.id,
1162+
remoteJid: editedMessage.key.remoteJid,
1163+
status: 'EDITED',
1164+
instanceId: this.instanceId,
1165+
messageId: (oldMessage as any).id,
1166+
},
1167+
});
1168+
}
11481169
}
11491170
}
11501171

@@ -3940,6 +3961,16 @@ export class BaileysStartupService extends ChannelStartupService {
39403961
}
39413962

39423963
try {
3964+
const oldMessage: any = await this.getMessage(data.key, true);
3965+
if (!oldMessage) throw new NotFoundException('Message not found');
3966+
if (oldMessage?.key?.remoteJid !== jid) {
3967+
throw new BadRequestException('RemoteJid does not match');
3968+
}
3969+
if (oldMessage?.messageTimestamp > Date.now() + 900000) {
3970+
// 15 minutes in milliseconds
3971+
throw new BadRequestException('Message is older than 15 minutes');
3972+
}
3973+
39433974
const response = await this.client.sendMessage(jid, {
39443975
...(options as any),
39453976
edit: data.key,
@@ -3963,15 +3994,17 @@ export class BaileysStartupService extends ChannelStartupService {
39633994
if ((message.key.valueOf() as any)?.deleted) {
39643995
new BadRequestException('You cannot edit deleted messages');
39653996
}
3966-
3967-
const updateMessage = this.prepareMessage({ ...response });
3997+
if (oldMessage.messageType === 'conversation' || oldMessage.messageType === 'extendedTextMessage') {
3998+
oldMessage.message.conversation = data.text;
3999+
} else {
4000+
oldMessage.message[oldMessage.messageType].caption = data.text;
4001+
}
39684002
message = await this.prismaRepository.message.update({
39694003
where: { id: message.id },
39704004
data: {
3971-
message: {
3972-
...updateMessage?.message?.[updateMessage.messageType]?.editedMessage,
3973-
},
4005+
message: oldMessage.message,
39744006
status: 'EDITED',
4007+
messageTimestamp: Math.floor(Date.now() / 1000), // Convert to int32 by dividing by 1000 to get seconds
39754008
},
39764009
});
39774010
const messageUpdate: any = {

src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ export class ChatwootService {
18981898
.replaceAll(/~((?!\s)([^\n~]+?)(?<!\s))~/g, '~~$1~~')
18991899
: originalMessage;
19001900

1901-
if (bodyMessage && bodyMessage.includes('Por favor, classifique esta conversa, http')) {
1901+
if (bodyMessage && bodyMessage.includes('/survey/responses/') && bodyMessage.includes('http')) {
19021902
return;
19031903
}
19041904

src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,6 @@ export class TypebotController extends ChatbotController implements ChatbotContr
10181018
return;
10191019
}
10201020

1021-
if (session && !session.awaitUser) {
1022-
return;
1023-
}
1024-
10251021
if (debounceTime && debounceTime > 0) {
10261022
this.processDebounce(this.userMessageDebounce, content, remoteJid, debounceTime, async (debouncedContent) => {
10271023
await this.typebotService.processTypebot(

src/api/integrations/chatbot/typebot/services/typebot.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ export class TypebotService {
741741
}
742742
}
743743

744+
if (session && !session.awaitUser) {
745+
return;
746+
}
747+
744748
if (session && session.status !== 'opened') {
745749
return;
746750
}

0 commit comments

Comments
 (0)