Skip to content

Commit be54331

Browse files
committed
Merge branch 'release/1.2.0'
2 parents 3fcbf45 + e19b825 commit be54331

28 files changed

+2360
-114
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
# 1.2.0 (homolog)
2+
3+
### Features
4+
5+
* Native integration with chatwoot
6+
* Added returning or non-returning participants option in fetchAllGroups
7+
* Added group integration to chatwoot
8+
* Added automation on create instance to chatwoot
9+
* Added verbose logs and format chatwoot service
10+
11+
### Fixed
12+
13+
* Adjusts in docker-compose files
14+
* Adjusts in number validation for AR and MX numbers
15+
* Adjusts in env files, removed save old_messages
16+
* Fix when sending a message to a group I don't belong returns a bad request
17+
* Fits the format on return from the fetchAllGroups endpoint
18+
* Adjust in send document with caption from chatwoot
19+
* Fixed message with undefind in chatwoot
20+
* Changed message in path /
21+
* Test duplicate message media in groups chatwoot
22+
* Optimize send message from group with mentions
23+
* Fixed name of the profile status in fetchInstances
24+
* Fixed error 500 when logout in instance with status = close
25+
126
# 1.1.5 (2023-07-12 07:17)
227

328
### Fixed

Docker/.env.example

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SERVER_URL='<url>' # ex.: http://localhost:3333
2+
13
CORS_ORIGIN='*' # Or separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
24
CORS_METHODS='POST,GET,PUT,DELETE'
35
CORS_CREDENTIALS=true
@@ -31,7 +33,6 @@ DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
3133

3234
# Choose the data you want to save in the application's database or store
3335
DATABASE_SAVE_DATA_INSTANCE=false
34-
DATABASE_SAVE_DATA_OLD_MESSAGE=false
3536
DATABASE_SAVE_DATA_NEW_MESSAGE=false
3637
DATABASE_SAVE_MESSAGE_UPDATE=false
3738
DATABASE_SAVE_DATA_CONTACTS=false
@@ -41,7 +42,8 @@ REDIS_ENABLED=false
4142
REDIS_URI=redis://redis:6379
4243
REDIS_PREFIX_KEY=evolution
4344

44-
# Webhook Settings
45+
# Global Webhook Settings
46+
# Each instance's Webhook URL and events will be requested at the time it is created
4547
## Define a global webhook that will listen for enabled events from all instances
4648
WEBHOOK_GLOBAL_URL='<url>'
4749
WEBHOOK_GLOBAL_ENABLED=false
@@ -53,6 +55,7 @@ WEBHOOK_EVENTS_QRCODE_UPDATED=true
5355
WEBHOOK_EVENTS_MESSAGES_SET=true
5456
WEBHOOK_EVENTS_MESSAGES_UPSERT=true
5557
WEBHOOK_EVENTS_MESSAGES_UPDATE=true
58+
WEBHOOK_EVENTS_SEND_MESSAGE=true
5659
WEBHOOK_EVENTS_CONTACTS_SET=true
5760
WEBHOOK_EVENTS_CONTACTS_UPSERT=true
5861
WEBHOOK_EVENTS_CONTACTS_UPDATE=true
@@ -76,6 +79,8 @@ CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari
7679
QRCODE_LIMIT=30
7780

7881
# Defines an authentication type for the api
82+
# We recommend using the apikey because it will allow you to use a custom token,
83+
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
7984
AUTHENTICATION_TYPE='apikey' # jwt or 'apikey'
8085
## Define a global apikey to access all instances.
8186
### OBS: This key must be inserted in the request header to create an instance.
@@ -89,4 +94,7 @@ AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
8994
AUTHENTICATION_INSTANCE_MODE=server # container or server
9095
# if you are using container mode, set the container name and the webhook url to default instance
9196
AUTHENTICATION_INSTANCE_NAME=evolution
92-
AUTHENTICATION_INSTANCE_WEBHOOK_URL='<url>'
97+
AUTHENTICATION_INSTANCE_WEBHOOK_URL='<url>'
98+
AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
99+
AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
100+
AUTHENTICATION_INSTANCE_CHATWOOT_URL='<url>'

Docker/mongodb/docker-compose.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ services:
99
container_name: mongodb
1010
image: mongo
1111
restart: always
12-
volumes:
13-
- evolution_mongodb_data:/data/db
14-
- evolution_mongodb_configdb:/data/configdb
1512
ports:
1613
- 27017:27017
1714
environment:
18-
MONGO_INITDB_ROOT_USERNAME: root
19-
MONGO_INITDB_ROOT_PASSWORD: root
15+
- MONGO_INITDB_ROOT_USERNAME=root
16+
- MONGO_INITDB_ROOT_PASSWORD=root
17+
- PUID=1000
18+
- PGID=1000
19+
volumes:
20+
- evolution_mongodb_data:/data/db
21+
- evolution_mongodb_configdb:/data/configdb
2022
networks:
2123
- evolution-net
2224
expose:

