Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f95f312

Browse files
committedJul 24, 2023
Merge branch 'release/1.4.2'
2 parents cc91f2e + 4d9ca4b commit f95f312

File tree

9 files changed

+166
-147
lines changed

9 files changed

+166
-147
lines changed
 

‎CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 1.4.2 (2023-07-24 20:52)
2+
3+
### Fixed
4+
5+
* Fixed validation is set settings
6+
* Adjusts in group validations
7+
* Ajusts in sticker message to chatwoot
8+
19
# 1.4.1 (2023-07-24 18:28)
210

311
### Fixed

‎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": "1.4.1",
3+
"version": "1.4.2",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {

‎src/validate/validate.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ export const createGroupSchema: JSONSchema7 = {
667667
subject: { type: 'string' },
668668
description: { type: 'string' },
669669
profilePicture: { type: 'string' },
670+
promoteParticipants: { type: 'boolean', enum: [true, false] },
670671
participants: {
671672
type: 'array',
672673
minItems: 1,

‎src/whatsapp/controllers/instance.controller.ts

Lines changed: 126 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -41,77 +41,136 @@ export class InstanceController {
4141
chatwoot_url,
4242
chatwoot_sign_msg,
4343
}: InstanceDto) {
44-
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
44+
try {
45+
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
4546

46-
if (instanceName !== instanceName.toLowerCase().replace(/[^a-z0-9]/g, '')) {
47-
throw new BadRequestException(
48-
'The instance name must be lowercase and without special characters',
47+
if (instanceName !== instanceName.toLowerCase().replace(/[^a-z0-9]/g, '')) {
48+
throw new BadRequestException(
49+
'The instance name must be lowercase and without special characters',
50+
);
51+
}
52+
53+
this.logger.verbose('checking duplicate token');
54+
await this.authService.checkDuplicateToken(token);
55+
56+
this.logger.verbose('creating instance');
57+
const instance = new WAStartupService(
58+
this.configService,
59+
this.eventEmitter,
60+
this.repository,
61+
this.cache,
4962
);
50-
}
63+
instance.instanceName = instanceName
64+
.toLowerCase()
65+
.replace(/[^a-z0-9]/g, '')
66+
.replace(' ', '');
5167

52-
this.logger.verbose('checking duplicate token');
53-
await this.authService.checkDuplicateToken(token);
54-
55-
this.logger.verbose('creating instance');
56-
const instance = new WAStartupService(
57-
this.configService,
58-
this.eventEmitter,
59-
this.repository,
60-
this.cache,
61-
);
62-
instance.instanceName = instanceName
63-
.toLowerCase()
64-
.replace(/[^a-z0-9]/g, '')
65-
.replace(' ', '');
66-
67-
this.logger.verbose('instance: ' + instance.instanceName + ' created');
68-
69-
this.waMonitor.waInstances[instance.instanceName] = instance;
70-
this.waMonitor.delInstanceTime(instance.instanceName);
71-
72-
this.logger.verbose('generating hash');
73-
const hash = await this.authService.generateHash(
74-
{
75-
instanceName: instance.instanceName,
76-
},
77-
token,
78-
);
68+
this.logger.verbose('instance: ' + instance.instanceName + ' created');
69+
70+
this.waMonitor.waInstances[instance.instanceName] = instance;
71+
this.waMonitor.delInstanceTime(instance.instanceName);
72+
73+
this.logger.verbose('generating hash');
74+
const hash = await this.authService.generateHash(
75+
{
76+
instanceName: instance.instanceName,
77+
},
78+
token,
79+
);
80+
81+
this.logger.verbose('hash: ' + hash + ' generated');
82+
83+
let getEvents: string[];
84+
85+
if (webhook) {
86+
if (!isURL(webhook, { require_tld: false })) {
87+
throw new BadRequestException('Invalid "url" property in webhook');
88+
}
7989

80-
this.logger.verbose('hash: ' + hash + ' generated');
90+
this.logger.verbose('creating webhook');
91+
try {
92+
this.webhookService.create(instance, {
93+
enabled: true,
94+
url: webhook,
95+
events,
96+
webhook_by_events,
97+
});
8198

82-
let getEvents: string[];
99+
getEvents = (await this.webhookService.find(instance)).events;
100+
} catch (error) {
101+
this.logger.log(error);
102+
}
103+
}
104+
105+
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
106+
let getQrcode: wa.QrCode;
107+
108+
if (qrcode) {
109+
this.logger.verbose('creating qrcode');
110+
await instance.connectToWhatsapp(number);
111+
await delay(5000);
112+
getQrcode = instance.qrCode;
113+
}
114+
115+
const result = {
116+
instance: {
117+
instanceName: instance.instanceName,
118+
status: 'created',
119+
},
120+
hash,
121+
webhook,
122+
webhook_by_events,
123+
events: getEvents,
124+
qrcode: getQrcode,
125+
};
126+
127+
this.logger.verbose('instance created');
128+
this.logger.verbose(result);
129+
130+
return result;
131+
}
132+
133+
if (!chatwoot_account_id) {
134+
throw new BadRequestException('account_id is required');
135+
}
83136

84-
if (webhook) {
85-
if (!isURL(webhook, { require_tld: false })) {
86-
throw new BadRequestException('Invalid "url" property in webhook');
137+
if (!chatwoot_token) {
138+
throw new BadRequestException('token is required');
87139
}
88140

89-
this.logger.verbose('creating webhook');
141+
if (!chatwoot_url) {
142+
throw new BadRequestException('url is required');
143+
}
144+
145+
if (!isURL(chatwoot_url, { require_tld: false })) {
146+
throw new BadRequestException('Invalid "url" property in chatwoot');
147+
}
148+
149+
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
150+
90151
try {
91-
this.webhookService.create(instance, {
152+
this.chatwootService.create(instance, {
92153
enabled: true,
93-
url: webhook,
94-
events,
95-
webhook_by_events,
154+
account_id: chatwoot_account_id,
155+
token: chatwoot_token,
156+
url: chatwoot_url,
157+
sign_msg: chatwoot_sign_msg || false,
158+
name_inbox: instance.instanceName,
159+
number,
96160
});
97161

98-
getEvents = (await this.webhookService.find(instance)).events;
162+
this.chatwootService.initInstanceChatwoot(
163+
instance,
164+
instance.instanceName,
165+
`${urlServer}/chatwoot/webhook/${instance.instanceName}`,
166+
qrcode,
167+
number,
168+
);
99169
} catch (error) {
100170
this.logger.log(error);
101171
}
102-
}
103172

104-
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
105-
let getQrcode: wa.QrCode;
106-
107-
if (qrcode) {
108-
this.logger.verbose('creating qrcode');
109-
await instance.connectToWhatsapp(number);
110-
await delay(5000);
111-
getQrcode = instance.qrCode;
112-
}
113-
114-
const result = {
173+
return {
115174
instance: {
116175
instanceName: instance.instanceName,
117176
status: 'created',
@@ -120,75 +179,21 @@ export class InstanceController {
120179
webhook,
121180
webhook_by_events,
122181
events: getEvents,
123-
qrcode: getQrcode,
182+
chatwoot: {
183+
enabled: true,
184+
account_id: chatwoot_account_id,
185+
token: chatwoot_token,
186+
url: chatwoot_url,
187+
sign_msg: chatwoot_sign_msg || false,
188+
number,
189+
name_inbox: instance.instanceName,
190+
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
191+
},
124192
};
125-
126-
this.logger.verbose('instance created');
127-
this.logger.verbose(result);
128-
129-
return result;
130-
}
131-
132-
if (!chatwoot_account_id) {
133-
throw new BadRequestException('account_id is required');
134-
}
135-
136-
if (!chatwoot_token) {
137-
throw new BadRequestException('token is required');
138-
}
139-
140-
if (!chatwoot_url) {
141-
throw new BadRequestException('url is required');
142-
}
143-
144-
if (!isURL(chatwoot_url, { require_tld: false })) {
145-
throw new BadRequestException('Invalid "url" property in chatwoot');
146-
}
147-
148-
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
149-
150-
try {
151-
this.chatwootService.create(instance, {
152-
enabled: true,
153-
account_id: chatwoot_account_id,
154-
token: chatwoot_token,
155-
url: chatwoot_url,
156-
sign_msg: chatwoot_sign_msg || false,
157-
name_inbox: instance.instanceName,
158-
number,
159-
});
160-
161-
this.chatwootService.initInstanceChatwoot(
162-
instance,
163-
instance.instanceName,
164-
`${urlServer}/chatwoot/webhook/${instance.instanceName}`,
165-
qrcode,
166-
number,
167-
);
168193
} catch (error) {
169-
this.logger.log(error);
194+
console.log(error);
195+
return { error: true, message: error.toString() };
170196
}
171-
172-
return {
173-
instance: {
174-
instanceName: instance.instanceName,
175-
status: 'created',
176-
},
177-
hash,
178-
webhook,
179-
webhook_by_events,
180-
events: getEvents,
181-
chatwoot: {
182-
enabled: true,
183-
account_id: chatwoot_account_id,
184-
token: chatwoot_token,
185-
url: chatwoot_url,
186-
sign_msg: chatwoot_sign_msg || false,
187-
number,
188-
name_inbox: instance.instanceName,
189-
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
190-
},
191-
};
192197
}
193198

194199
public async connectToWhatsapp({ instanceName, number = null }: InstanceDto) {

‎src/whatsapp/controllers/settings.controller.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export class SettingsController {
1515
'requested createSettings from ' + instance.instanceName + ' instance',
1616
);
1717

18-
if (data.reject_call && data.msg_call.trim() == '') {
19-
throw new BadRequestException('msg_call is required');
20-
}
21-
2218
return this.settingsService.create(instance, data);
2319
}
2420

‎src/whatsapp/dto/group.dto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export class CreateGroupDto {
22
subject: string;
3-
description?: string;
43
participants: string[];
4+
description?: string;
5+
promoteParticipants?: boolean;
56
}
67

78
export class GroupPictureDto {

‎src/whatsapp/repository/repository.manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ export class RepositoryBroker {
102102
this.logger.verbose('creating store path: ' + storePath);
103103

104104
const tempDir = join(storePath, 'temp');
105+
const chatwootDir = join(storePath, 'chatwoot');
105106

107+
if (!fs.existsSync(chatwootDir)) {
108+
this.logger.verbose('creating chatwoot dir: ' + chatwootDir);
109+
fs.mkdirSync(chatwootDir, { recursive: true });
110+
}
106111
if (!fs.existsSync(tempDir)) {
107112
this.logger.verbose('creating temp dir: ' + tempDir);
108113
fs.mkdirSync(tempDir, { recursive: true });

‎src/whatsapp/services/chatwoot.service.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ export class ChatwootService {
11791179
videoMessage: msg.videoMessage?.caption,
11801180
extendedTextMessage: msg.extendedTextMessage?.text,
11811181
messageContextInfo: msg.messageContextInfo?.stanzaId,
1182-
stickerMessage: msg.stickerMessage?.fileSha256.toString('base64'),
1182+
stickerMessage: undefined,
11831183
documentMessage: msg.documentMessage?.caption,
11841184
documentWithCaptionMessage:
11851185
msg.documentWithCaptionMessage?.message?.documentMessage?.caption,
@@ -1199,10 +1199,6 @@ export class ChatwootService {
11991199

12001200
const result = typeKey ? types[typeKey] : undefined;
12011201

1202-
if (typeKey === 'stickerMessage') {
1203-
return null;
1204-
}
1205-
12061202
if (typeKey === 'contactMessage') {
12071203
const vCardData = result.split('\n');
12081204
const contactInfo = {};
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.