Skip to content

Commit be7bb2e

Browse files
committed
Merge branch 'release/1.4.0'
2 parents c252f5f + 1c30728 commit be7bb2e

26 files changed

+809
-148
lines changed

CHANGELOG.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
# 1.4.0 (2023-07-24 17:03)
2+
3+
### Features
4+
5+
* Added connection functionality via pairing code
6+
* Added fetch profile endpoint in chat controller
7+
* Created settings controller
8+
* Added reject call and send text message when receiving a call
9+
* Added setting to ignore group messages
10+
* Added connection with pairing code in chatwoot with command /init:{NUMBER}
11+
* Added encoding option in endpoint sendWhatsAppAudio
12+
13+
### Fixed
14+
15+
* Added link preview option in send text message
16+
* Fixed problem with fileSha256 appearing when sending a sticker in chatwoot
17+
* Fixed issue where it was not possible to open a conversation when sent at first by me on my cell phone in chatwoot
18+
* Now it only updates the contact name if it is the same as the phone number in chatwoot
19+
* Now accepts all chatwoot inbox templates
20+
* Command to create new instances set to /new_instance:{NAME}:{NUMBER}
21+
* Fix in chatwoot set, sign msg can now be disabled
22+
23+
### Integrations
24+
25+
- Chatwoot: v2.18.0 - v3.0.0 (Beta)
26+
127
# 1.3.2 (2023-07-21 17:19)
228

329
### Fixed
@@ -10,19 +36,27 @@
1036
* For compatibility reasons, container mode has been removed
1137
* Added docker-compose files example
1238

39+
### Integrations
40+
41+
- Chatwoot: v2.18.0
42+
1343
# 1.3.1 (2023-07-20 07:48)
1444

1545
### Fixed
1646

1747
* Adjust in create store files
1848

49+
### Integrations
50+
51+
- Chatwoot: v2.18.0
52+
1953
# 1.3.0 (2023-07-19 11:33)
2054

2155
### Features
2256

2357
* Added messages.delete event
2458
* Added restart instance endpoint
25-
* Created automation for creating instances in the chatwoot bot with the command '#inbox_whatsapp:<INSTANCE_NAME>'
59+
* Created automation for creating instances in the chatwoot bot with the command '#inbox_whatsapp:{INSTANCE_NAME}
2660
* Change Baileys version to: 6.4.0
2761
* Send contact in chatwoot
2862
* Send contact array in chatwoot

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

src/validate/validate.schema.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const instanceNameSchema: JSONSchema7 = {
5858
},
5959
},
6060
qrcode: { type: 'boolean', enum: [true, false] },
61+
number: { type: 'string', pattern: '^\\d+[\\.@\\w-]+' },
6162
token: { type: 'string' },
6263
},
6364
...isNotEmpty('instanceName'),
@@ -123,7 +124,7 @@ const optionsSchema: JSONSchema7 = {
123124

124125
const numberDefinition: JSONSchema7Definition = {
125126
type: 'string',
126-
pattern: '^\\d+[\\.@\\w-]+',
127+
// pattern: '^\\d+[\\.@\\w-]+',
127128
description: 'Invalid format',
128129
};
129130

@@ -398,7 +399,7 @@ export const contactMessageSchema: JSONSchema7 = {
398399
email: { type: 'string' },
399400
url: { type: 'string' },
400401
},
401-
required: ['fullName', 'wuid', 'phoneNumber'],
402+
required: ['fullName', 'phoneNumber'],
402403
...isNotEmpty('fullName'),
403404
},
404405
minItems: 1,
@@ -445,7 +446,7 @@ export const whatsappNumberSchema: JSONSchema7 = {
445446
uniqueItems: true,
446447
items: {
447448
type: 'string',
448-
pattern: '^\\d+',
449+
// pattern: '^\\d+',
449450
description: '"numbers" must be an array of numeric strings',
450451
},
451452
},
@@ -587,6 +588,17 @@ export const profilePictureSchema: JSONSchema7 = {
587588
},
588589
};
589590