Docker/redis/docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ services:
88
redis:
99
image: redis:latest
1010
container_name: redis
11+
command: >
12+
redis-server
13+
--port 6379
14+
--appendonly yes
15+
volumes:
16+
- evolution_redis:/data
1117
ports:
1218
- 6379:6379
1319
networks:

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ENV DOCKER_ENV=true
1515

1616
ENV SERVER_TYPE="http"
1717
ENV SERVER_PORT=8080
18+
ENV SERVER_URL=$SERVER_URL
1819

1920
ENV CORS_ORIGIN="*"
2021
ENV CORS_METHODS="POST,GET,PUT,DELETE"
@@ -40,7 +41,6 @@ ENV DATABASE_ENABLED=$DATABASE_ENABLED
4041
ENV DATABASE_CONNECTION_URI=$DATABASE_CONNECTION_URI
4142
ENV DATABASE_CONNECTION_DB_PREFIX_NAME=$DATABASE_CONNECTION_DB_PREFIX_NAME
4243
ENV DATABASE_SAVE_DATA_INSTANCE=$DATABASE_SAVE_DATA_INSTANCE
43-
ENV DATABASE_SAVE_DATA_OLD_MESSAGE=$DATABASE_SAVE_DATA_OLD_MESSAGE
4444
ENV DATABASE_SAVE_DATA_NEW_MESSAGE=$DATABASE_SAVE_DATA_NEW_MESSAGE
4545
ENV DATABASE_SAVE_MESSAGE_UPDATE=$DATABASE_SAVE_MESSAGE_UPDATE
4646
ENV DATABASE_SAVE_DATA_CONTACTS=$DATABASE_SAVE_DATA_CONTACTS
@@ -57,8 +57,9 @@ ENV WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=$WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS
5757
ENV WEBHOOK_EVENTS_APPLICATION_STARTUP=$WEBHOOK_EVENTS_APPLICATION_STARTUP
5858
ENV WEBHOOK_EVENTS_QRCODE_UPDATED=$WEBHOOK_EVENTS_QRCODE_UPDATED
5959
ENV WEBHOOK_EVENTS_MESSAGES_SET=$WEBHOOK_EVENTS_MESSAGES_SET
60-
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
6160
ENV WEBHOOK_EVENTS_MESSAGES_UPSERT=$WEBHOOK_EVENTS_MESSAGES_UPSERT
61+
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
62+
ENV WEBHOOK_EVENTS_SEND_MESSAGE=$WEBHOOK_EVENTS_SEND_MESSAGE
6263
ENV WEBHOOK_EVENTS_CONTACTS_SET=$WEBHOOK_EVENTS_CONTACTS_SET
6364
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=$WEBHOOK_EVENTS_CONTACTS_UPSERT
6465
ENV WEBHOOK_EVENTS_CONTACTS_UPDATE=$WEBHOOK_EVENTS_CONTACTS_UPDATE
@@ -88,6 +89,9 @@ ENV AUTHENTICATION_JWT_SECRET="L=0YWt]b2w[WF>#>:&E`"
8889

8990
ENV AUTHENTICATION_INSTANCE_NAME=$AUTHENTICATION_INSTANCE_NAME
9091
ENV AUTHENTICATION_INSTANCE_WEBHOOK_URL=$AUTHENTICATION_INSTANCE_WEBHOOK_URL
92+
ENV AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=$AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID
93+
ENV AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=$AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN
94+
ENV AUTHENTICATION_INSTANCE_CHATWOOT_URL=$AUTHENTICATION_INSTANCE_CHATWOOT_URL
9195
ENV AUTHENTICATION_INSTANCE_MODE=$AUTHENTICATION_INSTANCE_MODE
9296

9397
RUN npm install

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evolution-api",
3-
"version": "1.1.4",
3+
"version": "1.2.0",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {
@@ -43,7 +43,8 @@
4343
"@adiwajshing/keyed-db": "^0.2.4",
4444
"@ffmpeg-installer/ffmpeg": "^1.1.0",
4545
"@hapi/boom": "^10.0.1",
46-
"@whiskeysockets/baileys": "github:EvolutionAPI/Baileys",
46+
"@whiskeysockets/baileys": "github:vphelipe/WhiskeySockets-Baileys#master",
47+
"@figuro/chatwoot-sdk": "^1.1.14",
4748
"axios": "^1.3.5",
4849
"class-validator": "^0.13.2",
4950
"compression": "^1.7.4",

src/config/env.config.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { join } from 'path';
44
import { SRC_DIR } from './path.config';
55
import { isBooleanString } from 'class-validator';
66

7-
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number };
7+
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
88

