From 4453dff36d13ee5ebbae37d1ae7db4fe6e42d697 Mon Sep 17 00:00:00 2001 From: Helio Elias Date: Fri, 14 Jul 2023 17:35:42 +0000 Subject: [PATCH 1/9] Change network in docker-compose(api, mongo and redis), add mongo-express and rebrow, tools for maintenance and visualize data --- Docker/{.env.example => .env copy.example} | 0 Docker/mongodb/docker-compose.yaml | 26 ++++++++++++++++------ Docker/redis/docker-compose.yaml | 19 ++++++++++------ docker-compose.yaml | 12 +++++----- 4 files changed, 36 insertions(+), 21 deletions(-) rename Docker/{.env.example => .env copy.example} (100%) diff --git a/Docker/.env.example b/Docker/.env copy.example similarity index 100% rename from Docker/.env.example rename to Docker/.env copy.example diff --git a/Docker/mongodb/docker-compose.yaml b/Docker/mongodb/docker-compose.yaml index 714109c9..a0e0e53c 100644 --- a/Docker/mongodb/docker-compose.yaml +++ b/Docker/mongodb/docker-compose.yaml @@ -1,9 +1,5 @@ version: '3.3' -networks: - evolution-net: - driver: bridge - services: mongodb: container_name: mongodb @@ -17,11 +13,27 @@ services: environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: root - networks: - - evolution-net expose: - 27017 + mongo-express: + image: mongo-express + 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 + ports: + - 8081:8081 + links: + - mongodb + volumes: evolution_mongodb_data: - evolution_mongodb_configdb: \ No newline at end of file + evolution_mongodb_configdb: + +networks: + default: + name: evolution-net + \ No newline at end of file diff --git a/Docker/redis/docker-compose.yaml b/Docker/redis/docker-compose.yaml index 55e73847..76b85df8 100644 --- a/Docker/redis/docker-compose.yaml +++ b/Docker/redis/docker-compose.yaml @@ -1,17 +1,22 @@ version: '3.3' -networks: - evolution-net: - driver: bridge - services: redis: image: redis:latest container_name: redis ports: - 6379:6379 - networks: - - evolution-net - + + rebrow: + image: marian/rebrow + ports: + - 5001:5001 + links: + - redis + volumes: evolution_redis: + +networks: + default: + name: evolution-net \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 45345f32..467dea74 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,9 +1,5 @@ version: '3.3' -networks: - evolution-net: - driver: bridge - services: api: container_name: evolution_api @@ -17,11 +13,13 @@ services: env_file: - ./Docker/.env command: ['node', './dist/src/main.js'] - networks: - - evolution-net expose: - 8080 volumes: evolution_instances: - evolution_store: \ No newline at end of file + evolution_store: + +networks: + default: + name: evolution-net \ No newline at end of file From 8c4f2991c77e80bfba2e339a1973700f1daf723f Mon Sep 17 00:00:00 2001 From: Helio Elias Date: Fri, 14 Jul 2023 17:59:29 +0000 Subject: [PATCH 2/9] Change network in docker-compose(api, mongo and redis), add mongo-express and rebrow, tools for maintenance and visualize data --- Docker/redis/docker-compose.yaml | 2 +- docker-compose.yaml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Docker/redis/docker-compose.yaml b/Docker/redis/docker-compose.yaml index 76b85df8..c6c5abf1 100644 --- a/Docker/redis/docker-compose.yaml +++ b/Docker/redis/docker-compose.yaml @@ -19,4 +19,4 @@ volumes: networks: default: - name: evolution-net \ No newline at end of file + name: evolution-net diff --git a/docker-compose.yaml b/docker-compose.yaml index 467dea74..c62e6ff4 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -22,4 +22,5 @@ volumes: networks: default: - name: evolution-net \ No newline at end of file + name: evolution-net + \ No newline at end of file From 666023d89ab29682467c3b62e40d198fcd001ceb Mon Sep 17 00:00:00 2001 From: Helio Elias Date: Fri, 14 Jul 2023 18:04:36 +0000 Subject: [PATCH 3/9] docker-compose full services --- docker-compose-full.yaml | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 docker-compose-full.yaml diff --git a/docker-compose-full.yaml b/docker-compose-full.yaml new file mode 100644 index 00000000..6b6a3235 --- /dev/null +++ b/docker-compose-full.yaml @@ -0,0 +1,72 @@ +version: '3.3' + +services: + redis: + image: redis:latest + container_name: redis + ports: + - 6379:6379 + + rebrow: + image: marian/rebrow + ports: + - 5001:5001 + links: + - redis + +mongodb: + 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 + expose: + - 27017 + + mongo-express: + image: mongo-express + 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 + ports: + - 8081:8081 + links: + - mongodb + api: + container_name: evolution_api + image: evolution/api:local + restart: always + ports: + - 8080:8080 + volumes: + - evolution_instances:/evolution/instances + - evolution_store:/evolution/store + env_file: + - ./Docker/.env + command: ['node', './dist/src/main.js'] + expose: + - 8080 + links: + - mongodb + - redis + +volumes: + evolution_instances: + evolution_store: + evolution_mongodb_data: + evolution_mongodb_configdb: + evolution_redis: + +networks: + default: + name: evolution-net + \ No newline at end of file From f33a6aba39208c9e131087472359b3507949e288 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 14 Jul 2023 15:29:04 -0300 Subject: [PATCH 4/9] fix: Adjusts in docker files --- CHANGELOG.md | 8 +++++++- package.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd69a55..941f3703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -# 1.2.0 (homolog) +# 1.2.1 (homolog) + +### Fixed + +* Adjusts in docker files + +# 1.2.0 (2023-07-14 15:28) ### Features diff --git a/package.json b/package.json index c0e8c825..21d6fcee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evolution-api", - "version": "1.2.0", + "version": "1.2.1", "description": "Rest api for communication with WhatsApp", "main": "./dist/src/main.js", "scripts": { From 70f7c8ce89ce55d0c90c44bc3530429587738221 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 14 Jul 2023 17:04:15 -0300 Subject: [PATCH 5/9] feat: Save picture url groups in chatwoot --- src/whatsapp/services/chatwoot.service.ts | 54 ++++++++++++++++++----- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 4500fde8..4f0e22cd 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -258,6 +258,7 @@ export class ChatwootService { inboxId: number, isGroup: boolean, name?: string, + avatar_url?: string, ) { this.logger.verbose('create contact to instance: ' + instance.instanceName); @@ -275,6 +276,7 @@ export class ChatwootService { inbox_id: inboxId, name: name || phoneNumber, phone_number: `+${phoneNumber}`, + avatar_url: avatar_url, }; } else { this.logger.verbose('create contact group in chatwoot'); @@ -282,6 +284,7 @@ export class ChatwootService { inbox_id: inboxId, name: name || phoneNumber, identifier: phoneNumber, + avatar_url: avatar_url, }; } @@ -404,27 +407,58 @@ export class ChatwootService { nameContact = `${group.subject} (GROUP)`; this.logger.verbose('find or create participant in chatwoot'); - const participant = - (await this.findContact(instance, body.key.participant.split('@')[0])) || - ((await this.createContact( + + const picture_url = await this.waMonitor.waInstances[ + instance.instanceName + ].profilePicture(body.key.participant.split('@')[0]); + + const findParticipant = await this.findContact( + instance, + body.key.participant.split('@')[0], + ); + + if (findParticipant) { + await this.updateContact(instance, findParticipant.id, { + name: nameContact, + avatar_url: picture_url.profilePictureUrl || null, + }); + } else { + await this.createContact( instance, body.key.participant.split('@')[0], filterInbox.id, - false, - body.pushName || body.key.participant.split('@')[0], - )) as any); + isGroup, + nameContact, + picture_url.profilePictureUrl || null, + ); + } } this.logger.verbose('find or create contact in chatwoot'); - const contact = - (await this.findContact(instance, chatId)) || - ((await this.createContact( + + const picture_url = await this.waMonitor.waInstances[ + instance.instanceName + ].profilePicture(chatId); + + const findContact = await this.findContact(instance, chatId); + + let contact: any; + + if (findContact) { + contact = await this.updateContact(instance, findContact.id, { + name: nameContact, + avatar_url: picture_url.profilePictureUrl || null, + }); + } else { + contact = await this.createContact( instance, chatId, filterInbox.id, isGroup, nameContact, - )) as any); + picture_url.profilePictureUrl || null, + ); + } if (!contact) { this.logger.warn('contact not found'); From 7f4c9b5b112e4896e81b9a1652f6761809157c1a Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 14 Jul 2023 17:04:39 -0300 Subject: [PATCH 6/9] feat: Save picture url groups in chatwoot --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 941f3703..7a9f27ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 1.2.1 (homolog) +### Features + +* Save picture url groups in chatwoot + ### Fixed * Adjusts in docker files From d4766f9c81b60d1fe4cdeb024d9f4a9991b2c34b Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 14 Jul 2023 17:22:30 -0300 Subject: [PATCH 7/9] feat: Save picture url groups in chatwoot --- src/whatsapp/services/chatwoot.service.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 4f0e22cd..74c47d0c 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -43,6 +43,12 @@ export class ChatwootService { this.logger.verbose('message cache saved'); } + private clearMessageCache() { + this.logger.verbose('clear message cache'); + this.messageCache.clear(); + this.saveMessageCache(); + } + private async getProvider(instance: InstanceDto) { this.logger.verbose('get provider to instance: ' + instance.instanceName); try { @@ -465,7 +471,9 @@ export class ChatwootService { return null; } - const contactId = contact.id || contact.payload.contact.id; + console.log(contact); + + const contactId = contact.payload.id || contact.payload.contact.id; if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) { this.logger.verbose('update contact name in chatwoot'); @@ -1002,6 +1010,9 @@ export class ChatwootService { return { message: 'bot' }; } + this.logger.verbose('clear cache'); + this.clearMessageCache(); + this.logger.verbose('Format message to send'); let formatText: string; if (senderName === null || senderName === undefined) { @@ -1158,6 +1169,7 @@ export class ChatwootService { } if (event === 'messages.upsert') { + console.log(body); this.logger.verbose('event messages.upsert'); if (body.key.remoteJid === 'status@broadcast') { From 2a04f7b378a67b4177291d9d89730edc124648b4 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 14 Jul 2023 17:54:48 -0300 Subject: [PATCH 8/9] feat: Save picture url groups in chatwoot --- Docker/{.env copy.example => .env.example} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Docker/{.env copy.example => .env.example} (100%) diff --git a/Docker/.env copy.example b/Docker/.env.example similarity index 100% rename from Docker/.env copy.example rename to Docker/.env.example From b260959a6e68b215f325ef5cec9a7d0f969f90c5 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 14 Jul 2023 18:04:20 -0300 Subject: [PATCH 9/9] fix: Save picture url groups in chatwoot --- CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9f27ec..3d44de46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,9 @@ # 1.2.1 (homolog) -### Features - -* Save picture url groups in chatwoot - ### Fixed * Adjusts in docker files +* Save picture url groups in chatwoot # 1.2.0 (2023-07-14 15:28)