Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcode-tec committed Jul 14, 2023
2 parents 3fcbf45 + e19b825 commit be54331
Show file tree
Hide file tree
Showing 28 changed files with 2,360 additions and 114 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# 1.2.0 (homolog)

### Features

* Native integration with chatwoot
* Added returning or non-returning participants option in fetchAllGroups
* Added group integration to chatwoot
* Added automation on create instance to chatwoot
* Added verbose logs and format chatwoot service

### Fixed

* Adjusts in docker-compose files
* Adjusts in number validation for AR and MX numbers
* Adjusts in env files, removed save old_messages
* Fix when sending a message to a group I don't belong returns a bad request
* Fits the format on return from the fetchAllGroups endpoint
* Adjust in send document with caption from chatwoot
* Fixed message with undefind in chatwoot
* Changed message in path /
* Test duplicate message media in groups chatwoot
* Optimize send message from group with mentions
* Fixed name of the profile status in fetchInstances
* Fixed error 500 when logout in instance with status = close

# 1.1.5 (2023-07-12 07:17)

### Fixed
Expand Down
14 changes: 11 additions & 3 deletions Docker/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SERVER_URL='<url>' # ex.: http://localhost:3333

CORS_ORIGIN='*' # Or separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
CORS_METHODS='POST,GET,PUT,DELETE'
CORS_CREDENTIALS=true
Expand Down Expand Up @@ -31,7 +33,6 @@ DATABASE_CONNECTION_DB_PREFIX_NAME=evolution

# Choose the data you want to save in the application's database or store
DATABASE_SAVE_DATA_INSTANCE=false
DATABASE_SAVE_DATA_OLD_MESSAGE=false
DATABASE_SAVE_DATA_NEW_MESSAGE=false
DATABASE_SAVE_MESSAGE_UPDATE=false
DATABASE_SAVE_DATA_CONTACTS=false
Expand All @@ -41,7 +42,8 @@ REDIS_ENABLED=false
REDIS_URI=redis://redis:6379
REDIS_PREFIX_KEY=evolution

# Webhook Settings
# Global Webhook Settings
# Each instance's Webhook URL and events will be requested at the time it is created
## Define a global webhook that will listen for enabled events from all instances
WEBHOOK_GLOBAL_URL='<url>'
WEBHOOK_GLOBAL_ENABLED=false
Expand All @@ -53,6 +55,7 @@ WEBHOOK_EVENTS_QRCODE_UPDATED=true
WEBHOOK_EVENTS_MESSAGES_SET=true
WEBHOOK_EVENTS_MESSAGES_UPSERT=true
WEBHOOK_EVENTS_MESSAGES_UPDATE=true
WEBHOOK_EVENTS_SEND_MESSAGE=true
WEBHOOK_EVENTS_CONTACTS_SET=true
WEBHOOK_EVENTS_CONTACTS_UPSERT=true
WEBHOOK_EVENTS_CONTACTS_UPDATE=true
Expand All @@ -76,6 +79,8 @@ CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari
QRCODE_LIMIT=30

# Defines an authentication type for the api
# We recommend using the apikey because it will allow you to use a custom token,
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
AUTHENTICATION_TYPE='apikey' # jwt or 'apikey'
## Define a global apikey to access all instances.
### OBS: This key must be inserted in the request header to create an instance.
Expand All @@ -89,4 +94,7 @@ AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
AUTHENTICATION_INSTANCE_MODE=server # container or server
# if you are using container mode, set the container name and the webhook url to default instance
AUTHENTICATION_INSTANCE_NAME=evolution
AUTHENTICATION_INSTANCE_WEBHOOK_URL='<url>'
AUTHENTICATION_INSTANCE_WEBHOOK_URL='<url>'
AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
AUTHENTICATION_INSTANCE_CHATWOOT_URL='<url>'
12 changes: 7 additions & 5 deletions Docker/mongodb/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ services:
container_name: mongodb
image: mongo
restart: always
volumes:
- evolution_mongodb_data:/data/db
- evolution_mongodb_configdb:/data/configdb
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
- PUID=1000
- PGID=1000
volumes:
- evolution_mongodb_data:/data/db
- evolution_mongodb_configdb:/data/configdb
networks:
- evolution-net
expose:
Expand Down
6 changes: 6 additions & 0 deletions Docker/redis/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ services:
redis:
image: redis:latest
container_name: redis
command: >
redis-server
--port 6379
--appendonly yes
volumes:
- evolution_redis:/data
ports:
- 6379:6379
networks:
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ENV DOCKER_ENV=true