99
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
1010
export type Cors = {
@@ -33,7 +33,6 @@ export type Log = {
3333

3434
export type SaveData = {
3535
INSTANCE: boolean;
36-
OLD_MESSAGE: boolean;
3736
NEW_MESSAGE: boolean;
3837
MESSAGE_UPDATE: boolean;
3938
CONTACTS: boolean;
@@ -77,6 +76,7 @@ export type EventsWebhook = {
7776
MESSAGES_SET: boolean;
7877
MESSAGES_UPSERT: boolean;
7978
MESSAGES_UPDATE: boolean;
79+
SEND_MESSAGE: boolean;
8080
CONTACTS_SET: boolean;
8181
CONTACTS_UPDATE: boolean;
8282
CONTACTS_UPSERT: boolean;
@@ -98,6 +98,9 @@ export type Instance = {
9898
NAME: string;
9999
WEBHOOK_URL: string;
100100
MODE: string;
101+
CHATWOOT_ACCOUNT_ID?: string;
102+
CHATWOOT_TOKEN?: string;
103+
CHATWOOT_URL?: string;
101104
};
102105
export type Auth = {
103106
API_KEY: ApiKey;
@@ -170,6 +173,7 @@ export class ConfigService {
170173
SERVER: {
171174
TYPE: process.env.SERVER_TYPE as 'http' | 'https',
172175
PORT: Number.parseInt(process.env.SERVER_PORT),
176+
URL: process.env.SERVER_URL,
173177
},
174178
CORS: {
175179
ORIGIN: process.env.CORS_ORIGIN.split(','),
@@ -203,7 +207,6 @@ export class ConfigService {
203207
ENABLED: process.env?.DATABASE_ENABLED === 'true',
204208
SAVE_DATA: {
205209
INSTANCE: process.env?.DATABASE_SAVE_DATA_INSTANCE === 'true',
206-
OLD_MESSAGE: process.env?.DATABASE_SAVE_DATA_OLD_MESSAGE === 'true',
207210
NEW_MESSAGE: process.env?.DATABASE_SAVE_DATA_NEW_MESSAGE === 'true',
208211
MESSAGE_UPDATE: process.env?.DATABASE_SAVE_MESSAGE_UPDATE === 'true',
209212
CONTACTS: process.env?.DATABASE_SAVE_DATA_CONTACTS === 'true',
@@ -235,6 +238,7 @@ export class ConfigService {
235238
MESSAGES_SET: process.env?.WEBHOOK_EVENTS_MESSAGES_SET === 'true',
236239
MESSAGES_UPSERT: process.env?.WEBHOOK_EVENTS_MESSAGES_UPSERT === 'true',
237240
MESSAGES_UPDATE: process.env?.WEBHOOK_EVENTS_MESSAGES_UPDATE === 'true',
241+
SEND_MESSAGE: process.env?.WEBHOOK_EVENTS_SEND_MESSAGE === 'true',
238242
CONTACTS_SET: process.env?.WEBHOOK_EVENTS_CONTACTS_SET === 'true',
239243
CONTACTS_UPDATE: process.env?.WEBHOOK_EVENTS_CONTACTS_UPDATE === 'true',
240244
CONTACTS_UPSERT: process.env?.WEBHOOK_EVENTS_CONTACTS_UPSERT === 'true',
@@ -275,6 +279,10 @@ export class ConfigService {
275279
NAME: process.env.AUTHENTICATION_INSTANCE_NAME,
276280
WEBHOOK_URL: process.env.AUTHENTICATION_INSTANCE_WEBHOOK_URL,
277281
MODE: process.env.AUTHENTICATION_INSTANCE_MODE,
282+
CHATWOOT_ACCOUNT_ID:
283+
process.env.AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID || '',
284+
CHATWOOT_TOKEN: process.env.AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN || '',
285+
CHATWOOT_URL: process.env.AUTHENTICATION_INSTANCE_CHATWOOT_URL || '',
278286
},
279287
},
280288
};

src/dev-env.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
SERVER:
99
TYPE: http # https
1010
PORT: 8080 # 443
11+
URL: localhost
1112

1213
CORS:
1314
ORIGIN:
14-
- '*'
15+
- "*"
1516
# - yourdomain.com
1617
METHODS:
1718
- POST
@@ -63,23 +64,23 @@ CLEAN_STORE:
6364
DATABASE:
6465
ENABLED: false
6566
CONNECTION:
66-
URI: 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true'
67+
URI: "mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true"
6768
DB_PREFIX_NAME: evolution
6869
# Choose the data you want to save in the application's database or store
6970
SAVE_DATA:
7071
INSTANCE: false
71-
OLD_MESSAGE: false
7272
NEW_MESSAGE: false
7373
MESSAGE_UPDATE: false
7474
CONTACTS: false
7575
CHATS: false
7676

7777
REDIS:
7878
ENABLED: false
79-
URI: 'redis://localhost:6379'
80-
PREFIX_KEY: 'evolution'
79+
URI: "redis://localhost:6379"
80+
PREFIX_KEY: "evolution"
8181

82-
# Webhook Settings
82+
# Global Webhook Settings
83+
# Each instance's Webhook URL and events will be requested at the time it is created
8384
WEBHOOK:
8485
# Define a global webhook that will listen for enabled events from all instances
8586
GLOBAL:
@@ -88,13 +89,14 @@ WEBHOOK:
8889
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
8990
WEBHOOK_BY_EVENTS: false
9091
# Automatically maps webhook paths
91-
# Set the events you want to hear
92+
# Set the events you want to hear
9293
EVENTS:
9394
APPLICATION_STARTUP: false
9495
QRCODE_UPDATED: true
9596
MESSAGES_SET: true
9697
MESSAGES_UPSERT: true
9798
MESSAGES_UPDATE: true
99+
SEND_MESSAGE: true
98100
CONTACTS_SET: true
99101
CONTACTS_UPSERT: true
100102
CONTACTS_UPDATE: true
@@ -112,14 +114,16 @@ WEBHOOK:
112114

113115
CONFIG_SESSION_PHONE:
114116
# Name that will be displayed on smartphone connection
115-
CLIENT: 'Evolution API'
117+
CLIENT: "Evolution API"
116118
NAME: chrome # chrome | firefox | edge | opera | safari
117119

118120
# Set qrcode display limit
119121
QRCODE:
120122
LIMIT: 30
121123

122124
# Defines an authentication type for the api
125+
# We recommend using the apikey because it will allow you to use a custom token,
126+
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
123127
AUTHENTICATION:
124128
TYPE: apikey # jwt or apikey
125129
# Define a global apikey to access all instances
@@ -134,8 +138,11 @@ AUTHENTICATION:
134138
SECRET: L=0YWt]b2w[WF>#>:&E`
135139
# Set the instance name and webhook url to create an instance in init the application
136140
INSTANCE:
137-
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
141+
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
138142
MODE: server # container or server
139143
# if you are using container mode, set the container name and the webhook url to default instance
140144
NAME: evolution
141145
WEBHOOK_URL: <url>
146+
CHATWOOT_ACCOUNT_ID: 1
147+
CHATWOOT_TOKEN: 123456
148+
CHATWOOT_URL: <url>

src/validate/validate.schema.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const instanceNameSchema: JSONSchema7 = {
3939
'MESSAGES_SET',
4040
'MESSAGES_UPSERT',
4141
'MESSAGES_UPDATE',
42+
'SEND_MESSAGE',
4243
'CONTACTS_SET',
4344
'CONTACTS_UPSERT',
4445
'CONTACTS_UPDATE',
@@ -699,6 +700,16 @@ export const groupJidSchema: JSONSchema7 = {
699700
...isNotEmpty('groupJid'),
700701
};
701702

703+
export const getParticipantsSchema: JSONSchema7 = {
704+
$id: v4(),
705+
type: 'object',
706+
properties: {
707+
getParticipants: { type: 'string', enum: ['true', 'false'] },
708+
},
709+
required: ['getParticipants'],
710+
...isNotEmpty('getParticipants'),
711+
};
712+
702713
export const groupSendInviteSchema: JSONSchema7 = {
703714
$id: v4(),
704715
type: 'object',
@@ -835,6 +846,7 @@ export const webhookSchema: JSONSchema7 = {
835846
'MESSAGES_SET',
836847
'MESSAGES_UPSERT',
837848
'MESSAGES_UPDATE',
849+
'SEND_MESSAGE',
838850
'CONTACTS_SET',
839851
'CONTACTS_UPSERT',
840852
'CONTACTS_UPDATE',
@@ -855,3 +867,17 @@ export const webhookSchema: JSONSchema7 = {
855867
required: ['url', 'enabled'],
856868
...isNotEmpty('url'),
857869
};
870+
871+
export const chatwootSchema: JSONSchema7 = {
872+
$id: v4(),
873+
type: 'object',
874+
properties: {
875+
enabled: { type: 'boolean', enum: [true, false] },
876+
account_id: { type: 'string' },
877+
token: { type: 'string' },
878+
url: { type: 'string' },
879+
sign_msg: { type: 'boolean', enum: [true, false] },
880+
},
881+
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg'],
882+
...isNotEmpty('account_id', 'token', 'url', 'sign_msg'),
883+
};

0 commit comments

Comments
 (0)