591+
export const profileSchema: JSONSchema7 = {
592+
type: 'object',
593+
properties: {
594+
wuid: { type: 'string' },
595+
name: { type: 'string' },
596+
picture: { type: 'string' },
597+
status: { type: 'string' },
598+
isBusiness: { type: 'boolean' },
599+
},
600+
};
601+
590602
export const messageValidateSchema: JSONSchema7 = {
591603
$id: v4(),
592604
type: 'object',
@@ -865,3 +877,15 @@ export const chatwootSchema: JSONSchema7 = {
865877
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg'],
866878
...isNotEmpty('account_id', 'token', 'url', 'sign_msg'),
867879
};
880+
881+
export const settingsSchema: JSONSchema7 = {
882+
$id: v4(),
883+
type: 'object',
884+
properties: {
885+
reject_call: { type: 'boolean', enum: [true, false] },
886+
msg_call: { type: 'string' },
887+
groups_ignore: { type: 'boolean', enum: [true, false] },
888+
},
889+
required: ['reject_call'],
890+
...isNotEmpty('reject_call'),
891+
};

src/whatsapp/controllers/chat.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ export class ChatController {
4848
return await this.waMonitor.waInstances[instanceName].profilePicture(data.number);
4949
}
5050

51+
public async fetchProfile({ instanceName }: InstanceDto, data: NumberDto) {
52+
logger.verbose('requested fetchProfile from ' + instanceName + ' instance');
53+
return await this.waMonitor.waInstances[instanceName].fetchProfile(
54+
instanceName,
55+
data.number,
56+
);
57+
}
58+
5159
public async fetchContacts({ instanceName }: InstanceDto, query: ContactQuery) {
5260
logger.verbose('requested fetchContacts from ' + instanceName + ' instance');
5361
return await this.waMonitor.waInstances[instanceName].fetchContacts(query);

src/whatsapp/controllers/chatwoot.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ChatwootController {
3333
throw new BadRequestException('token is required');
3434
}
3535

36-
if (!data.sign_msg) {
36+
if (data.sign_msg !== true && data.sign_msg !== false) {
3737
throw new BadRequestException('sign_msg is required');
3838
}
3939
}
@@ -94,4 +94,10 @@ export class ChatwootController {
9494

9595
return chatwootService.receiveWebhook(instance, data);
9696
}
97+
98+
public async newInstance(data: any) {
99+
const chatwootService = new ChatwootService(waMonitor, this.configService);
100+
101+
return chatwootService.newInstance(data);
102+
}
97103
}

src/whatsapp/controllers/instance.controller.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class InstanceController {
3434
webhook_by_events,
3535
events,
3636
qrcode,
37+
number,
3738
token,
3839
chatwoot_account_id,
3940
chatwoot_token,
@@ -105,25 +106,12 @@ export class InstanceController {
105106

106107
if (qrcode) {
107108
this.logger.verbose('creating qrcode');
108-
await instance.connectToWhatsapp();
109-
await delay(2000);
109+
await instance.connectToWhatsapp(number);
110+
await delay(3000);
110111
getQrcode = instance.qrCode;
111112
}
112113

113-
this.logger.verbose('instance created');
114-
this.logger.verbose({
115-
instance: {
116-
instanceName: instance.instanceName,
117-
status: 'created',
118-
},
119-
hash,
120-
webhook,
121-
webhook_by_events,
122-
events: getEvents,
123-
qrcode: getQrcode,
124-
});
125-
126-
return {
114+
const result = {
127115
instance: {
128116
instanceName: instance.instanceName,
129117
status: 'created',
@@ -134,6 +122,11 @@ export class InstanceController {
134122
events: getEvents,
135123
qrcode: getQrcode,
136124
};
125+
126+
this.logger.verbose('instance created');
127+
this.logger.verbose(result);
128+
129+
return result;
137130
}
138131

139132
if (!chatwoot_account_id) {
@@ -162,13 +155,15 @@ export class InstanceController {
162155
url: chatwoot_url,
163156
sign_msg: chatwoot_sign_msg || false,
164157
name_inbox: instance.instanceName,
158+
number,
165159
});
166160

167161
this.chatwootService.initInstanceChatwoot(
168162
instance,
169163
instance.instanceName,
170164
`${urlServer}/chatwoot/webhook/${instance.instanceName}`,
171165
qrcode,
166+
number,
172167
);
173168
} catch (error) {
174169
this.logger.log(error);
@@ -189,13 +184,14 @@ export class InstanceController {
189184
token: chatwoot_token,
190185
url: chatwoot_url,
191186
sign_msg: chatwoot_sign_msg || false,
187+
number,
192188
name_inbox: instance.instanceName,
193189
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
194190
},
195191
};
196192
}
197193

198-
public async connectToWhatsapp({ instanceName }: InstanceDto) {
194+
public async connectToWhatsapp({ instanceName, number = null }: InstanceDto) {
199195
try {
200196
this.logger.verbose(
201197
'requested connectToWhatsapp from ' + instanceName + ' instance',
@@ -206,17 +202,29 @@ export class InstanceController {
206202

207203
this.logger.verbose('state: ' + state);
208204

209-
switch (state) {
210-
case 'close':
211-
this.logger.verbose('connecting');
212-
await instance.connectToWhatsapp();
213-
await delay(2000);
214-
return instance.qrCode;
215-
case 'connecting':
216-
return instance.qrCode;
217-
default:
218-
return await this.connectionState({ instanceName });
205+
if (state == 'open') {
206+
return await this.connectionState({ instanceName });
207+
}
208+
209+
if (state == 'connecting') {
210+
return instance.qrCode;
211+
}
212+
213+
if (state == 'close') {
214+
this.logger.verbose('connecting');
215+
await instance.connectToWhatsapp(number);
216+
217+
await delay(2000);
218+
return instance.qrCode;
219219
}
220+
221+
return {
222+
instance: {
223+
instanceName: instanceName,
224+
status: state,
225+
},
226+
qrcode: instance?.qrCode,
227+
};
220228
} catch (error) {
221229
this.logger.error(error);
222230
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { isURL } from 'class-validator';
2+
import { BadRequestException } from '../../exceptions';
3+
import { InstanceDto } from '../dto/instance.dto';
4+
import { SettingsDto } from '../dto/settings.dto';
5+
import { SettingsService } from '../services/settings.service';
6+
import { Logger } from '../../config/logger.config';
7+
8+
const logger = new Logger('SettingsController');
9+
10+
export class SettingsController {
11+
constructor(private readonly settingsService: SettingsService) {}
12+
13+
public async createSettings(instance: InstanceDto, data: SettingsDto) {
14+
logger.verbose(
15+
'requested createSettings from ' + instance.instanceName + ' instance',
16+
);
17+
18+
if (data.reject_call && data.msg_call.trim() == '') {
19+
throw new BadRequestException('msg_call is required');
20+
}
21+
22+
return this.settingsService.create(instance, data);
23+
}
24+
25+
public async findSettings(instance: InstanceDto) {
26+
logger.verbose('requested findSettings from ' + instance.instanceName + ' instance');
27+
return this.settingsService.find(instance);
28+
}
29+
}

src/whatsapp/dto/chat.dto.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ export class NumberDto {
2626
number: string;
2727
}
2828

29+
export class NumberBusiness {
30+
wid?: string;
31+
jid?: string;
32+
exists?: boolean;
33+
isBusiness: boolean;
34+
name?: string;
35+
message?: string;
36+
description?: string;
37+
email?: string;
38+
website?: string[];
39+
address?: string;
40+
}
41+
2942
export class ProfileNameDto {
3043
name: string;
3144
}

src/whatsapp/dto/chatwoot.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export class ChatwootDto {
55
url?: string;
66
name_inbox?: string;
77
sign_msg?: boolean;
8+
number?: string;
89
}

src/whatsapp/dto/instance.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class InstanceDto {
44
webhook_by_events?: boolean;
55
events?: string[];
66
qrcode?: boolean;
7+
number?: string;
78
token?: string;
89
chatwoot_account_id?: string;
910
chatwoot_token?: string;

src/whatsapp/dto/sendMessage.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export class Options {
1515
presence?: WAPresence;
1616
quoted?: Quoted;
1717
mentions?: Mentions;
18+
linkPreview?: boolean;
19+
encoding?: boolean;
1820
}
1921
class OptionsMessage {
2022
options: Options;

src/whatsapp/dto/settings.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class SettingsDto {
2+
reject_call?: boolean;
3+
msg_call?: string;
4+
groups_ignore?: boolean;
5+
}

src/whatsapp/models/chatwoot.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class ChatwootRaw {
99
url?: string;
1010
name_inbox?: string;
1111
sign_msg?: boolean;
12+
number?: string;
1213
}
1314

1415
const chatwootSchema = new Schema<ChatwootRaw>({
@@ -19,6 +20,7 @@ const chatwootSchema = new Schema<ChatwootRaw>({
1920
url: { type: String, required: true },
2021
name_inbox: { type: String, required: true },
2122
sign_msg: { type: Boolean, required: true },
23+
number: { type: String, required: true },
2224
});
2325

2426
export const ChatwootModel = dbserver?.model(

src/whatsapp/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './message.model';
44
export * from './auth.model';
55
export * from './webhook.model';
66
export * from './chatwoot.model';
7+
export * from './settings.model';

0 commit comments

Comments
 (0)