ENV SERVER_TYPE="http"
ENV SERVER_PORT=8080
ENV SERVER_URL=$SERVER_URL

ENV CORS_ORIGIN="*"
ENV CORS_METHODS="POST,GET,PUT,DELETE"
Expand All @@ -40,7 +41,6 @@ ENV DATABASE_ENABLED=$DATABASE_ENABLED
ENV DATABASE_CONNECTION_URI=$DATABASE_CONNECTION_URI
ENV DATABASE_CONNECTION_DB_PREFIX_NAME=$DATABASE_CONNECTION_DB_PREFIX_NAME
ENV DATABASE_SAVE_DATA_INSTANCE=$DATABASE_SAVE_DATA_INSTANCE
ENV DATABASE_SAVE_DATA_OLD_MESSAGE=$DATABASE_SAVE_DATA_OLD_MESSAGE
ENV DATABASE_SAVE_DATA_NEW_MESSAGE=$DATABASE_SAVE_DATA_NEW_MESSAGE
ENV DATABASE_SAVE_MESSAGE_UPDATE=$DATABASE_SAVE_MESSAGE_UPDATE
ENV DATABASE_SAVE_DATA_CONTACTS=$DATABASE_SAVE_DATA_CONTACTS
Expand All @@ -57,8 +57,9 @@ ENV WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=$WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS
ENV WEBHOOK_EVENTS_APPLICATION_STARTUP=$WEBHOOK_EVENTS_APPLICATION_STARTUP
ENV WEBHOOK_EVENTS_QRCODE_UPDATED=$WEBHOOK_EVENTS_QRCODE_UPDATED
ENV WEBHOOK_EVENTS_MESSAGES_SET=$WEBHOOK_EVENTS_MESSAGES_SET
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
ENV WEBHOOK_EVENTS_MESSAGES_UPSERT=$WEBHOOK_EVENTS_MESSAGES_UPSERT
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
ENV WEBHOOK_EVENTS_SEND_MESSAGE=$WEBHOOK_EVENTS_SEND_MESSAGE
ENV WEBHOOK_EVENTS_CONTACTS_SET=$WEBHOOK_EVENTS_CONTACTS_SET
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=$WEBHOOK_EVENTS_CONTACTS_UPSERT
ENV WEBHOOK_EVENTS_CONTACTS_UPDATE=$WEBHOOK_EVENTS_CONTACTS_UPDATE
Expand Down Expand Up @@ -88,6 +89,9 @@ ENV AUTHENTICATION_JWT_SECRET="L=0YWt]b2w[WF>#>:&E`"

ENV AUTHENTICATION_INSTANCE_NAME=$AUTHENTICATION_INSTANCE_NAME
ENV AUTHENTICATION_INSTANCE_WEBHOOK_URL=$AUTHENTICATION_INSTANCE_WEBHOOK_URL
ENV AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=$AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID
ENV AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=$AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN
ENV AUTHENTICATION_INSTANCE_CHATWOOT_URL=$AUTHENTICATION_INSTANCE_CHATWOOT_URL
ENV AUTHENTICATION_INSTANCE_MODE=$AUTHENTICATION_INSTANCE_MODE

