From 04a6f7c95435ff3a3f25d16227ea778c89896b18 Mon Sep 17 00:00:00 2001 From: Helio Elias Date: Fri, 21 Jul 2023 15:02:09 +0000 Subject: [PATCH 1/3] fix docker and create docker-compose with all services --- .../docker-compose.yaml | 12 +- Docker/evolution-api-all-services/.env | 109 ++++++++++++++++++ .../docker-compose.yaml | 91 +++++++++++++++ 3 files changed, 204 insertions(+), 8 deletions(-) rename docker-compose.yaml => Docker/docker-compose.yaml (73%) create mode 100644 Docker/evolution-api-all-services/.env create mode 100644 Docker/evolution-api-all-services/docker-compose.yaml diff --git a/docker-compose.yaml b/Docker/docker-compose.yaml similarity index 73% rename from docker-compose.yaml rename to Docker/docker-compose.yaml index c6d1bc73..cbc55c12 100644 --- a/docker-compose.yaml +++ b/Docker/docker-compose.yaml @@ -1,9 +1,10 @@ version: '3.3' services: + api: container_name: evolution_api - image: evolution/api:local + image: davidsongomes/evolution-api restart: always ports: - 8080:8080 @@ -11,16 +12,11 @@ services: - evolution_instances:/evolution/instances - evolution_store:/evolution/store env_file: - - ./Docker/.env + - .env command: ['node', './dist/src/main.js'] expose: - 8080 volumes: evolution_instances: - evolution_store: - -networks: - evolution-net: - external: true - \ No newline at end of file + evolution_store: \ No newline at end of file diff --git a/Docker/evolution-api-all-services/.env b/Docker/evolution-api-all-services/.env new file mode 100644 index 00000000..555ba7bc --- /dev/null +++ b/Docker/evolution-api-all-services/.env @@ -0,0 +1,109 @@ +# Server URL - Set your application url +SERVER_URL='http://localhost:8080' + +# Cors - * for all or set separate by commas - ex.: 'yourdomain1.com, yourdomain2.com' +CORS_ORIGIN='*' +CORS_METHODS='POST,GET,PUT,DELETE' +CORS_CREDENTIALS=true + +# Determine the logs to be displayed +LOG_LEVEL='ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS' +LOG_COLOR=true +# Log Baileys - "fatal" | "error" | "warn" | "info" | "debug" | "trace" +LOG_BAILEYS=error + +# Determine how long the instance should be deleted from memory in case of no connection. +# Default time: 5 minutes +# If you don't even want an expiration, enter the value false +DEL_INSTANCE=false + +# Temporary data storage +STORE_MESSAGES=true +STORE_MESSAGE_UP=true +STORE_CONTACTS=true +STORE_CHATS=true + +# Set Store Interval in Seconds (7200 = 2h) +CLEAN_STORE_CLEANING_INTERVAL=7200 +CLEAN_STORE_MESSAGES=true +CLEAN_STORE_MESSAGE_UP=true +CLEAN_STORE_CONTACTS=true +CLEAN_STORE_CHATS=true + +# Permanent data storage +DATABASE_ENABLED=true +DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true +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_NEW_MESSAGE=false +DATABASE_SAVE_MESSAGE_UPDATE=false +DATABASE_SAVE_DATA_CONTACTS=false +DATABASE_SAVE_DATA_CHATS=false + +REDIS_ENABLED=true +REDIS_URI=redis://redis:6379 +REDIS_PREFIX_KEY=evolution + +# 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='' +WEBHOOK_GLOBAL_ENABLED=false +# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event +WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false +## Set the events you want to hear +WEBHOOK_EVENTS_APPLICATION_STARTUP=false +WEBHOOK_EVENTS_QRCODE_UPDATED=true +WEBHOOK_EVENTS_MESSAGES_SET=true +WEBHOOK_EVENTS_MESSAGES_UPSERT=true +WEBHOOK_EVENTS_MESSAGES_UPDATE=true +WEBHOOK_EVENTS_MESSAGES_DELETE=true +WEBHOOK_EVENTS_SEND_MESSAGE=true +WEBHOOK_EVENTS_CONTACTS_SET=true +WEBHOOK_EVENTS_CONTACTS_UPSERT=true +WEBHOOK_EVENTS_CONTACTS_UPDATE=true +WEBHOOK_EVENTS_PRESENCE_UPDATE=true +WEBHOOK_EVENTS_CHATS_SET=true +WEBHOOK_EVENTS_CHATS_UPSERT=true +WEBHOOK_EVENTS_CHATS_UPDATE=true +WEBHOOK_EVENTS_CHATS_DELETE=true +WEBHOOK_EVENTS_GROUPS_UPSERT=true +WEBHOOK_EVENTS_GROUPS_UPDATE=true +WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true +WEBHOOK_EVENTS_CONNECTION_UPDATE=true +# This event fires every time a new token is requested via the refresh route +WEBHOOK_EVENTS_NEW_JWT_TOKEN=false + +# Name that will be displayed on smartphone connection +CONFIG_SESSION_PHONE_CLIENT='Evolution API' +# Browser Name = chrome | firefox | edge | opera | safari +CONFIG_SESSION_PHONE_NAME=chrome + +# 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 +# jwt or 'apikey' +AUTHENTICATION_TYPE='apikey' +## Define a global apikey to access all instances. +### OBS: This key must be inserted in the request header to create an instance. +AUTHENTICATION_API_KEY='B6D711FCDE4D4FD5936544120E713976' +AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true +## Set the secret key to encrypt and decrypt your token and its expiration time +# seconds - 3600s ===1h | zero (0) - never expires +AUTHENTICATION_JWT_EXPIRIN_IN=0 +AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG' +# Set the instance name and webhook url to create an instance in init the application +# With this option activated, you work with a url per webhook event, respecting the local url and the name of each event +# container or server +AUTHENTICATION_INSTANCE_MODE=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='' +AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1 +AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456 +AUTHENTICATION_INSTANCE_CHATWOOT_URL='' \ No newline at end of file diff --git a/Docker/evolution-api-all-services/docker-compose.yaml b/Docker/evolution-api-all-services/docker-compose.yaml new file mode 100644 index 00000000..1fe01975 --- /dev/null +++ b/Docker/evolution-api-all-services/docker-compose.yaml @@ -0,0 +1,91 @@ +version: '3.3' + +services: + + mongodb: + container_name: mongodb + image: mongo + restart: on-failure + ports: + - 27017:27017 + environment: + - 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 + expose: + - 27017 + + mongo-express: + container_name: mongodb-express + image: mongo-express + restart: on-failure + ports: + - 8081:8081 + depends_on: + - mongodb + environment: + ME_CONFIG_BASICAUTH_USERNAME: root + ME_CONFIG_BASICAUTH_PASSWORD: root + ME_CONFIG_MONGODB_SERVER: mongodb + ME_CONFIG_MONGODB_ADMINUSERNAME: root + ME_CONFIG_MONGODB_ADMINPASSWORD: root + links: + - mongodb + + redis: + container_name: redis + image: redis:latest + restart: on-failure + ports: + - 6379:6379 + command: > + redis-server + --port 6379 + --appendonly yes + volumes: + - evolution_redis:/data + + rebrow: + container_name: rebrow + image: marian/rebrow + restart: on-failure + depends_on: + - redis + ports: + - 5001:5001 + links: + - redis + + api: + container_name: evolution_api + image: davidsongomes/evolution-api + restart: always + depends_on: + - mongodb + - redis + ports: + - 8080:8080 + volumes: + - evolution_instances:/evolution/instances + - evolution_store:/evolution/store + env_file: + - .env + command: ['node', './dist/src/main.js'] + expose: + - 8080 + +volumes: + evolution_mongodb_data: + evolution_mongodb_configdb: + evolution_redis: + evolution_instances: + evolution_store: + +networks: + evolution-net: + external: true + \ No newline at end of file From d6194316e1e05f409e4b31c5ec241a622836d54a Mon Sep 17 00:00:00 2001 From: Helio Elias Date: Wed, 2 Aug 2023 13:25:00 -0300 Subject: [PATCH 2/3] Fix Dockers --- package.json | 2 ++ src/install-evolution-api-ws.ts | 15 +++++++++++++++ src/uninstall-evolution-api-ws.ts | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/install-evolution-api-ws.ts create mode 100644 src/uninstall-evolution-api-ws.ts diff --git a/package.json b/package.json index 5c182838..09df55a4 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "mongoose": "^6.10.5", "node-cache": "^5.1.2", "node-mime-types": "^1.1.0", + "node-windows": "^1.0.0-beta.8", "pino": "^8.11.0", "proxy-agent": "^6.2.1", "qrcode": "^1.5.1", @@ -81,6 +82,7 @@ "@types/js-yaml": "^4.0.5", "@types/jsonwebtoken": "^8.5.9", "@types/node": "^18.15.11", + "@types/node-windows": "^0.1.2", "@types/qrcode": "^1.5.0", "@types/qrcode-terminal": "^0.12.0", "@types/uuid": "^8.3.4", diff --git a/src/install-evolution-api-ws.ts b/src/install-evolution-api-ws.ts new file mode 100644 index 00000000..1faadbf9 --- /dev/null +++ b/src/install-evolution-api-ws.ts @@ -0,0 +1,15 @@ +import nodeWindows from 'node-windows'; +import path from 'path'; + +const svc = new nodeWindows.Service({ + name: 'EvolutionAPIServer', + description: + 'WhatsApp-Api-NodeJs - This project is based on the CodeChat. The original project is an implementation of Baileys', + script: path.join(__dirname, 'main.js'), +}); + +svc.on('install', () => { + svc.start(); +}); + +svc.install(); diff --git a/src/uninstall-evolution-api-ws.ts b/src/uninstall-evolution-api-ws.ts new file mode 100644 index 00000000..4311f503 --- /dev/null +++ b/src/uninstall-evolution-api-ws.ts @@ -0,0 +1,16 @@ +import nodeWindows from 'node-windows'; +import path from 'path'; + +const svc = new nodeWindows.Service({ + name: 'EvolutionAPIServer', + description: + 'WhatsApp-Api-NodeJs - This project is based on the CodeChat. The original project is an implementation of Baileys', + script: path.join(__dirname, 'main.js'), +}); + +svc.on('uninstall', () => { + console.log('Uninstall complete.'); + console.log('The service exists: ', svc.exists); +}); + +svc.uninstall(); From f32e259d2ff5cb67dd33f783d3e3bea4bf56c3e5 Mon Sep 17 00:00:00 2001 From: Helio Elias Date: Tue, 8 Aug 2023 21:06:58 -0300 Subject: [PATCH 3/3] Fix isURL function to by pass url with localhost, when webhook is enable --- src/install-evolution-api-ws.ts | 15 --------------- src/uninstall-evolution-api-ws.ts | 16 ---------------- src/whatsapp/services/whatsapp.service.ts | 2 +- 3 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 src/install-evolution-api-ws.ts delete mode 100644 src/uninstall-evolution-api-ws.ts diff --git a/src/install-evolution-api-ws.ts b/src/install-evolution-api-ws.ts deleted file mode 100644 index 1faadbf9..00000000 --- a/src/install-evolution-api-ws.ts +++ /dev/null @@ -1,15 +0,0 @@ -import nodeWindows from 'node-windows'; -import path from 'path'; - -const svc = new nodeWindows.Service({ - name: 'EvolutionAPIServer', - description: - 'WhatsApp-Api-NodeJs - This project is based on the CodeChat. The original project is an implementation of Baileys', - script: path.join(__dirname, 'main.js'), -}); - -svc.on('install', () => { - svc.start(); -}); - -svc.install(); diff --git a/src/uninstall-evolution-api-ws.ts b/src/uninstall-evolution-api-ws.ts deleted file mode 100644 index 4311f503..00000000 --- a/src/uninstall-evolution-api-ws.ts +++ /dev/null @@ -1,16 +0,0 @@ -import nodeWindows from 'node-windows'; -import path from 'path'; - -const svc = new nodeWindows.Service({ - name: 'EvolutionAPIServer', - description: - 'WhatsApp-Api-NodeJs - This project is based on the CodeChat. The original project is an implementation of Baileys', - script: path.join(__dirname, 'main.js'), -}); - -svc.on('uninstall', () => { - console.log('Uninstall complete.'); - console.log('The service exists: ', svc.exists); -}); - -svc.uninstall(); diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 6de7d847..dc82a516 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -453,7 +453,7 @@ export class WAStartupService { } try { - if (this.localWebhook.enabled && isURL(this.localWebhook.url)) { + if (this.localWebhook.enabled && isURL(this.localWebhook.url, { require_tld: false })) { const httpService = axios.create({ baseURL }); const postData = { event,