Skip to content

Commit acad895

Browse files
authored
Merge branch 'EvolutionAPI:v2.0.0' into v2.0.0
2 parents 4932759 + 5671521 commit acad895

File tree

9 files changed

+209
-18
lines changed

9 files changed

+209
-18
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# 2.1.2 (develop)
2+
3+
### Features
4+
5+
* Sync lost messages on chatwoot
6+
7+
### Fixed
8+
9+
* Fetch status message
10+
* Adjusts in migrations
11+
* Update pushName in chatwoot
12+
* Validate message before sending chatwoot
13+
* Adds the message status to the return of the "prepareMessage" function
14+
* Fixed openai setting when send a message with chatwoot
15+
116
# 2.1.1 (2024-09-22 10:31)
217

318
### Features

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM node:20-alpine AS builder
33
RUN apk update && \
44
apk add git ffmpeg wget curl bash
55

6-
LABEL version="2.1.1" description="Api to control whatsapp features through http requests."
6+
LABEL version="2.1.2" description="Api to control whatsapp features through http requests."
77
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
88
LABEL contact="contato@atendai.com"
99

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evolution-api",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/main.js",
66
"type": "commonjs",
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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 `Label` 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 `Label` 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 `Media` 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 `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`.
31+
- 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`.
32+
- 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`.
33+
- 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`.
34+
- 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`.
35+
- 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`.
36+
- 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`.
37+
- 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`.
38+
- 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`.
39+
- 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`.
40+
- 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`.
41+
- 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`.
42+
- 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`.
43+
- 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`.
44+
- 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`.
45+
- 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`.
46+
- 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`.
47+
- 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`.
48+
- 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`.
49+
- 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`.
50+
- 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`.
51+
- 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`.
52+
- 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`.
53+
- 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`.
54+
- 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`.
55+
56+
*/
57+
-- AlterTable
58+
ALTER TABLE `Chat` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
59+
MODIFY `updatedAt` TIMESTAMP NULL;
60+
61+
-- AlterTable
62+
ALTER TABLE `Chatwoot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
63+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
64+
65+
-- AlterTable
66+
ALTER TABLE `Contact` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
67+
MODIFY `updatedAt` TIMESTAMP NULL;
68+
69+
-- AlterTable
70+
ALTER TABLE `Dify` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
71+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
72+
73+
-- AlterTable
74+
ALTER TABLE `DifySetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
75+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
76+
77+
-- AlterTable
78+
ALTER TABLE `EvolutionBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
79+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
80+
81+
-- AlterTable
82+
ALTER TABLE `EvolutionBotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
83+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
84+
85+
-- AlterTable
86+
ALTER TABLE `Flowise` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
87+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
88+
89+
-- AlterTable
90+
ALTER TABLE `FlowiseSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
91+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
92+
93+
-- AlterTable
94+
ALTER TABLE `Instance` MODIFY `disconnectionAt` TIMESTAMP NULL,
95+
MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
96+
MODIFY `updatedAt` TIMESTAMP NULL;
97+
98+
-- AlterTable
99+
ALTER TABLE `IntegrationSession` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
100+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
101+
102+
-- AlterTable
103+
ALTER TABLE `Label` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
104+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
105+
106+
-- AlterTable
107+
ALTER TABLE `Media` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;
108+
109+
-- AlterTable
110+
ALTER TABLE `Message` ADD COLUMN `status` INTEGER NULL;
111+
112+
-- AlterTable
113+
ALTER TABLE `OpenaiBot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
114+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
115+
116+
-- AlterTable
117+
ALTER TABLE `OpenaiCreds` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
118+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
119+
120+
-- AlterTable
121+
ALTER TABLE `OpenaiSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
122+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
123+
124+
-- AlterTable
125+
ALTER TABLE `Proxy` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
126+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
127+
128+
-- AlterTable
129+
ALTER TABLE `Rabbitmq` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
130+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
131+
132+
-- AlterTable
133+
ALTER TABLE `Session` MODIFY `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
134+
135+
-- AlterTable
136+
ALTER TABLE `Setting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
137+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
138+
139+
-- AlterTable
140+
ALTER TABLE `Sqs` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
141+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
142+
143+
-- AlterTable
144+
ALTER TABLE `Template` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
145+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
146+
147+
-- AlterTable
148+
ALTER TABLE `Typebot` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
149+
MODIFY `updatedAt` TIMESTAMP NULL;
150+
151+
-- AlterTable
152+
ALTER TABLE `TypebotSetting` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
153+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
154+
155+
-- AlterTable
156+
ALTER TABLE `Webhook` ADD COLUMN `headers` JSON NULL,
157+
MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
158+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
159+
160+
-- AlterTable
161+
ALTER TABLE `Websocket` MODIFY `createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
162+
MODIFY `updatedAt` TIMESTAMP NOT NULL;
163+
164+
-- CreateTable
165+
CREATE TABLE `IsOnWhatsapp` (
166+
`id` VARCHAR(191) NOT NULL,
167+
`remoteJid` VARCHAR(100) NOT NULL,
168+
`jidOptions` VARCHAR(191) NOT NULL,
169+
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
170+
`updatedAt` TIMESTAMP NOT NULL,
171+
172+
UNIQUE INDEX `IsOnWhatsapp_remoteJid_key`(`remoteJid`),
173+
PRIMARY KEY (`id`)
174+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

prisma/mysql-schema.prisma

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ model Message {
159159
MessageUpdate MessageUpdate[]
160160
Media Media?
161161
webhookUrl String? @db.VarChar(500)
162+
status Int? @db.Int
162163
163164
sessionId String?
164165
session IntegrationSession? @relation(fields: [sessionId], references: [id])
@@ -574,3 +575,11 @@ model FlowiseSetting {
574575
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
575576
instanceId String @unique
576577
}
578+
579+
model IsOnWhatsapp {
580+
id String @id @default(cuid())
581+
remoteJid String @unique @db.VarChar(100)
582+
jidOptions String
583+
createdAt DateTime @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp
584+
updatedAt DateTime @updatedAt @db.Timestamp
585+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Message" ADD COLUMN "status" INTEGER;

prisma/postgresql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ model Message {
158158
MessageUpdate MessageUpdate[]
159159
Media Media?
160160
webhookUrl String? @db.VarChar(500)
161+
status Int? @db.Integer
161162
162163
sessionId String?
163164
session IntegrationSession? @relation(fields: [sessionId], references: [id])

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ export class BaileysStartupService extends ChannelStartupService {
10741074
}
10751075
}
10761076

1077-
if (this.configService.get<Openai>('OPENAI').ENABLED) {
1077+
if (this.configService.get<Openai>('OPENAI').ENABLED && received?.message?.audioMessage) {
10781078
const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({
10791079
where: {
10801080
instanceId: this.instanceId,
@@ -1084,12 +1084,7 @@ export class BaileysStartupService extends ChannelStartupService {
10841084
},
10851085
});
10861086

1087-
if (
1088-
openAiDefaultSettings &&
1089-
openAiDefaultSettings.openaiCredsId &&
1090-
openAiDefaultSettings.speechToText &&
1091-
received?.message?.audioMessage
1092-
) {
1087+
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
10931088
messageRaw.message.speechToText = await this.openaiService.speechToText(
10941089
openAiDefaultSettings.OpenaiCreds,
10951090
received,
@@ -1180,7 +1175,7 @@ export class BaileysStartupService extends ChannelStartupService {
11801175

11811176
const contactRaw: { remoteJid: string; pushName: string; profilePicUrl?: string; instanceId: string } = {
11821177
remoteJid: received.key.remoteJid,
1183-
pushName: received.key.fromMe ? '' : (received.key.fromMe == null ? '' : received.pushName),
1178+
pushName: received.key.fromMe ? '' : received.key.fromMe == null ? '' : received.pushName,
11841179
profilePicUrl: (await this.profilePicture(received.key.remoteJid)).profilePictureUrl,
11851180
instanceId: this.instanceId,
11861181
};
@@ -1945,7 +1940,7 @@ export class BaileysStartupService extends ChannelStartupService {
19451940
);
19461941
}
19471942

1948-
if (this.configService.get<Openai>('OPENAI').ENABLED) {
1943+
if (this.configService.get<Openai>('OPENAI').ENABLED && messageRaw?.message?.audioMessage) {
19491944
const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({
19501945
where: {
19511946
instanceId: this.instanceId,
@@ -1955,12 +1950,7 @@ export class BaileysStartupService extends ChannelStartupService {
19551950
},
19561951
});
19571952

1958-
if (
1959-
openAiDefaultSettings &&
1960-
openAiDefaultSettings.openaiCredsId &&
1961-
openAiDefaultSettings.speechToText &&
1962-
messageRaw?.message?.audioMessage
1963-
) {
1953+
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
19641954
messageRaw.message.speechToText = await this.openaiService.speechToText(
19651955
openAiDefaultSettings.OpenaiCreds,
19661956
messageRaw,

src/api/services/channel.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ export class ChannelStartupService {
600600
where: {
601601
instanceId: this.instanceId,
602602
remoteJid: query.where?.remoteJid,
603-
messageId: query.where?.id,
603+
keyId: query.where?.id,
604604
},
605605
skip: query.offset * (query?.page === 1 ? 0 : (query?.page as number) - 1),
606606
take: query.offset,

0 commit comments

Comments
 (0)