RUN npm install
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evolution-api",
"version": "1.1.4",
"version": "1.2.0",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js",
"scripts": {
Expand Down Expand Up @@ -43,7 +43,8 @@
"@adiwajshing/keyed-db": "^0.2.4",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@hapi/boom": "^10.0.1",
"@whiskeysockets/baileys": "github:EvolutionAPI/Baileys",
"@whiskeysockets/baileys": "github:vphelipe/WhiskeySockets-Baileys#master",
"@figuro/chatwoot-sdk": "^1.1.14",
"axios": "^1.3.5",
"class-validator": "^0.13.2",
"compression": "^1.7.4",
Expand Down
14 changes: 11 additions & 3 deletions src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'path';
import { SRC_DIR } from './path.config';
import { isBooleanString } from 'class-validator';

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

export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
export type Cors = {
Expand Down Expand Up @@ -33,7 +33,6 @@ export type Log = {

export type SaveData = {
INSTANCE: boolean;
OLD_MESSAGE: boolean;
NEW_MESSAGE: boolean;
MESSAGE_UPDATE: boolean;
CONTACTS: boolean;
Expand Down Expand Up @@ -77,6 +76,7 @@ export type EventsWebhook = {
MESSAGES_SET: boolean;
MESSAGES_UPSERT: boolean;
MESSAGES_UPDATE: boolean;
SEND_MESSAGE: boolean;
CONTACTS_SET: boolean;
CONTACTS_UPDATE: boolean;
CONTACTS_UPSERT: boolean;
Expand All @@ -98,6 +98,9 @@ export type Instance = {
NAME: string;
WEBHOOK_URL: string;
MODE: string;
CHATWOOT_ACCOUNT_ID?: string;
CHATWOOT_TOKEN?: string;
CHATWOOT_URL?: string;
};
export type Auth = {
API_KEY: ApiKey;
Expand Down Expand Up @@ -170,6 +173,7 @@ export class ConfigService {
SERVER: {
TYPE: process.env.SERVER_TYPE as 'http' | 'https',
PORT: Number.parseInt(process.env.SERVER_PORT),
URL: process.env.SERVER_URL,
},
CORS: {
ORIGIN: process.env.CORS_ORIGIN.split(','),
Expand Down Expand Up @@ -203,7 +207,6 @@ export class ConfigService {
ENABLED: process.env?.DATABASE_ENABLED === 'true',
SAVE_DATA: {
INSTANCE: process.env?.DATABASE_SAVE_DATA_INSTANCE === 'true',
OLD_MESSAGE: process.env?.DATABASE_SAVE_DATA_OLD_MESSAGE === 'true',
NEW_MESSAGE: process.env?.DATABASE_SAVE_DATA_NEW_MESSAGE === 'true',
MESSAGE_UPDATE: process.env?.DATABASE_SAVE_MESSAGE_UPDATE === 'true',
CONTACTS: process.env?.DATABASE_SAVE_DATA_CONTACTS === 'true',
Expand Down Expand Up @@ -235,6 +238,7 @@ export class ConfigService {
MESSAGES_SET: process.env?.WEBHOOK_EVENTS_MESSAGES_SET === 'true',
MESSAGES_UPSERT: process.env?.WEBHOOK_EVENTS_MESSAGES_UPSERT === 'true',
MESSAGES_UPDATE: process.env?.WEBHOOK_EVENTS_MESSAGES_UPDATE === 'true',
SEND_MESSAGE: process.env?.WEBHOOK_EVENTS_SEND_MESSAGE === 'true',
CONTACTS_SET: process.env?.WEBHOOK_EVENTS_CONTACTS_SET === 'true',
CONTACTS_UPDATE: process.env?.WEBHOOK_EVENTS_CONTACTS_UPDATE === 'true',
CONTACTS_UPSERT: process.env?.WEBHOOK_EVENTS_CONTACTS_UPSERT === 'true',
Expand Down Expand Up @@ -275,6 +279,10 @@ export class ConfigService {
NAME: process.env.AUTHENTICATION_INSTANCE_NAME,
WEBHOOK_URL: process.env.AUTHENTICATION_INSTANCE_WEBHOOK_URL,
MODE: process.env.AUTHENTICATION_INSTANCE_MODE,
CHATWOOT_ACCOUNT_ID:
process.env.AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID || '',
CHATWOOT_TOKEN: process.env.AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN || '',
CHATWOOT_URL: process.env.AUTHENTICATION_INSTANCE_CHATWOOT_URL || '',
},
},
};
Expand Down
25 changes: 16 additions & 9 deletions src/dev-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
SERVER:
TYPE: http # https
PORT: 8080 # 443
URL: localhost

CORS:
ORIGIN:
- '*'
- "*"
# - yourdomain.com
METHODS:
- POST
Expand Down Expand Up @@ -63,23 +64,23 @@ CLEAN_STORE:
DATABASE:
ENABLED: false
CONNECTION:
URI: 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true'
URI: "mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true"
DB_PREFIX_NAME: evolution
# Choose the data you want to save in the application's database or store
SAVE_DATA:
INSTANCE: false
OLD_MESSAGE: false
NEW_MESSAGE: false
MESSAGE_UPDATE: false
CONTACTS: false
CHATS: false

REDIS:
ENABLED: false
URI: 'redis://localhost:6379'
PREFIX_KEY: 'evolution'
URI: "redis://localhost:6379"
PREFIX_KEY: "evolution"

# Webhook Settings
# Global Webhook Settings
# Each instance's Webhook URL and events will be requested at the time it is created
WEBHOOK:
# Define a global webhook that will listen for enabled events from all instances
GLOBAL:
Expand All @@ -88,13 +89,14 @@ WEBHOOK:
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
WEBHOOK_BY_EVENTS: false
# Automatically maps webhook paths
# Set the events you want to hear
# Set the events you want to hear
EVENTS:
APPLICATION_STARTUP: false
QRCODE_UPDATED: true
MESSAGES_SET: true
MESSAGES_UPSERT: true
MESSAGES_UPDATE: true
SEND_MESSAGE: true
CONTACTS_SET: true
CONTACTS_UPSERT: true
CONTACTS_UPDATE: true
Expand All @@ -112,14 +114,16 @@ WEBHOOK:

CONFIG_SESSION_PHONE:
# Name that will be displayed on smartphone connection
CLIENT: 'Evolution API'
CLIENT: "Evolution API"
NAME: chrome # chrome | firefox | edge | opera | safari

# Set qrcode display limit
QRCODE:
LIMIT: 30

# Defines an authentication type for the api
# We recommend using the apikey because it will allow you to use a custom token,
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
AUTHENTICATION:
TYPE: apikey # jwt or apikey
# Define a global apikey to access all instances
Expand All @@ -134,8 +138,11 @@ AUTHENTICATION:
SECRET: L=0YWt]b2w[WF>#>:&E`
# Set the instance name and webhook url to create an instance in init the application
INSTANCE:
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event
MODE: server # container or server
# if you are using container mode, set the container name and the webhook url to default instance
NAME: evolution
WEBHOOK_URL: <url>
CHATWOOT_ACCOUNT_ID: 1
CHATWOOT_TOKEN: 123456
CHATWOOT_URL: <url>
26 changes: 26 additions & 0 deletions src/validate/validate.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const instanceNameSchema: JSONSchema7 = {
'MESSAGES_SET',
'MESSAGES_UPSERT',
'MESSAGES_UPDATE',
'SEND_MESSAGE',
'CONTACTS_SET',
'CONTACTS_UPSERT',
'CONTACTS_UPDATE',
Expand Down Expand Up @@ -699,6 +700,16 @@ export const groupJidSchema: JSONSchema7 = {
...isNotEmpty('groupJid'),
};

export const getParticipantsSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
getParticipants: { type: 'string', enum: ['true', 'false'] },
},
required: ['getParticipants'],
...isNotEmpty('getParticipants'),
};

export const groupSendInviteSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
Expand Down Expand Up @@ -835,6 +846,7 @@ export const webhookSchema: JSONSchema7 = {
'MESSAGES_SET',
'MESSAGES_UPSERT',
'MESSAGES_UPDATE',
'SEND_MESSAGE',
'CONTACTS_SET',
'CONTACTS_UPSERT',
'CONTACTS_UPDATE',
Expand All @@ -855,3 +867,17 @@ export const webhookSchema: JSONSchema7 = {
required: ['url', 'enabled'],
...isNotEmpty('url'),
};

export const chatwootSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
account_id: { type: 'string' },
token: { type: 'string' },
url: { type: 'string' },
sign_msg: { type: 'boolean', enum: [true, false] },
},
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg'],
...isNotEmpty('account_id', 'token', 'url', 'sign_msg'),
};
Loading

0 comments on commit be54331

Please sign in to comment.