Skip to content

Commit bddd640

Browse files
committed
Merge branch 'release/1.5.2'
2 parents bd64b0c + 413ad66 commit bddd640

File tree

10 files changed

+194
-39
lines changed

10 files changed

+194
-39
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2+
# 1.5.2 (2023-09-28 17:56)
3+
4+
### Fixed
5+
6+
* Fix chatwootSchema in chatwoot model to store reopen_conversation and conversation_pending options
7+
* Problem resolved when sending files from minio to typebot
8+
* Improvement in the "startTypebot" method to create persistent session when triggered
9+
* New manager for Evo 1.5.2 - Set Typebot update
10+
* Resolved problems when reading/querying instances
11+
112
# 1.5.1 (2023-09-17 13:50)
213

314
### Feature

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:16.18-alpine
22

3-
LABEL version="1.5.1" description="Api to control whatsapp features through http requests."
3+
LABEL version="1.5.2" description="Api to control whatsapp features through http requests."
44
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
55
LABEL contact="[email protected]"
66

Extras/appsmith/manager.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evolution-api",
3-
"version": "1.5.1",
3+
"version": "1.5.2",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {
@@ -46,7 +46,7 @@
4646
"@figuro/chatwoot-sdk": "^1.1.16",
4747
"@hapi/boom": "^10.0.1",
4848
"@sentry/node": "^7.59.2",
49-
"@whiskeysockets/baileys": "^6.4.0",
49+
"@whiskeysockets/baileys": "^6.5.0",
5050
"amqplib": "^0.10.3",
5151
"axios": "^1.3.5",
5252
"class-validator": "^0.13.2",
@@ -78,8 +78,7 @@
7878
"sharp": "^0.30.7",
7979
"socket.io": "^4.7.1",
8080
"socks-proxy-agent": "^8.0.1",
81-
"uuid": "^9.0.0",
82-
"whatsapp-web.js": "^1.22.1"
81+
"uuid": "^9.0.0"
8382
},
8483
"devDependencies": {
8584
"@types/compression": "^1.7.2",

src/whatsapp/dto/typebot.dto.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ export class Session {
44
status?: string;
55
createdAt?: number;
66
updateAt?: number;
7+
prefilledVariables?: PrefilledVariables;
8+
}
9+
10+
export class PrefilledVariables {
11+
remoteJid?: string;
12+
pushName?: string;
13+
additionalData?: { [key: string]: any };
714
}
815

916
export class TypebotDto {

src/whatsapp/models/chatwoot.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const chatwootSchema = new Schema<ChatwootRaw>({
2424
name_inbox: { type: String, required: true },
2525
sign_msg: { type: Boolean, required: true },
2626
number: { type: String, required: true },
27+
reopen_conversation: { type: Boolean, required: true },
28+
conversation_pending: { type: Boolean, required: true },
2729
});
2830

2931
export const ChatwootModel = dbserver?.model(ChatwootRaw.name, chatwootSchema, 'chatwoot');

src/whatsapp/models/typebot.model.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class Session {
88
status?: string;
99
createdAt?: number;
1010
updateAt?: number;
11+
prefilledVariables?: {
12+
remoteJid?: string;
13+
pushName?: string;
14+
additionalData?: { [key: string]: any };
15+
};
1116
}
1217

1318
export class TypebotRaw {
@@ -40,6 +45,11 @@ const typebotSchema = new Schema<TypebotRaw>({
4045
status: { type: String, required: true },
4146
createdAt: { type: Number, required: true },
4247
updateAt: { type: Number, required: true },
48+
prefilledVariables: {
49+
remoteJid: { type: String, required: false },
50+
pushName: { type: String, required: false },
51+
additionalData: { type: Schema.Types.Mixed, required: false }
52+
},
4353
},
4454
],
4555
});

src/whatsapp/services/monitor.service.ts

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { join } from 'path';
77
import { Auth, ConfigService, Database, DelInstance, HttpServer, Redis } from '../../config/env.config';
88
import { Logger } from '../../config/logger.config';
99
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
10+
// inserido por francis inicio
11+
import { NotFoundException } from '../../exceptions';
12+
// inserido por francis fim
1013
import { dbserver } from '../../libs/db.connect';
1114
import { RedisCache } from '../../libs/redis.client';
1215
import {
@@ -72,7 +75,7 @@ export class WAMonitoringService {
7275
}, 1000 * 60 * time);
7376
}
7477
}
75-
78+
/* ocultado por francis inicio
7679
public async instanceInfo(instanceName?: string) {
7780
this.logger.verbose('get instance info');
7881
@@ -128,6 +131,96 @@ export class WAMonitoringService {
128131
return instances;
129132
}
130133
134+
ocultado por francis fim */
135+
136+
// inserido por francis inicio
137+
138+
public async instanceInfo(instanceName?: string) {
139+
this.logger.verbose('get instance info');
140+
if (instanceName && !this.waInstances[instanceName]) {
141+
throw new NotFoundException(`Instance "${instanceName}" not found`);
142+
}
143+
144+
const instances: any[] = [];
145+
146+
for await (const [key, value] of Object.entries(this.waInstances)) {
147+
if (value) {
148+
this.logger.verbose('get instance info: ' + key);
149+
let chatwoot: any;
150+
151+
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
152+
153+
const findChatwoot = await this.waInstances[key].findChatwoot();
154+
155+
if (findChatwoot && findChatwoot.enabled) {
156+
chatwoot = {
157+
...findChatwoot,
158+
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(key)}`,
159+
};
160+
}
161+
162+
if (value.connectionStatus.state === 'open') {
163+
this.logger.verbose('instance: ' + key + ' - connectionStatus: open');
164+
165+
const instanceData = {
166+
instance: {
167+
instanceName: key,
168+
owner: value.wuid,
169+
profileName: (await value.getProfileName()) || 'not loaded',
170+
profilePictureUrl: value.profilePictureUrl,
171+
profileStatus: (await value.getProfileStatus()) || '',
172+
status: value.connectionStatus.state,
173+
},
174+
};
175+
176+
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
177+
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
178+
179+
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey;
180+
181+
instanceData.instance['chatwoot'] = chatwoot;
182+
}
183+
184+
instances.push(instanceData);
185+
} else {
186+
this.logger.verbose('instance: ' + key + ' - connectionStatus: ' + value.connectionStatus.state);
187+
188+
const instanceData = {
189+
instance: {
190+
instanceName: key,
191+
status: value.connectionStatus.state,
192+
},
193+
};
194+
195+
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
196+
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
197+
198+
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey;
199+
200+
instanceData.instance['chatwoot'] = chatwoot;
201+
}
202+
203+
instances.push(instanceData);
204+
}
205+
}
206+
}
207+
208+
this.logger.verbose('return instance info: ' + instances.length);
209+
210+
return instances.find((i) => i.instance.instanceName === instanceName) ?? instances;
211+
}
212+
213+
214+
215+
// inserido por francis fim
216+
217+
218+
219+
220+
221+
222+
223+
131224
private delInstanceFiles() {
132225
this.logger.verbose('cron to delete instance files started');
133226
setInterval(async () => {

src/whatsapp/services/typebot.service.ts

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ export class TypebotService {
100100
const url = data.url;
101101
const typebot = data.typebot;
102102
const variables = data.variables;
103+
const findTypebot = await this.find(instance);
104+
const sessions = (findTypebot.sessions as Session[]) ?? [];
105+
const expire = findTypebot.expire;
106+
const keyword_finish = findTypebot.keyword_finish;
107+
const delay_message = findTypebot.delay_message;
108+
const unknown_message = findTypebot.unknown_message;
109+
const listening_from_me = findTypebot.listening_from_me;
103110

104111
const prefilledVariables = {
105112
remoteJid: remoteJid,
@@ -109,42 +116,47 @@ export class TypebotService {
109116
prefilledVariables[variable.name] = variable.value;
110117
});
111118

112-
const id = Math.floor(Math.random() * 10000000000).toString();
113-
114-
const reqData = {
115-
sessionId: id,
116-
startParams: {
117-
typebot: data.typebot,
118-
prefilledVariables: prefilledVariables,
119-
},
120-
};
121-
122-
const request = await axios.post(data.url + '/api/v1/sendMessage', reqData);
123-
124-
await this.sendWAMessage(
125-
instance,
126-
remoteJid,
127-
request.data.messages,
128-
request.data.input,
129-
request.data.clientSideActions,
130-
);
131-
132-
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
133-
remoteJid: remoteJid,
119+
const response = await this.createNewSession(instance, {
134120
url: url,
135121
typebot: typebot,
136-
variables: variables,
137-
sessionId: id,
122+
remoteJid: remoteJid,
123+
expire: expire,
124+
keyword_finish: keyword_finish,
125+
delay_message: delay_message,
126+
unknown_message: unknown_message,
127+
listening_from_me: listening_from_me,
128+
sessions: sessions,
129+
prefilledVariables: prefilledVariables,
138130
});
139131

132+
if (response.sessionId) {
133+
await this.sendWAMessage(
134+
instance,
135+
remoteJid,
136+
response.messages,
137+
response.input,
138+
response.clientSideActions,
139+
);
140+
141+
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
142+
remoteJid: remoteJid,
143+
url: url,
144+
typebot: typebot,
145+
prefilledVariables: prefilledVariables,
146+
sessionId: `${response.sessionId}`,
147+
});
148+
} else {
149+
throw new Error("Session ID not found in response");
150+
}
151+
140152
return {
141153
typebot: {
142154
...instance,
143155
typebot: {
144156
url: url,
145157
remoteJid: remoteJid,
146158
typebot: typebot,
147-
variables: variables,
159+
prefilledVariables: prefilledVariables,
148160
},
149161
},
150162
};
@@ -193,8 +205,9 @@ export class TypebotService {
193205
startParams: {
194206
typebot: data.typebot,
195207
prefilledVariables: {
208+
...data.prefilledVariables,
196209
remoteJid: data.remoteJid,
197-
pushName: data.pushName,
210+
pushName: data.pushName || 'Default Name',
198211
instanceName: instance.instanceName,
199212
},
200213
},
@@ -209,6 +222,12 @@ export class TypebotService {
209222
status: 'opened',
210223
createdAt: Date.now(),
211224
updateAt: Date.now(),
225+
prefilledVariables: {
226+
...data.prefilledVariables,
227+
remoteJid: data.remoteJid,
228+
pushName: data.pushName || 'Default Name',
229+
instanceName: instance.instanceName,
230+
}
212231
});
213232

214233
const typebotData = {

src/whatsapp/services/whatsapp.service.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,22 +2308,36 @@ export class WAStartupService {
23082308
mediaMessage.fileName = arrayMatch[1];
23092309
this.logger.verbose('File name: ' + mediaMessage.fileName);
23102310
}
2311+
// *inserido francis inicio
2312+
let mimetype: string;
2313+
// *inserido francis final
2314+
23112315

23122316
if (mediaMessage.mediatype === 'image' && !mediaMessage.fileName) {
23132317
mediaMessage.fileName = 'image.png';
2318+
// inserido francis inicio
2319+
mimetype = 'image/png';
2320+
// inserido francis inicio
2321+
23142322
}
23152323

23162324
if (mediaMessage.mediatype === 'video' && !mediaMessage.fileName) {
23172325
mediaMessage.fileName = 'video.mp4';
2326+
// inserido francis inicio
2327+
mimetype = 'video/mp4';
2328+
// inserido francis final
23182329
}
23192330

2320-
let mimetype: string;
2331+
// ocultado francis inicio
2332+
// let mimetype: string;
23212333

2322-
if (isURL(mediaMessage.media)) {
2323-
mimetype = getMIMEType(mediaMessage.media);
2324-
} else {
2325-
mimetype = getMIMEType(mediaMessage.fileName);
2326-
}
2334+
2335+
// if (isURL(mediaMessage.media)) {
2336+
// mimetype = getMIMEType(mediaMessage.media);
2337+
// } else {
2338+
// mimetype = getMIMEType(mediaMessage.fileName);
2339+
// }
2340+
// ocultado francis final
23272341

23282342
this.logger.verbose('Mimetype: ' + mimetype);
23292343

0 commit comments

Comments
 (0)