Compare commits

..

196 Commits
1.7.1 ... 1.8.2

Author SHA1 Message Date
Davidson Gomes
b8fe5603fd Merge branch 'release/1.8.2' 2024-07-03 16:10:38 -03:00
Davidson Gomes
762453c0e3 chore: Add workflow to publish Docker image
A new untracked file '.github/workflows/publish\_docker\_image\_latest.yml' was added. This workflow will handle the process of publishing the latest Docker image. This change allows for easier and more automated deployment of the Node.js project.
2024-07-03 16:10:23 -03:00
Davidson Gomes
af1b5caa29 Merge tag '1.8.2' into develop
* Corretion in globall rabbitmq queue name
* Improvement in the use of mongodb database for credentials
* Fixed base64 in webhook for documentWithCaption
* Fixed Generate pairing code
2024-07-03 16:09:25 -03:00
Davidson Gomes
50b3379d88 Merge branch 'release/1.8.2' 2024-07-03 16:09:17 -03:00
Davidson Gomes
c9ac5984ec Merge tag '1.8.2' into develop
* Corretion in globall rabbitmq queue name
* Improvement in the use of mongodb database for credentials
* Fixed base64 in webhook for documentWithCaption
* Fixed Generate pairing code
2024-07-03 16:06:24 -03:00
Davidson Gomes
29ba63d621 Merge branch 'release/1.8.2' 2024-07-03 16:06:16 -03:00
Davidson Gomes
2ce64af502 Merge tag '1.8.2' into develop
* Corretion in globall rabbitmq queue name
* Improvement in the use of mongodb database for credentials
* Fixed base64 in webhook for documentWithCaption
* Fixed Generate pairing code
2024-07-03 13:51:36 -03:00
Davidson Gomes
28c517a3d5 Merge branch 'release/1.8.2' 2024-07-03 13:51:28 -03:00
Davidson Gomes
18ebe27bc3 "chore: Updated package and documentation versions to v1.8.2"
Explanation:
This commit updates the package and documentation versions to v1.8.2. The package.json and swagger.yaml files were modified accordingly. These changes are mainly for maintenance purposes and do not affect the functionality of the application.
2024-07-03 13:51:16 -03:00
Davidson Gomes
0f7a39a08f chore(changelog): Update changelog to v1.8.2
This commit updates the changelog to reflect the release of version 1.8.2. The date of the release has been updated in the header of the changelog. No functional changes were made in this release.

Modified: CHANGELOG.md
2024-07-03 13:50:30 -03:00
Davidson Gomes
a8121d7fe6 fix: Correction in global RabbitMQ queue name
Fix global RabbitMQ queue name in `channel.service.ts` and update CHANGELOG.md.
The queue name has been changed from `transformedWe` to `event`.
This fix prevents queue errors and ensures correct functionality of inter-service communication.
2024-07-03 13:47:25 -03:00
Davidson Gomes
b63b7b0b7b fix: Generate pairing code and update Baileys repository
Update package.json to use the new Baileys repository and modify the Whatsapp Baileys service to generate a pairing code. This change fixes the issue with the previous Baileys repository and improves the pairing process for Whatsapp.

Changes:
- Update package.json to use the new Baileys repository
- Modify Whatsapp Baileys service to generate a pairing code
- Fix issue with previous Baileys repository
- Improve pairing process for Whatsapp
2024-07-03 13:45:05 -03:00
Davidson Gomes
14ea5d959f Merge pull request #662 from drauber/cwId_missing
Add -cwId- when findByName
2024-06-26 10:32:09 -03:00
Douglas Rauber at Nitro
86b2999fcf Add -cwId- when findByName 2024-06-24 10:37:54 -03:00
Davidson Gomes
f5bd11fc19 feat: add support for documentWithCaptionMessage in WhatsApp Baileys service
Modified whatsapp.baileys.service.ts to include handling for documentWithCaptionMessage. This change ensures that messages with documents having captions are properly processed, enhancing the service's message handling capabilities. No impact on existing functionalities.
2024-06-18 11:34:47 -03:00
Davidson Gomes
c060d330de fix: normalize event names in channel.service.ts
Normalized event names by replacing underscores with dots and converting to lowercase. This ensures consistent naming conventions and prevents potential issues with queue bindings.
2024-06-18 11:32:50 -03:00
Davidson Gomes
1e320f7904 fix: update use-multi-file-auth-state-db.ts to handle edge cases
Refactored the use-multi-file-auth-state-db.ts to better handle edge cases in multi-file authentication state management. This change improves reliability and ensures more robust error handling, reducing potential issues during authentication.
2024-06-17 11:19:22 -03:00
Davidson Gomes
975b3ee528 fix: reorder imports to resolve linting issues
Reordered imports in multiple files to resolve linting issues and improve code readability. This change does not impact the functionality but ensures the code adheres to the project's coding standards.
2024-06-16 17:19:45 -03:00
Davidson Gomes
5b47bc9ef0 feat: update dependencies and improve caching logic
Updated package.json to include latest dependencies. Enhanced caching logic in cache.service.ts and rediscache.ts for better performance. Improved DTOs in chat.dto.ts, instance.dto.ts, and sendMessage.dto.ts for more robust data handling. Refined instance.controller.ts and chatwoot.service.ts to streamline API integrations. Adjusted authentication state management in use-multi-file-auth-state-db.ts, use-multi-file-auth-state-provider-files.ts, and use-multi-file-auth-state-redis-db.ts. These changes aim to optimize the system's performance and reliability.
2024-06-16 17:17:55 -03:00
Davidson Gomes
053a7981d1 fix: update default values for WA_BUSINESS environment variables
Updated default values for WA_BUSINESS_TOKEN_WEBHOOK, WA_BUSINESS_URL, and WA_BUSINESS_VERSION in env.config.ts to 'evolution', 'https://graph.facebook.com', and 'v19.0' respectively. This change ensures that the application uses more appropriate defaults if environment variables are not set, improving reliability and consistency.
2024-06-13 18:51:18 -03:00
Davidson Gomes
5f1f025d65 Merge tag '1.8.1' into develop
v
2024-06-12 19:49:40 -03:00
Davidson Gomes
dfb003fd72 Merge branch 'release/1.8.1' 2024-06-12 19:49:37 -03:00
Davidson Gomes
5239e431c2 feat: update server and monitor services
Updated server.module.ts and monitor.service.ts to improve service initialization and monitoring logic. Modified main.ts to integrate changes. This enhances the application's performance and reliability.
2024-06-12 19:48:56 -03:00
Davidson Gomes
53cc6132f5 Merge tag '1.8.1' into develop
v
2024-06-12 19:03:36 -03:00
Davidson Gomes
0bc1b78db9 Merge branch 'release/1.8.1' 2024-06-12 19:03:30 -03:00
Davidson Gomes
2a9412c81a chore: adjust socket configuration and update baileys version
Updated package.json to include the latest version of baileys for improved functionality. Modified whatsapp.baileys.service.ts to adjust socket configuration, enhancing the stability and performance of the service.
2024-06-12 19:02:36 -03:00
Davidson Gomes
f707cf4109 Merge tag '1.8.1' into develop
v
2024-06-09 14:22:20 -03:00
Davidson Gomes
410cfc8bcb Merge branch 'release/1.8.1' 2024-06-09 14:22:17 -03:00
Davidson Gomes
f1a3fd872f git actions v2 2024-06-09 14:20:48 -03:00
Davidson Gomes
fff0ca5c79 Merge tag '1.8.1' into develop
v
2024-06-08 21:33:12 -03:00
Davidson Gomes
bd069200ea Merge branch 'release/1.8.1' 2024-06-08 21:33:02 -03:00
Davidson Gomes
c898f1e62a v1.8.1 2024-06-08 21:32:50 -03:00
Davidson Gomes
2002e1c38d changelog 2024-06-08 21:31:02 -03:00
Davidson Gomes
1f817df5f6 fix: Correction of variables breaking lines in typebot 2024-06-08 21:27:58 -03:00
Davidson Gomes
8eced6c575 Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop 2024-06-05 21:48:53 -03:00
Davidson Gomes
afcf6eab71 cacheGroupMetadata 2024-06-05 21:48:37 -03:00
Davidson Gomes
9633412ef6 cacheGroupMetadata 2024-06-05 21:39:33 -03:00
Davidson Gomes
8034e7f587 cacheGroupMetadata 2024-06-05 21:25:55 -03:00
Davidson Gomes
5be01e1c18 Merge pull request #629 from cark7/develop
fix: added validation when sending gif image
2024-06-04 16:59:36 -03:00
Carlos Chinchilla
6371773416 fix: added validation when sending gif image 2024-06-04 15:14:02 -03:00
Davidson Gomes
52230edc5c session worker compatibility 2024-06-03 19:06:00 -03:00
Davidson Gomes
dd123c6a99 Adjust to repository from session worker 2024-06-01 19:47:43 -03:00
Davidson Gomes
5b2a0fdcb1 Adjust to repository from session worker 2024-06-01 19:29:37 -03:00
Davidson Gomes
9354af3bc7 Adjust to repository from session worker 2024-06-01 19:20:59 -03:00
Davidson Gomes
f48f331d43 New method of saving sessions to a file using worker 2024-06-01 13:28:29 -03:00
Davidson Gomes
696261d749 New method of saving sessions to a file using worker 2024-06-01 09:54:56 -03:00
Davidson Gomes
0e9d036fe0 Merge pull request #622 from jrCleber/main
Adiciona templates para Relatório de Bug e Solicitação de Recursos
2024-05-29 10:34:23 -03:00
Cleber Wilson
8e19fe2fb5 labels para filtros adicionada 2024-05-29 10:33:23 -03:00
Cleber Wilson
861b690217 Adiciona templates para Relatório de Bug e Solicitação de Recursos
- Cria um template para Relatório de Bug com os seguintes campos:
  - Termos de aceite
  - Descrição detalhada do problema
  - Expectativa versus observação
  - Capturas de tela/vídeos
  - Versão da API
  - Ambiente
  - Especificações adicionais do ambiente
  - Logs (se aplicável)
  - Notas adicionais

- Cria um template para Solicitação de Recursos com os seguintes campos:
  - Termos de aceite
  - Tipo de recurso
  - Motivação para a solicitação
  - Exemplos de uso
  - Ideias de desenvolvimento
  - Notas adicionais
2024-05-29 10:08:42 -03:00
Davidson Gomes
f7c9541f5e Merge tag '1.8.0' into develop
v
2024-05-27 16:36:08 -03:00
Davidson Gomes
05b5ae8a84 Merge branch 'release/1.8.0' 2024-05-27 16:36:03 -03:00
Davidson Gomes
2e9c14a0a8 fix: security fix in fetch instance with client key when not connected to mongodb 2024-05-27 16:35:59 -03:00
Davidson Gomes
3350cec589 fix: security fix in fetch instance with client key when not connected to mongodb 2024-05-27 16:35:55 -03:00
Davidson Gomes
bd7a42646b Merge tag '1.8.0' into develop
v
2024-05-27 16:24:29 -03:00
Davidson Gomes
2ae4ddee18 Merge branch 'release/1.8.0' 2024-05-27 16:24:25 -03:00
Davidson Gomes
2fb6e2b209 fix: Build in docker for linux/amd64, linux/arm64 platforms 2024-05-27 16:24:21 -03:00
Davidson Gomes
91f869b136 Merge tag '1.8.0' into develop
v
2024-05-27 16:17:30 -03:00
Davidson Gomes
1284a97625 Merge branch 'release/1.8.0' 2024-05-27 16:17:27 -03:00
Davidson Gomes
3a5cfbf36f fix: Build in docker for linux/amd64, linux/arm64 platforms 2024-05-27 16:17:22 -03:00
Davidson Gomes
47b8ecd43b Merge tag '1.8.0' into develop
v
2024-05-27 16:09:16 -03:00
Davidson Gomes
25ce1a4689 Merge branch 'release/1.8.0' 2024-05-27 16:09:12 -03:00
Davidson Gomes
a5156709ab fix: Build in docker for linux/amd64, linux/arm64 platforms 2024-05-27 16:09:07 -03:00
Davidson Gomes
fd2d37d862 Merge tag '1.8.0' into develop
v
2024-05-27 16:07:19 -03:00
Davidson Gomes
87bf433e9a Merge branch 'release/1.8.0' 2024-05-27 16:07:15 -03:00
Davidson Gomes
b5ec79daae fix: Build in docker for linux/amd64, linux/arm64 platforms 2024-05-27 16:07:03 -03:00
Davidson Gomes
3b19200997 Merge tag '1.7.6' into develop
v
2024-05-27 15:54:45 -03:00
Davidson Gomes
0ab040080c Merge branch 'release/1.7.6' 2024-05-27 15:54:42 -03:00
Davidson Gomes
5719896d18 fix: git actions 2024-05-27 15:54:31 -03:00
Davidson Gomes
e9e1cb6ebc Merge tag '1.7.6' into develop
v
2024-05-27 15:51:22 -03:00
Davidson Gomes
ceee6a7e74 Merge branch 'release/1.7.6' 2024-05-27 15:51:19 -03:00
Davidson Gomes
ebfc6d4fa5 fix: git actions 2024-05-27 15:51:06 -03:00
Davidson Gomes
0d62557a15 Merge pull request #609 from stack-app-br/main
chore: build docker image to platforms: linux/amd64,linux/arm64
2024-05-27 15:45:28 -03:00
Davidson Gomes
097c09328f Merge pull request #615 from deivisonrpg/fix-merge-brazil-contacts
fix(chatwoot): add merge_brazil_contacts flag to ChannelStartupService and add logs
2024-05-27 15:34:56 -03:00
Davidson Gomes
732103292b Merge pull request #618 from edisoncm-ti/develop
fix: Correction to Postgres connection string in environment files
2024-05-27 15:34:29 -03:00
edisoncm-ti
3191e9b450 fix: Correction to Postgres connection string in environment files 2024-05-27 15:14:52 -03:00
Davidson Gomes
bf88fdbb31 fix: adjust send presence 2024-05-27 12:57:18 -03:00
Davidson Gomes
4c3fb5e762 correction in message formatting when generated by AI as markdown in typebot 2024-05-27 09:27:42 -03:00
Davidson Gomes
e4b6f4ff0d correction in message formatting when generated by AI as markdown in typebot 2024-05-27 09:23:53 -03:00
Deivison Lincoln
ca0b0d4602 Add merge_brazil_contacts flag to ChannelStartupService 2024-05-25 10:09:37 -03:00
Deivison Lincoln
d7c3779ff7 fix: Add merge_brazil_contacts flag to ChannelStartupService 2024-05-25 10:05:04 -03:00
Davidson Gomes
f0d40eea15 New global mode for rabbitmq events 2024-05-24 18:48:54 -03:00
Davidson Gomes
68dcc1c86a adjusts in create instance 2024-05-23 11:56:52 -03:00
Davidson Gomes
f7dcab3736 Now in the manager, when logging in with the client's apikey, the listing only shows the instance corresponding to the provided apikey (only with MongoDB) 2024-05-23 11:31:45 -03:00
Davidson Gomes
2fcb476c50 Now in the manager, when logging in with the client's apikey, the listing only shows the instance corresponding to the provided apikey (only with MongoDB) 2024-05-23 11:30:47 -03:00
Antonio Milesi Bastos
44a7cd62c8 Merge pull request #1 from stack-app-br/releases/1.7.5
chore: build docker image to platforms: linux/amd64,linux/arm64
2024-05-21 11:56:53 -03:00
@milesibastos
f7f0f8251b chore: build docker image to platforms: linux/amd64,linux/arm64 2024-05-21 11:48:13 -03:00
Davidson Gomes
395b81a6ac Merge tag '1.7.5' into develop
v
2024-05-21 08:53:58 -03:00
Davidson Gomes
da06ed1185 Merge branch 'release/1.7.5' 2024-05-21 08:53:53 -03:00
Davidson Gomes
67afbd6a77 v1.7.5 2024-05-21 08:53:35 -03:00
Davidson Gomes
8fce53b4af fixed version whatsapp web for baileys 2024-05-21 08:38:08 -03:00
Davidson Gomes
65bba23519 update baileys version 2024-05-20 19:53:23 -03:00
Davidson Gomes
283b497788 downgrade baileys version 2024-05-20 19:39:56 -03:00
Davidson Gomes
8cc1b8daa8 Merge pull request #590 from Ckk3/fix-envvar-CLEAN_STORE_CLEANING_INTERVAL
Corrigindo variável inexistente do arquivo env.config.ts e substituindo pela correta CLEAN_STORE_CLEANING_INTERVAL
2024-05-09 14:15:09 -03:00
Davidson Gomes
9ccdb45a7a Merge pull request #587 from deivisonrpg/chatwoot-merge-contact-with-nine
feature(chatwoot): add merge_brazil_contacts function to solve nine digit in brazilian numbers
2024-05-09 14:12:31 -03:00
Davidson Gomes
f78d360c38 Merge pull request #586 from deivisonrpg/chatwoot-update-contact
refactor(chatwoot): optimize ChatwootService method for updating contact inform…
2024-05-09 14:11:07 -03:00
Ckk3
6144fbe856 changing CLEAN_STORE_CLEANING_TERMINAL to CLEAN_STORE_CLEANING_INTERVAL 2024-05-09 13:21:28 -03:00
Deivison Lincoln
8446be7646 fix(chatwoot): fix grupos 2024-05-08 16:47:21 -03:00
Deivison Lincoln
8875ab1e93 feat: add merge_brazil_contacts flag to instance controller 2024-05-08 15:26:56 -03:00
Deivison Lincoln
7c207a50e1 feat: add merge_brazil_contacts to swagger doc 2024-05-08 15:11:37 -03:00
Deivison Lincoln
dcc32479ff feature(chatwoot): add merge_brazil_contacts function to solve nine digit in brazilian numbers 2024-05-08 15:03:37 -03:00
Deivison Lincoln
09911c472d refactor: optimize ChatwootService method for updating contact information 2024-05-08 14:34:03 -03:00
Davidson Gomes
7a0149ee23 Merge pull request #571 from stack-app-br/main
chore: build docker image to platforms: linux/amd64, linux/arm64
2024-05-08 11:02:11 -03:00
Davidson Gomes
3ae8cf32b0 Merge pull request #584 from Al1st1c/fix/swagger-auth
Fix/swagger auth
2024-05-08 09:56:59 -03:00
Davidson Gomes
11cf947bbb Merge pull request #583 from deivisonrpg/chore-update-aws-sdk-v3
chore(aws sqs): update aws sdk v3
2024-05-08 09:56:24 -03:00
Davidson Gomes
60a20f61af Merge pull request #582 from deivisonrpg/hotfix-getOpenConversationByContact
fix(chatwoot): getOpenConversationByContact and init queries error
2024-05-08 09:55:08 -03:00
Davidson Gomes
e65c7b6bcf Merge pull request #577 from neanderdev/mark-chat-as-unread
feat: method to mark chat as unread
2024-05-08 09:54:37 -03:00
Al1stic
80c892aca3 fix env 2024-05-06 19:31:37 -03:00
dev2
39ee266598 fix: correcao swagger sem authkey 2024-05-06 19:28:57 -03:00
Deivison Lincoln
aa58d7744e chore: update AWS SDK dependency to version 3.569.0 2024-05-06 17:28:41 -03:00
Deivison Lincoln
ea3b0b3712 fix: optimize ChatwootService method for retrieving open conversations 2024-05-06 16:30:16 -03:00
Deivison Lincoln
d9d8707123 chore: update baileys to version 6.7.2 2024-05-06 16:29:37 -03:00
Neander de Souza
8e9a1e2ba5 feat: method to mark chat as unread 2024-05-06 09:08:36 -03:00
Davidson Gomes
e29b4865e8 update baileys 2024-05-01 19:20:40 -03:00
@milesibastos
4b60ca175d chore: build docker image to platforms: linux/amd64,linux/arm64 2024-04-30 17:48:35 -03:00
Davidson Gomes
2fbbc7b5a9 Merge tag '1.7.4' into develop
v
2024-04-28 09:47:24 -03:00
Davidson Gomes
633dbb82d3 Merge branch 'release/1.7.4' 2024-04-28 09:47:19 -03:00
Davidson Gomes
95907b3cea v 1.7.4 2024-04-28 09:47:06 -03:00
Davidson Gomes
14c210c771 fix: new version baileys 2024-04-28 09:41:22 -03:00
Davidson Gomes
00e7fcc46b changelog 2024-04-27 13:13:43 -03:00
Davidson Gomes
720efcbcbf Merge pull request #566 from judsonjuniorr/feat/cw-inbox-name
Chatwoot inbox name
2024-04-27 13:13:06 -03:00
Davidson Gomes
d95791cc18 changelog 2024-04-27 13:12:29 -03:00
Davidson Gomes
d45b7af3b6 fix: recovering messages 2024-04-27 13:11:33 -03:00
Davidson Gomes
0ad3acaf07 Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop 2024-04-24 18:55:49 -03:00
Davidson Gomes
e27818ecda adjusts in integration 2024-04-24 18:55:38 -03:00
Davidson Gomes
ff21cf4d4c Merge pull request #558 from jaison-x/pr2
feat(chatwoot): send private message on error message sent from chatwoot
2024-04-23 19:11:10 -03:00
Davidson Gomes
dc19c7fdec Merge pull request #555 from jaison-x/pr
fix(chatwoot): fix bug when chatwoot params reopen_conversation and conversation_pending are enabled
2024-04-23 19:10:57 -03:00
jaison-x
6c8ffd8ec6 feat(chatwoot): send private message on error message sent from chatwoot 2024-04-23 17:26:22 -03:00
jaison-x
96fdb210be feat(chatwoot): send private message on error message sent from chatwoot 2024-04-23 17:15:41 -03:00
jaison-x
84ad8e0d6e feat(chatwoot): send private message on error message sent from chatwoot 2024-04-23 15:09:28 -03:00
Davidson Gomes
53361682f4 Recovering messages 2024-04-23 08:01:59 -03:00
jaison-x
0ee243f284 fix(chatwoot): fix bug when chatwoot params reopen_conversation and conversation_pending are enabled 2024-04-22 13:41:06 -03:00
Judson Cairo
26ff0b634f Revert "Update current inbox if exists"
This reverts commit f44ab0f678.
2024-04-21 16:49:15 -03:00
Judson Cairo
f44ab0f678 Update current inbox if exists 2024-04-21 16:46:49 -03:00
Judson Cairo
1f128747bb Fix inbox name on cw config 2024-04-21 16:37:27 -03:00
Judson Cairo
3bf975d90f Set chatwoot custom inbox name 2024-04-21 16:33:20 -03:00
Davidson Gomes
92f8951be4 Merge tag '2.3.9' into develop
v
2024-04-18 21:24:30 -03:00
Davidson Gomes
e071f56767 Merge branch 'release/2.3.9' 2024-04-18 21:24:27 -03:00
Davidson Gomes
c85619efcf fix: Recovering messages lost with redis cache 2024-04-18 17:33:09 -03:00
Davidson Gomes
27f9ae1e56 fix: Recovering messages lost with redis cache 2024-04-18 17:31:10 -03:00
Davidson Gomes
7449102d95 fix: Recovering messages lost with redis cache 2024-04-18 17:31:05 -03:00
Davidson Gomes
234a2c71b5 Merge pull request #543 from PauloAK/history-set-message-status
Adicionado message.status ao webhook MESSAGES_SET
2024-04-18 16:05:44 -03:00
Davidson Gomes
4dd5533202 fix: Adjusts in proxy on fetchAgent 2024-04-18 12:54:00 -03:00
Davidson Gomes
a4d1740754 fix: Adjusts in proxy on fetchAgent 2024-04-18 12:53:55 -03:00
Davidson Gomes
1a2ea1c38a Merge tag '1.7.3' into develop
* Revert fix audio encoding
* Recovering messages lost with redis cache
* Adjusts in redis for save instances
* Adjusts in proxy
* Revert pull request #523
* Added instance name on logs
* Added support for Spanish
* Fix error: invalid operator. The allowed operators for identifier are equal_to,not_equal_to in chatwoot
2024-04-18 12:12:40 -03:00
Davidson Gomes
371ec9b8d5 Merge branch 'release/1.7.3' 2024-04-18 12:12:27 -03:00
Davidson Gomes
5e288d57ea changelog 2024-04-18 12:12:11 -03:00
Davidson Gomes
61bd5b3484 fix: Adjusts in redis for save instances 2024-04-18 10:39:24 -03:00
Paulo Kramer
bb974e10f5 Added message status to the messaging-history.set 2024-04-18 01:34:52 -03:00
Davidson Gomes
4ed1335f89 changelog 2024-04-17 19:58:31 -03:00
Davidson Gomes
4274c7afdb Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop 2024-04-17 18:48:11 -03:00
Davidson Gomes
27f67142c8 changelog 2024-04-17 18:46:50 -03:00
Davidson Gomes
ac8aba6ba4 Merge pull request #542 from nestordavalos/develop
 feat: add support for Spanish
2024-04-17 18:45:38 -03:00
Davidson Gomes
07ff61c070 changelog 2024-04-17 18:25:35 -03:00
nestordavalos
3645ac6704 Merge branch 'develop' of https://github.com/EvolutionAPI/evolution-api into develop 2024-04-17 17:20:42 -04:00
nestordavalos
9764719245 feat: add support for Spanish 2024-04-17 17:20:37 -04:00
Davidson Gomes
b3aeed7fc1 fix: retry messages 2024-04-17 18:14:11 -03:00
Davidson Gomes
5ae5d8546e fix: retry messages 2024-04-17 18:10:43 -03:00
Davidson Gomes
d190d8b1af Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop 2024-04-17 12:43:55 -03:00
Davidson Gomes
c45538684d fix: fix audio encoding 2024-04-17 12:43:49 -03:00
Davidson Gomes
575e7bf4c4 Merge pull request #539 from jaison-x/pr2
fix: this.localProxy.proxy can be undefined
2024-04-17 12:08:54 -03:00
jaison-x
a4338d8472 fix: this.localProxy.proxy can be undefined 2024-04-17 11:03:55 -03:00
Davidson Gomes
7d542cf115 Merge pull request #538 from jaison-x/pr
fix(chatwoot): error: invalid operator. The allowed operators for identifier are [equal_to,not_equal_to]
2024-04-17 11:03:35 -03:00
jaison-x
9c9a542bbe fix(chatwoot): error: invalid operator. The allowed operators for identifier are [equal_to,not_equal_to]
In chatwoot version 3.8 we can't use the filter operator 'contains' for the field 'identifier'
2024-04-17 10:50:25 -03:00
Davidson Gomes
b6c56551bc fix: Revert pull request #523 2024-04-16 19:13:25 -03:00
Davidson Gomes
1379228196 fix: Revert pull request #523 2024-04-16 19:12:03 -03:00
Davidson Gomes
d6e19b9273 adjusts in v1.7.3 2024-04-16 19:08:44 -03:00
Davidson Gomes
5e0e4051dc Merge tag '1.7.2' into develop
* Mobile connection via sms (test)

* Adjusts in redis
* Send global event in websocket
* Adjusts in proxy
* Fix audio encoding
* Fix conversation read on chatwoot version 3.7
* Fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled
* Changed returned sessions on typebot status change
* Reorganization of files and folders
2024-04-12 17:32:30 -03:00
Davidson Gomes
8caf3a0a7b Merge branch 'release/1.7.2' 2024-04-12 17:32:18 -03:00
Davidson Gomes
96ae97664c v 1.7.2 2024-04-12 17:31:58 -03:00
Davidson Gomes
901b121695 fix: reorganization of files and folders 2024-04-12 17:28:02 -03:00
Davidson Gomes
3e88c9f0c7 fix: reorganization of files and folders 2024-04-12 17:23:28 -03:00
Davidson Gomes
94f5c130bf fix: reorganization of files and folders 2024-04-12 17:22:11 -03:00
Davidson Gomes
eb04c3f113 fix: reorganization of files and folders 2024-04-12 17:15:13 -03:00
Davidson Gomes
8ece6fb998 fix: reorganization of files and folders 2024-04-12 17:13:15 -03:00
Davidson Gomes
794213b5c6 fix: quoted messages 2024-04-12 15:53:06 -03:00
Davidson Gomes
ef4a9ab66b fix: retry messages 2024-04-12 15:11:04 -03:00
Davidson Gomes
86e978faad fix: send contact.upsert via webhook 2024-04-12 12:51:13 -03:00
Davidson Gomes
d5d8f2a318 fix: send contact.upsert via webhook 2024-04-12 12:33:31 -03:00
Davidson Gomes
4ca1fad335 Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop 2024-04-12 12:00:24 -03:00
Davidson Gomes
0edf6bdcb1 fix: audio encoding 2024-04-12 12:00:14 -03:00
Davidson Gomes
c2839ddd56 Merge pull request #528 from jaison-x/pr
fix(chatwoot): fix conversation read on chatwoot version 3.7
2024-04-12 11:48:37 -03:00
jaison-x
28581f88b2 fix(chatwoot): fix conversation read on chatwoot version 3.7
if contact has more than one conversation, we could get the wrong conversation.
2024-04-12 11:30:19 -03:00
Davidson Gomes
833c625d18 Merge pull request #527 from jaison-x/pr
fix(chatwoot): fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled
2024-04-12 11:22:13 -03:00
Davidson Gomes
6e2a3a410a fix: audio encoding 2024-04-12 11:20:18 -03:00
jaison-x
3e85af9589 fix(chatwoot): fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled 2024-04-12 10:59:28 -03:00
Davidson Gomes
589dec52a3 ajustes proxy 2024-04-09 16:52:22 -03:00
Davidson Gomes
a5477509bd adjusts in redis 2024-04-09 07:43:20 -03:00
Davidson Gomes
5d951a96b5 adjusts in redis 2024-04-09 07:40:45 -03:00
Davidson Gomes
76552f6ae5 Merge branch 'develop' of github.com:EvolutionAPI/evolution-api into develop 2024-04-09 07:31:46 -03:00
Davidson Gomes
e153515847 adjusts in redis 2024-04-09 07:31:37 -03:00
Davidson Gomes
3bc692d894 adjusts in redis 2024-04-09 07:30:15 -03:00
Davidson Gomes
73360d66cd Merge pull request #523 from gabrielgranado/main
changed returned sessions on typebot status change
2024-04-09 06:46:24 -03:00
Davidson Gomes
04575d8051 adjusts in websocket 2024-04-09 06:44:59 -03:00
Joao Gabriel
9aba51cb45 changed returned sessions on typebot status change 2024-04-08 22:55:12 -03:00
Davidson Gomes
1172b6c871 mobile connection 2024-04-08 19:09:59 -03:00
Davidson Gomes
240f01f378 Merge tag '1.7.1' into develop
v
2024-04-03 10:45:55 -03:00
157 changed files with 3275 additions and 1510 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -1,38 +0,0 @@
---
name: "[EN] Bug report"
about: Create a report to help us improve
title: "[EN][BUG]"
labels: bug
assignees: ''
---
### Title: [Brief Description of the Bug]
#### Description:
Describe in detail the problem you encountered. Include any relevant context that may help understand the origin of the bug.
#### Steps to Reproduce:
1. List the steps necessary to reproduce the problem.
2. Try to be as specific as possible.
3. If the problem occurs in a specific scenario, describe it here.
#### Expected Behavior:
Describe what you expected to happen when following the steps above.
#### Current Behavior:
Explain what actually happens when you follow the steps above.
#### Screenshots/Videos:
If possible, add screenshots or videos illustrating the problem. This can be extremely helpful in understanding the issue.
#### Environment:
- **Server:** [e.g., Ubuntu 18.04]
- **API Version:** [e.g., 1.5.4]
- **Other Hardware/Software Specifications:** [e.g., CPU, GPU]
#### Submitting Logs:
Please attach logs that may be related to the problem. If the logs contain sensitive information, consider sending them privately to one of the project maintainers.
#### Additional Notes:
Include here any other information that you think might be useful in understanding or resolving the bug.

View File

@@ -0,0 +1,107 @@
name: Bug Report
description: Create a report to help us improve.
labels:
- bug
- en
# - help wanted
# Automatically assign the issue to:
# assignees: DavidsonGomes
body:
- type: checkboxes
id: terms
attributes:
label: Welcome!
description: |
The issue tracker is only for reporting bugs and feature requests.
For user-related support questions, please visit:
- [Discord](https://evolution-api.com/discord)
- [WhatsApp Group](https://evolution-api.com/whatsapp)
<br/>
**DO NOT OPEN AN ISSUE FOR GENERAL SUPPORT QUESTIONS.**
options:
- label: Yes, I have searched for similar issues on [GitHub](https://github.com/EvolutionAPI/evolution-api/issues) and found none.
required: true
- type: textarea
attributes:
label: What did you do?
description: |
How to write a good bug report?
- Respect the issue template as much as possible.
- The title should be short and descriptive.
- Explain the conditions that led you to report this issue: the context.
- The context should lead to something, an idea or problem you are facing.
- Be clear and concise.
- Format your messages to help the reader focus on what matters and understand the structure of your message, use [Markdown syntax](https://help.github.com/articles/github-flavored-markdown)
placeholder: Describe the problem you encountered in detail.
validations:
required: true
- type: textarea
attributes:
label: What did you expect?
placeholder: Describe what you expected to happen.
validations:
required: true
- type: textarea
attributes:
label: What did you observe instead of what you expected?
placeholder: Explain what actually happens when you follow the steps above.
validations:
required: true
- type: textarea
attributes:
label: Screenshots/Videos
placeholder: |
If possible, add screenshots or videos that illustrate the problem. This can be extremely helpful in understanding the issue better.
- type: textarea
attributes:
label: Which version of the API are you using?
description: |
Enter the version number found in the `version` property of the **package.json**.
placeholder: Paste the version here.
validations:
required: true
- type: dropdown
id: select
attributes:
label: What is your environment?
options:
- Windows
- Linux
- Mac
- Docker
- Other
validations:
required: true
- type: textarea
attributes:
label: Other environment specifications
placeholder: 'Hardware/Software: [e.g., CPU, GPU]'
validations:
required: false
- type: textarea
attributes:
label: If applicable, paste the log output
description: |
Please attach any logs that might be related to the issue.
If the logs contain sensitive information, consider sending them privately to one of the project maintainers.
placeholder: Paste the application log here.
validations:
required: false
- type: textarea
attributes:
label: Additional Notes
description: Include any other information you think might be useful to understand or resolve the bug.
validations:
required: false

View File

@@ -1,28 +0,0 @@
---
name: "[EN] Feature request"
about: Suggest an idea for the API
title: "[EN][FEAT]"
labels: enhancement
assignees: ''
---
### Title: [Brief Description of Feature Request]
#### Detailed Description:
Clearly and in detail, describe the functionality you wish to be implemented. Explain how this fits into the context of the project.
#### Rationale:
Explain why this functionality would be useful for the project. This helps in understanding the importance and priority of the request.
#### Usage Examples:
Provide specific examples of how this feature could be used. This can include scenarios or use cases where the feature would be particularly beneficial.
#### Possible Implementations:
If you have ideas on how this feature might be implemented, please share them here. This is not mandatory but can be helpful for the development team.
#### Impact on the Project:
Discuss how this new feature could impact other parts of the project, if applicable.
#### Additional Notes:
Any other information you believe is relevant to your request.

View File

@@ -0,0 +1,86 @@
name: Feature Request
description: Suggest ideas for the project.
labels:
- enhancement
- en
# Automatically assign the issue to:
# assignees: DavidsonGomes
body:
- type: checkboxes
id: terms
attributes:
label: Welcome!
description: '**DO NOT OPEN FOR GENERAL SUPPORT QUESTIONS.**'
options:
- label: Yes, I have searched for similar requests on [GitHub](https://github.com/code-chat-br/whatsapp-api/issues) and found none.
required: true
- type: dropdown
attributes:
label: What type of feature?
description: |
How to write a good feature request?
- Respect the issue template as much as possible.
- The title should be short and descriptive.
- Explain the conditions that led you to suggest this feature: the context.
- The context should lead to something, an idea or problem you are facing.
- Be clear and concise.
- Format your messages to help the reader focus on what matters and understand the structure of your message, use [Markdown syntax](https://help.github.com/articles/github-flavored-markdown)
options:
- Integration
- Functionality
- Endpoint
- Database adjustment
- Other
validations:
required: true
- type: textarea
attributes:
label: What is the motivation for the request?
description: |
What problem does the feature seek to solve?
Clearly and in detail describe the functionality you want to be implemented.
Explain how it fits into the context of the project.
placeholder: Detailed description
validations:
required: true
- type: textarea
attributes:
label: Usage Examples
description: |
Provide specific examples of how this functionality could be used.
This can include scenarios or use cases where the feature would be particularly beneficial.
placeholder: text - image - video - flowcharts
validations:
required: false
- type: textarea
attributes:
label: How should the feature be developed?
description: |
Should it be inserted directly into the code?
Should it be built as a different application that acts as an extension of the API?
For example: a `worker`?
Discuss how this new functionality could impact other parts of the project, if applicable.
---
If you have ideas on how this functionality could be implemented, please share them here.
This is not mandatory, but it can be helpful for the development team.
placeholder: Insert feature ideas here
validations:
required: false
- type: textarea
attributes:
label: Additional Notes
description: Any other information you believe is relevant to your request.
placeholder: Insert your observations here.
validations:
required: false

View File

@@ -1,38 +0,0 @@
---
name: "[PT] Reportar bug"
about: Reportar um problema
title: "[PT][BUG]"
labels: bug
assignees: ''
---
### Título: [Breve Descrição do Bug]
#### Descrição:
Descreva detalhadamente o problema que você encontrou. Inclua qualquer contexto relevante que possa ajudar a entender a origem do bug.
#### Passos para Reproduzir:
1. Liste os passos necessários para reproduzir o problema.
2. Tente ser o mais específico possível.
3. Se o problema ocorrer em um cenário específico, descreva-o aqui.
#### Comportamento Esperado:
Descreva o que você esperava que acontecesse quando seguisse os passos acima.
#### Comportamento Atual:
Explique o que realmente acontece quando você segue os passos acima.
#### Capturas de Tela/Vídeos:
Se possível, adicione capturas de tela ou vídeos que ilustrem o problema. Isso pode ser extremamente útil para entender o problema.
#### Ambiente:
- **Servidor:** [ex: Ubuntu 18.04]
- **Versão da API:** [ex: 1.5.4]
- **Outras Especificações de Hardware/Software:** [ex: CPU, GPU]
#### Envio de Logs:
Por favor, anexe os logs que possam estar relacionados ao problema. Se os logs contiverem informações sensíveis, considere enviá-los de forma privada para um dos mantenedores do projeto.
#### Notas Adicionais:
Inclua aqui qualquer outra informação que você ache que possa ser útil para entender ou resolver o bug.

View File

@@ -0,0 +1,108 @@
name: Relatório de bug
description: Crie um relatório para nos ajudar a melhorar.
labels:
- bug
- pt-br
# - help wanted
# Atrubuir automaticamente a issue a:
# assignees: DavidsonGomes
body:
- type: checkboxes
id: termos
attributes:
label: Bem-vido!
description: |
O rastreador de problemas é apenas para relatar bugs e solicitações de recursos.
Para perguntas de suporte relacionadas ao usuário final, acesse:
- [Discord](https://evolution-api.com/discord)
- [Grupo do WhatsApp](https://evolution-api.com/whatsapp)
<br/>
**NÃO ABRA UM PROBLEMA PARA PERGUNTAS GERAIS DE SUPORTE.**
options:
- label: Sim, pesquisei problemas semelhantes no [GitHub](https://github.com/EvolutionAPI/evolution-api/issues) e não encontrei nenhum.
required: true
- type: textarea
attributes:
label: O que você fez?
description: |
Como escrever um bom relatório de bug?
- Respeite o modelo de problema tanto quanto possível.
- O título deve ser curto e descritivo.
- Explique as condições que o levaram a reportar este problema: o contexto.
- O contexto deve levar a algo, ideia ou problema que você está enfrentando.
- Seja claro e conciso.
- Formate suas mensagens para ajudar o leitor a se concentrar no que importa e entender a estrutura da sua mensagem, use [sintaxe Markdown](https://help.github.com/articles/github-flavored-markdown)
placeholder: Descreva detalhadamente o problema que você encontrou.
validations:
required: true
- type: textarea
attributes:
label: O que você esperava?
placeholder: Descreva o que você esperava que acontecesse.
validations:
required: true
- type: textarea
attributes:
label: O que vc observou ao invés do que esperava?
placeholder: Explique o que realmente acontece quando você segue os passos acima.
validations:
required: true
- type: textarea
attributes:
label: Capturas de Tela/Vídeos
placeholder: |
Se possível, adicione capturas de tela ou vídeos que ilustrem o problema. Isso pode ser extremamente útil para entender melhor o problema.
- type: textarea
attributes:
label: Qual versão da API você está usando?
description: |
Insira o número da sua versão que está na propriedade `version` do **package.json**.
placeholder: Cole aqui a versão.
validations:
required: true
- type: dropdown
id: select
attributes:
label: Qual é o seu ambiente?
options:
- Windows
- Linux
- Mac
- Docker
- Outro
validations:
required: true
- type: textarea
attributes:
label: Outras expecificações do ambiente
placeholder: 'Hardware/Software: [ex: CPU, GPU]'
validations:
required: false
- type: textarea
attributes:
label: Se aplicável, cole a saída do log
description: |
Por favor, anexe os logs que possam estar relacionados ao problema.
Se os logs contiverem informações sensíveis, considere enviá-los de forma privada para um dos mantenedores do projeto.
placeholder: Cole aqui o log da aplicação
validations:
required: false
- type: textarea
attributes:
label: Notas Adicionais
description: Inclua aqui qualquer outra informação que você ache que possa ser útil para entender ou resolver o bug.
validations:
required: false

View File

@@ -1,28 +0,0 @@
---
name: "[PT] Solicitar recurso"
about: Sugira novos recursos para a API
title: "[PT][FEAT]"
labels: enhancement
assignees: ''
---
### Título: [Breve Descrição da Solicitação de Recurso]
#### Descrição Detalhada:
Descreva claramente e em detalhes a funcionalidade que você deseja que seja implementada. Explique como isso se encaixa no contexto do projeto.
#### Racional:
Explique por que essa funcionalidade seria útil para o projeto. Isso ajuda a entender a importância e a prioridade da solicitação.
#### Exemplos de Uso:
Forneça exemplos específicos de como essa funcionalidade poderia ser utilizada. Isso pode incluir cenários ou casos de uso onde a funcionalidade seria particularmente benéfica.
#### Possíveis Implementações:
Se você tem ideias sobre como essa funcionalidade pode ser implementada, por favor, compartilhe-as aqui. Isso não é obrigatório, mas pode ser útil para a equipe de desenvolvimento.
#### Impacto no Projeto:
Discuta como essa nova funcionalidade poderia impactar outras partes do projeto, se aplicável.
#### Notas Adicionais:
Qualquer outra informação que você acredita ser relevante para a sua solicitação.

View File

@@ -0,0 +1,86 @@
name: Solicitação de recursos
description: Sugira ideias para o projeto.
labels:
- enhancement
- pt-br
# Automatically assign the issue to:
# assignees: DavidsonGomes
body:
- type: checkboxes
id: termos
attributes:
label: Bem-vindo!
description: '**NÃO ABRA PARA PERGUNTAS GERAIS DE SUPORTE.**'
options:
- label: Sim, pesquisei solicitações semelhantes no [GitHub](https://github.com/code-chat-br/whatsapp-api/issues) e não encontrei nenhum.
required: true
- type: dropdown
attributes:
label: Qual tipo de recurso?
description: |
Como escrever uma boa solicitação de bug?
- Respeite o modelo de problema tanto quanto possível.
- O título deve ser curto e descritivo.
- Explique as condições que o levaram a reportar este problema: o contexto.
- O contexto deve levar a algo, ideia ou problema que você está enfrentando.
- Seja claro e conciso.
- Formate suas mensagens para ajudar o leitor a se concentrar no que importa e entender a estrutura da sua mensagem, use [sintaxe Markdown](https://help.github.com/articles/github-flavored-markdown)
options:
- Integração
- Funcionalidade
- Endpoint
- Ajuste de banco de dados
- Outro
validations:
required: true
- type: textarea
attributes:
label: Qual a motivação para a solicitação?
description: |
Qual problema o recurso busca resolver?
Descreva claramente e em detalhes a funcionalidade que você deseja que seja implementada.
Explique como isso se encaixa no contexto do projeto.
placeholder: Descrição detalhada
validations:
required: true
- type: textarea
attributes:
label: Exemplos de Uso
description: |
Forneça exemplos específicos de como essa funcionalidade poderia ser utilizada.
Isso pode incluir cenários ou casos de uso onde a funcionalidade seria particularmente benéfica.
placeholder: texto - imagem - video - fluxogramas
validations:
required: false
- type: textarea
attributes:
label: Como o recurso deve ser desenvolvido?
description: |
Deve ser inserido diretamente no código?
Deve ser construído uma aplicação diferente que atuará como uma extenção da api?
Por exemplo: um `worker`?
Discuta como essa nova funcionalidade poderia impactar outras partes do projeto, se aplicável.
---
Se você tem ideias sobre como essa funcionalidade pode ser implementada, por favor, compartilhe-as aqui.
Isso não é obrigatório, mas pode ser útil para a equipe de desenvolvimento.
placeholder: Insira ideias para o recurso
validations:
required: false
- type: textarea
attributes:
label: Notas Adicionais
description: Qualquer outra informação que você acredita ser relevante para a sua solicitação.
placeholder: Insira aqui as sua observções.
validations:
required: false

View File

@@ -2,63 +2,47 @@ name: Build Docker image
on: on:
push: push:
tags: ['v*'] tags:
- "*.*.*"
jobs: jobs:
build-amd: build_deploy:
name: Build and Deploy
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps: steps:
- name: Check out the repo - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Extract existing image metadata - name: Docker meta
id: image-meta id: meta
uses: docker/metadata-action@v4 uses: docker/metadata-action@v5
with: with:
images: atendai/evolution-api images: atendai/evolution-api
tags: type=semver,pattern=v{{version}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub - name: Login to GitHub Container Registry
uses: docker/login-action@v2 uses: docker/login-action@v3
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push AMD image - name: Build and push
uses: docker/build-push-action@v4 id: docker_build
uses: docker/build-push-action@v5
with: with:
context: . platforms: linux/amd64,linux/arm64
labels: ${{ steps.image-meta.outputs.labels }}
platforms: linux/amd64
push: true push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-arm: - name: Image digest
runs-on: buildjet-4vcpu-ubuntu-2204-arm run: echo ${{ steps.docker_build.outputs.digest }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Extract existing image metadata
id: image-meta
uses: docker/metadata-action@v4
with:
images: atendai/evolution-api
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push ARM image
uses: docker/build-push-action@v4
with:
context: .
labels: ${{ steps.image-meta.outputs.labels }}
platforms: linux/arm64
push: true

View File

@@ -0,0 +1,48 @@
name: Build Docker image
on:
push:
branches:
- develop
jobs:
build_deploy:
name: Build and Deploy
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: atendai/evolution-api
tags: homolog
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

View File

@@ -0,0 +1,48 @@
name: Build Docker image
on:
push:
branches:
- main
jobs:
build_deploy:
name: Build and Deploy
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: atendai/evolution-api
tags: latest
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

View File

@@ -0,0 +1,48 @@
name: Build Docker image
on:
push:
branches:
- v2.0.0
jobs:
build_deploy:
name: Build and Deploy
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: atendai/evolution-api
tags: v2.0.0-alpha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

View File

@@ -1,3 +1,88 @@
# 1.8.2 (2024-07-03 13:50)
### Fixed
* Corretion in globall rabbitmq queue name
* Improvement in the use of mongodb database for credentials
* Fixed base64 in webhook for documentWithCaption
* Fixed Generate pairing code
# 1.8.1 (2024-06-08 21:32)
### Feature
* New method of saving sessions to a file using worker, made in partnership with [codechat](https://github.com/code-chat-br/whatsapp-api)
### Fixed
* Correction of variables breaking lines in typebot
# 1.8.0 (2024-05-27 16:10)
### Feature
* Now in the manager, when logging in with the client's apikey, the listing only shows the instance corresponding to the provided apikey (only with MongoDB)
* New global mode for rabbitmq events
* Build in docker for linux/amd64, linux/arm64 platforms
### Fixed
* Correction in message formatting when generated by AI as markdown in typebot
* Security fix in fetch instance with client key when not connected to mongodb
# 1.7.5 (2024-05-21 08:50)
### Fixed
* Add merge_brazil_contacts function to solve nine digit in brazilian numbers
* Optimize ChatwootService method for updating contact
* Fix swagger auth
* Update aws sdk v3
* Fix getOpenConversationByContact and init queries error
* Method to mark chat as unread
* Added environment variable to manually select the WhatsApp web version for the baileys lib (optional)
# 1.7.4 (2024-04-28 09:46)
### Fixed
* Adjusts in proxy on fetchAgent
* Recovering messages lost with redis cache
* Log when init redis cache service
* Recovering messages lost with redis cache
* Chatwoot inbox name
* Update Baileys version
# 1.7.3 (2024-04-18 12:07)
### Fixed
* Revert fix audio encoding
* Recovering messages lost with redis cache
* Adjusts in redis for save instances
* Adjusts in proxy
* Revert pull request #523
* Added instance name on logs
* Added support for Spanish
* Fix error: invalid operator. The allowed operators for identifier are equal_to,not_equal_to in chatwoot
# 1.7.2 (2024-04-12 17:31)
### Feature
* Mobile connection via sms (test)
### Fixed
* Adjusts in redis
* Send global event in websocket
* Adjusts in proxy
* Fix audio encoding
* Fix conversation read on chatwoot version 3.7
* Fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled
* Changed returned sessions on typebot status change
* Reorganization of files and folders
# 1.7.1 (2024-04-03 10:19) # 1.7.1 (2024-04-03 10:19)
### Fixed ### Fixed

View File

@@ -43,16 +43,37 @@ DATABASE_SAVE_MESSAGE_UPDATE=false
DATABASE_SAVE_DATA_CONTACTS=false DATABASE_SAVE_DATA_CONTACTS=false
DATABASE_SAVE_DATA_CHATS=false DATABASE_SAVE_DATA_CHATS=false
REDIS_ENABLED=false
REDIS_URI=redis://redis:6379
REDIS_PREFIX_KEY=evdocker
RABBITMQ_ENABLED=false RABBITMQ_ENABLED=false
RABBITMQ_RABBITMQ_MODE=global
RABBITMQ_EXCHANGE_NAME=evolution_exchange
RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672 RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
RABBITMQ_EXCHANGE_NAME=evolution_exchange
RABBITMQ_GLOBAL_ENABLED=false
RABBITMQ_EVENTS_APPLICATION_STARTUP=false
RABBITMQ_EVENTS_QRCODE_UPDATED=true
RABBITMQ_EVENTS_MESSAGES_SET=true
RABBITMQ_EVENTS_MESSAGES_UPSERT=true
RABBITMQ_EVENTS_MESSAGES_UPDATE=true
RABBITMQ_EVENTS_MESSAGES_DELETE=true
RABBITMQ_EVENTS_SEND_MESSAGE=true
RABBITMQ_EVENTS_CONTACTS_SET=true
RABBITMQ_EVENTS_CONTACTS_UPSERT=true
RABBITMQ_EVENTS_CONTACTS_UPDATE=true
RABBITMQ_EVENTS_PRESENCE_UPDATE=true
RABBITMQ_EVENTS_CHATS_SET=true
RABBITMQ_EVENTS_CHATS_UPSERT=true
RABBITMQ_EVENTS_CHATS_UPDATE=true
RABBITMQ_EVENTS_CHATS_DELETE=true
RABBITMQ_EVENTS_GROUPS_UPSERT=true
RABBITMQ_EVENTS_GROUPS_UPDATE=true
RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
RABBITMQ_EVENTS_CONNECTION_UPDATE=true
RABBITMQ_EVENTS_LABELS_EDIT=true
RABBITMQ_EVENTS_LABELS_ASSOCIATION=true
RABBITMQ_EVENTS_CALL=true
RABBITMQ_EVENTS_TYPEBOT_START=false
RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS=false
WEBSOCKET_ENABLED=false WEBSOCKET_ENABLED=false
WEBSOCKET_GLOBAL_EVENTS=false
WA_BUSINESS_TOKEN_WEBHOOK=evolution WA_BUSINESS_TOKEN_WEBHOOK=evolution
WA_BUSINESS_URL=https://graph.facebook.com WA_BUSINESS_URL=https://graph.facebook.com
@@ -72,7 +93,7 @@ WEBHOOK_GLOBAL_URL=''
WEBHOOK_GLOBAL_ENABLED=false 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 # 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 WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
## Set the events you want to hear ## Set the events you want to hear
WEBHOOK_EVENTS_APPLICATION_STARTUP=false WEBHOOK_EVENTS_APPLICATION_STARTUP=false
WEBHOOK_EVENTS_QRCODE_UPDATED=true WEBHOOK_EVENTS_QRCODE_UPDATED=true
WEBHOOK_EVENTS_MESSAGES_SET=true WEBHOOK_EVENTS_MESSAGES_SET=true
@@ -113,7 +134,7 @@ CONFIG_SESSION_PHONE_NAME=Chrome
# Set qrcode display limit # Set qrcode display limit
QRCODE_LIMIT=30 QRCODE_LIMIT=30
QRCODE_COLOR=#198754 QRCODE_COLOR='#198754'
# old | latest # old | latest
TYPEBOT_API_VERSION=latest TYPEBOT_API_VERSION=latest
@@ -125,9 +146,17 @@ CHATWOOT_MESSAGE_DELETE=false # false | true
# If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp. # If you leave this option as true, when sending a message in Chatwoot, the client's last message will be marked as read on WhatsApp.
CHATWOOT_MESSAGE_READ=false # false | true CHATWOOT_MESSAGE_READ=false # false | true
# This db connection is used to import messages from whatsapp to chatwoot database # This db connection is used to import messages from whatsapp to chatwoot database
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname?sslmode=disable
CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE=true CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE=true
CACHE_REDIS_ENABLED=false
CACHE_REDIS_URI=redis://redis:6379
CACHE_REDIS_PREFIX_KEY=evolution
CACHE_REDIS_TTL=604800
CACHE_REDIS_SAVE_INSTANCES=false
CACHE_LOCAL_ENABLED=false
CACHE_LOCAL_TTL=604800
# Defines an authentication type for the api # Defines an authentication type for the api
# We recommend using the apikey because it will allow you to use a custom token, # 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 # if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
@@ -142,4 +171,4 @@ AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
AUTHENTICATION_JWT_EXPIRIN_IN=0 AUTHENTICATION_JWT_EXPIRIN_IN=0
AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`' AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
LANGUAGE=en # pt-BR, en LANGUAGE=en # pt-BR, en

View File

@@ -33,7 +33,10 @@ CLEAN_STORE_CHATS=true
# Permanent data storage # Permanent data storage
DATABASE_ENABLED=true DATABASE_ENABLED=true
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin &
readPreference=primary &
ssl=false &
directConnection=true
DATABASE_CONNECTION_DB_PREFIX_NAME=evolution DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
# Choose the data you want to save in the application's database or store # Choose the data you want to save in the application's database or store
@@ -43,10 +46,6 @@ DATABASE_SAVE_MESSAGE_UPDATE=false
DATABASE_SAVE_DATA_CONTACTS=false DATABASE_SAVE_DATA_CONTACTS=false
DATABASE_SAVE_DATA_CHATS=false DATABASE_SAVE_DATA_CHATS=false
REDIS_ENABLED=true
REDIS_URI=redis://redis:6379
REDIS_PREFIX_KEY=evolution
# Global Webhook Settings # Global Webhook Settings
# Each instance's Webhook URL and events will be requested at the time it is created # 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 ## Define a global webhook that will listen for enabled events from all instances
@@ -54,7 +53,7 @@ WEBHOOK_GLOBAL_URL=''
WEBHOOK_GLOBAL_ENABLED=false 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 # 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 WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
## Set the events you want to hear ## Set the events you want to hear
WEBHOOK_EVENTS_APPLICATION_STARTUP=false WEBHOOK_EVENTS_APPLICATION_STARTUP=false
WEBHOOK_EVENTS_QRCODE_UPDATED=true WEBHOOK_EVENTS_QRCODE_UPDATED=true
WEBHOOK_EVENTS_MESSAGES_SET=true WEBHOOK_EVENTS_MESSAGES_SET=true
@@ -87,6 +86,14 @@ CONFIG_SESSION_PHONE_NAME=chrome
# Set qrcode display limit # Set qrcode display limit
QRCODE_LIMIT=30 QRCODE_LIMIT=30
CACHE_REDIS_ENABLED=false
CACHE_REDIS_URI=redis://redis:6379
CACHE_REDIS_PREFIX_KEY=evolution
CACHE_REDIS_TTL=604800
CACHE_REDIS_SAVE_INSTANCES=false
CACHE_LOCAL_ENABLED=false
CACHE_LOCAL_TTL=604800
# Defines an authentication type for the api # Defines an authentication type for the api
# We recommend using the apikey because it will allow you to use a custom token, # 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 # if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
@@ -109,4 +116,4 @@ AUTHENTICATION_INSTANCE_NAME=evolution
AUTHENTICATION_INSTANCE_WEBHOOK_URL='' AUTHENTICATION_INSTANCE_WEBHOOK_URL=''
AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1 AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456 AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
AUTHENTICATION_INSTANCE_CHATWOOT_URL='' AUTHENTICATION_INSTANCE_CHATWOOT_URL=''

View File

@@ -1,6 +1,6 @@
FROM node:20.7.0-alpine AS builder FROM node:20.7.0-alpine AS builder
LABEL version="1.7.1" description="Api to control whatsapp features through http requests." LABEL version="1.8.0" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
LABEL contact="contato@agenciadgcode.com" LABEL contact="contato@agenciadgcode.com"
@@ -58,16 +58,39 @@ ENV DATABASE_SAVE_MESSAGE_UPDATE=false
ENV DATABASE_SAVE_DATA_CONTACTS=false ENV DATABASE_SAVE_DATA_CONTACTS=false
ENV DATABASE_SAVE_DATA_CHATS=false ENV DATABASE_SAVE_DATA_CHATS=false
ENV REDIS_ENABLED=false
ENV REDIS_URI=redis://redis:6379
ENV REDIS_PREFIX_KEY=evolution
ENV RABBITMQ_ENABLED=false ENV RABBITMQ_ENABLED=false
ENV RABBITMQ_MODE=global
ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672 ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
ENV RABBITMQ_GLOBAL_ENABLED=false
ENV RABBITMQ_EVENTS_APPLICATION_STARTUP=false
ENV RABBITMQ_EVENTS_INSTANCE_CREATE=false
ENV RABBITMQ_EVENTS_INSTANCE_DELETE=false
ENV RABBITMQ_EVENTS_QRCODE_UPDATED=true
ENV RABBITMQ_EVENTS_MESSAGES_SET=true
ENV RABBITMQ_EVENTS_MESSAGES_UPSERT=true
ENV RABBITMQ_EVENTS_MESSAGES_UPDATE=true
ENV RABBITMQ_EVENTS_MESSAGES_DELETE=true
ENV RABBITMQ_EVENTS_SEND_MESSAGE=true
ENV RABBITMQ_EVENTS_CONTACTS_SET=true
ENV RABBITMQ_EVENTS_CONTACTS_UPSERT=true
ENV RABBITMQ_EVENTS_CONTACTS_UPDATE=true
ENV RABBITMQ_EVENTS_PRESENCE_UPDATE=true
ENV RABBITMQ_EVENTS_CHATS_SET=true
ENV RABBITMQ_EVENTS_CHATS_UPSERT=true
ENV RABBITMQ_EVENTS_CHATS_UPDATE=true
ENV RABBITMQ_EVENTS_CHATS_DELETE=true
ENV RABBITMQ_EVENTS_GROUPS_UPSERT=true
ENV RABBITMQ_EVENTS_GROUPS_UPDATE=true
ENV RABBITMQ_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
ENV RABBITMQ_EVENTS_CONNECTION_UPDATE=true
ENV RABBITMQ_EVENTS_LABELS_EDIT=true
ENV RABBITMQ_EVENTS_LABELS_ASSOCIATION=true
ENV RABBITMQ_EVENTS_CALL=true
ENV RABBITMQ_EVENTS_TYPEBOT_START=false
ENV RABBITMQ_EVENTS_TYPEBOT_CHANGE_STATUS=false
ENV WEBSOCKET_ENABLED=false ENV WEBSOCKET_ENABLED=false
ENV WEBSOCKET_GLOBAL_EVENTS=false
ENV WA_BUSINESS_TOKEN_WEBHOOK=evolution ENV WA_BUSINESS_TOKEN_WEBHOOK=evolution
ENV WA_BUSINESS_URL=https://graph.facebook.com ENV WA_BUSINESS_URL=https://graph.facebook.com
@@ -128,6 +151,14 @@ ENV QRCODE_COLOR=#198754
ENV TYPEBOT_API_VERSION=latest ENV TYPEBOT_API_VERSION=latest
ENV CACHE_REDIS_ENABLED=false
ENV CACHE_REDIS_URI=redis://redis:6379
ENV CACHE_REDIS_PREFIX_KEY=evolution
ENV CACHE_REDIS_TTL=604800
ENV CACHE_REDIS_SAVE_INSTANCES=false
ENV CACHE_LOCAL_ENABLED=false
ENV CACHE_LOCAL_TTL=604800
ENV AUTHENTICATION_TYPE=apikey ENV AUTHENTICATION_TYPE=apikey
ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976 ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976

View File

@@ -1,6 +1,6 @@
{ {
"name": "evolution-api", "name": "evolution-api",
"version": "1.7.1", "version": "1.8.2",
"description": "Rest api for communication with WhatsApp", "description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js", "main": "./dist/src/main.js",
"scripts": { "scripts": {
@@ -46,10 +46,10 @@
"@figuro/chatwoot-sdk": "^1.1.16", "@figuro/chatwoot-sdk": "^1.1.16",
"@hapi/boom": "^10.0.1", "@hapi/boom": "^10.0.1",
"@sentry/node": "^7.59.2", "@sentry/node": "^7.59.2",
"@whiskeysockets/baileys": "6.6.0",
"amqplib": "^0.10.3", "amqplib": "^0.10.3",
"aws-sdk": "^2.1499.0", "@aws-sdk/client-sqs": "^3.569.0",
"axios": "^1.6.5", "axios": "^1.6.5",
"baileys": "github:EvolutionAPI/Baileys",
"class-validator": "^0.14.1", "class-validator": "^0.14.1",
"compression": "^1.7.4", "compression": "^1.7.4",
"cors": "^2.8.5", "cors": "^2.8.5",
@@ -60,6 +60,7 @@
"exiftool-vendored": "^22.0.0", "exiftool-vendored": "^22.0.0",
"express": "^4.18.2", "express": "^4.18.2",
"express-async-errors": "^3.1.1", "express-async-errors": "^3.1.1",
"fluent-ffmpeg": "^2.1.2",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"hbs": "^4.2.0", "hbs": "^4.2.0",
"https-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.2",

View File

@@ -1,13 +1,19 @@
export interface ICache { export interface ICache {
get(key: string): Promise<any>; get(key: string): Promise<any>;
hGet(key: string, field: string): Promise<any>;
set(key: string, value: any, ttl?: number): void; set(key: string, value: any, ttl?: number): void;
hSet(key: string, field: string, value: any): Promise<void>;
has(key: string): Promise<boolean>; has(key: string): Promise<boolean>;
keys(appendCriteria?: string): Promise<string[]>; keys(appendCriteria?: string): Promise<string[]>;
delete(key: string | string[]): Promise<number>; delete(key: string | string[]): Promise<number>;
hDelete(key: string, field: string): Promise<any>;
deleteAll(appendCriteria?: string): Promise<number>; deleteAll(appendCriteria?: string): Promise<number>;
} }

View File

@@ -4,6 +4,7 @@ import {
BlockUserDto, BlockUserDto,
DeleteMessage, DeleteMessage,
getBase64FromMediaMessageDto, getBase64FromMediaMessageDto,
MarkChatUnreadDto,
NumberDto, NumberDto,
PrivacySettingDto, PrivacySettingDto,
ProfileNameDto, ProfileNameDto,
@@ -40,6 +41,11 @@ export class ChatController {
return await this.waMonitor.waInstances[instanceName].archiveChat(data); return await this.waMonitor.waInstances[instanceName].archiveChat(data);
} }
public async markChatUnread({ instanceName }: InstanceDto, data: MarkChatUnreadDto) {
logger.verbose('requested markChatUnread from ' + instanceName + ' instance');
return await this.waMonitor.waInstances[instanceName].markChatUnread(data);
}
public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) { public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) {
logger.verbose('requested deleteMessage from ' + instanceName + ' instance'); logger.verbose('requested deleteMessage from ' + instanceName + ' instance');
return await this.waMonitor.waInstances[instanceName].deleteMessage(data); return await this.waMonitor.waInstances[instanceName].deleteMessage(data);

View File

@@ -1,28 +1,29 @@
import { delay } from '@whiskeysockets/baileys'; import { delay } from 'baileys';
import { isURL } from 'class-validator'; import { isURL } from 'class-validator';
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from 'eventemitter2';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
import { ConfigService, HttpServer, WaBusiness } from '../../config/env.config'; import { Auth, ConfigService, HttpServer, WaBusiness } from '../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../config/logger.config';
import { BadRequestException, InternalServerErrorException } from '../../exceptions'; import { BadRequestException, InternalServerErrorException, UnauthorizedException } from '../../exceptions';
import { RedisCache } from '../../libs/redis.client';
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto'; import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service';
import { SqsService } from '../integrations/sqs/services/sqs.service';
import { TypebotService } from '../integrations/typebot/services/typebot.service';
import { WebsocketService } from '../integrations/websocket/services/websocket.service';
import { ProviderFiles } from '../provider/sessions';
import { RepositoryBroker } from '../repository/repository.manager'; import { RepositoryBroker } from '../repository/repository.manager';
import { AuthService, OldToken } from '../services/auth.service'; import { AuthService, OldToken } from '../services/auth.service';
import { CacheService } from '../services/cache.service'; import { CacheService } from '../services/cache.service';
import { ChatwootService } from '../services/chatwoot.service'; import { BaileysStartupService } from '../services/channels/whatsapp.baileys.service';
import { BusinessStartupService } from '../services/channels/whatsapp.business.service';
import { IntegrationService } from '../services/integration.service'; import { IntegrationService } from '../services/integration.service';
import { WAMonitoringService } from '../services/monitor.service'; import { WAMonitoringService } from '../services/monitor.service';
import { RabbitmqService } from '../services/rabbitmq.service';
import { SettingsService } from '../services/settings.service'; import { SettingsService } from '../services/settings.service';
import { SqsService } from '../services/sqs.service';
import { TypebotService } from '../services/typebot.service';
import { WebhookService } from '../services/webhook.service'; import { WebhookService } from '../services/webhook.service';
import { WebsocketService } from '../services/websocket.service';
import { BaileysStartupService } from '../services/whatsapp.baileys.service';
import { BusinessStartupService } from '../services/whatsapp.business.service';
import { Events, Integration, wa } from '../types/wa.types'; import { Events, Integration, wa } from '../types/wa.types';
import { ProxyController } from './proxy.controller';
export class InstanceController { export class InstanceController {
constructor( constructor(
@@ -39,8 +40,11 @@ export class InstanceController {
private readonly sqsService: SqsService, private readonly sqsService: SqsService,
private readonly typebotService: TypebotService, private readonly typebotService: TypebotService,
private readonly integrationService: IntegrationService, private readonly integrationService: IntegrationService,
private readonly cache: RedisCache, private readonly proxyService: ProxyController,
private readonly cache: CacheService,
private readonly chatwootCache: CacheService, private readonly chatwootCache: CacheService,
private readonly baileysCache: CacheService,
private readonly providerFiles: ProviderFiles,
) {} ) {}
private readonly logger = new Logger(InstanceController.name); private readonly logger = new Logger(InstanceController.name);
@@ -53,6 +57,7 @@ export class InstanceController {
events, events,
qrcode, qrcode,
number, number,
mobile,
integration, integration,
token, token,
chatwoot_account_id, chatwoot_account_id,
@@ -62,6 +67,8 @@ export class InstanceController {
chatwoot_reopen_conversation, chatwoot_reopen_conversation,
chatwoot_conversation_pending, chatwoot_conversation_pending,
chatwoot_import_contacts, chatwoot_import_contacts,
chatwoot_name_inbox,
chatwoot_merge_brazil_contacts,
chatwoot_import_messages, chatwoot_import_messages,
chatwoot_days_limit_import_messages, chatwoot_days_limit_import_messages,
reject_call, reject_call,
@@ -84,6 +91,7 @@ export class InstanceController {
typebot_delay_message, typebot_delay_message,
typebot_unknown_message, typebot_unknown_message,
typebot_listening_from_me, typebot_listening_from_me,
proxy,
}: InstanceDto) { }: InstanceDto) {
try { try {
this.logger.verbose('requested createInstance from ' + instanceName + ' instance'); this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
@@ -104,6 +112,8 @@ export class InstanceController {
this.repository, this.repository,
this.cache, this.cache,
this.chatwootCache, this.chatwootCache,
this.baileysCache,
this.providerFiles,
); );
} else { } else {
instance = new BaileysStartupService( instance = new BaileysStartupService(
@@ -112,10 +122,12 @@ export class InstanceController {
this.repository, this.repository,
this.cache, this.cache,
this.chatwootCache, this.chatwootCache,
this.baileysCache,
this.providerFiles,
); );
} }
await this.waMonitor.saveInstance({ integration, instanceName, token, number }); await this.waMonitor.saveInstance({ integration, instanceName, token, number, mobile });
instance.instanceName = instanceName; instance.instanceName = instanceName;
@@ -345,6 +357,18 @@ export class InstanceController {
} }
} }
if (proxy) {
const testProxy = await this.proxyService.testProxy(proxy);
if (!testProxy) {
throw new BadRequestException('Invalid proxy');
}
await this.proxyService.createProxy(instance, {
enabled: true,
proxy,
});
}
if (typebot_url) { if (typebot_url) {
try { try {
if (!isURL(typebot_url, { require_tld: false })) { if (!isURL(typebot_url, { require_tld: false })) {
@@ -405,7 +429,7 @@ export class InstanceController {
if (qrcode) { if (qrcode) {
this.logger.verbose('creating qrcode'); this.logger.verbose('creating qrcode');
await instance.connectToWhatsapp(number); await instance.connectToWhatsapp(number, mobile);
await delay(5000); await delay(5000);
getQrcode = instance.qrCode; getQrcode = instance.qrCode;
} }
@@ -495,11 +519,12 @@ export class InstanceController {
token: chatwoot_token, token: chatwoot_token,
url: chatwoot_url, url: chatwoot_url,
sign_msg: chatwoot_sign_msg || false, sign_msg: chatwoot_sign_msg || false,
name_inbox: instance.instanceName.split('-cwId-')[0], name_inbox: chatwoot_name_inbox ?? instance.instanceName.split('-cwId-')[0],
number, number,
reopen_conversation: chatwoot_reopen_conversation || false, reopen_conversation: chatwoot_reopen_conversation || false,
conversation_pending: chatwoot_conversation_pending || false, conversation_pending: chatwoot_conversation_pending || false,
import_contacts: chatwoot_import_contacts ?? true, import_contacts: chatwoot_import_contacts ?? true,
merge_brazil_contacts: chatwoot_merge_brazil_contacts ?? false,
import_messages: chatwoot_import_messages ?? true, import_messages: chatwoot_import_messages ?? true,
days_limit_import_messages: chatwoot_days_limit_import_messages ?? 60, days_limit_import_messages: chatwoot_days_limit_import_messages ?? 60,
auto_create: true, auto_create: true,
@@ -555,11 +580,12 @@ export class InstanceController {
sign_msg: chatwoot_sign_msg || false, sign_msg: chatwoot_sign_msg || false,
reopen_conversation: chatwoot_reopen_conversation || false, reopen_conversation: chatwoot_reopen_conversation || false,
conversation_pending: chatwoot_conversation_pending || false, conversation_pending: chatwoot_conversation_pending || false,
merge_brazil_contacts: chatwoot_merge_brazil_contacts ?? false,
import_contacts: chatwoot_import_contacts ?? true, import_contacts: chatwoot_import_contacts ?? true,
import_messages: chatwoot_import_messages ?? true, import_messages: chatwoot_import_messages ?? true,
days_limit_import_messages: chatwoot_days_limit_import_messages || 60, days_limit_import_messages: chatwoot_days_limit_import_messages || 60,
number, number,
name_inbox: instance.instanceName, name_inbox: chatwoot_name_inbox ?? instance.instanceName,
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
}, },
}; };
@@ -569,7 +595,7 @@ export class InstanceController {
} }
} }
public async connectToWhatsapp({ instanceName, number = null }: InstanceDto) { public async connectToWhatsapp({ instanceName, number = null, mobile = null }: InstanceDto) {
try { try {
this.logger.verbose('requested connectToWhatsapp from ' + instanceName + ' instance'); this.logger.verbose('requested connectToWhatsapp from ' + instanceName + ' instance');
@@ -592,7 +618,7 @@ export class InstanceController {
if (state == 'close') { if (state == 'close') {
this.logger.verbose('connecting'); this.logger.verbose('connecting');
await instance.connectToWhatsapp(number); await instance.connectToWhatsapp(number, mobile);
await delay(5000); await delay(5000);
return instance.qrCode; return instance.qrCode;
@@ -633,6 +659,20 @@ export class InstanceController {
} }
} }
public async registerMobileCode({ instanceName }: InstanceDto, { mobileCode }: any) {
try {
this.logger.verbose('requested registerMobileCode from ' + instanceName + ' instance');
const instance = this.waMonitor.waInstances[instanceName];
console.log('mobileCode', mobileCode);
await instance.receiveMobileCode(mobileCode);
return { status: 'SUCCESS', error: false, response: { message: 'Mobile code registered' } };
} catch (error) {
this.logger.error(error);
}
}
public async connectionState({ instanceName }: InstanceDto) { public async connectionState({ instanceName }: InstanceDto) {
this.logger.verbose('requested connectionState from ' + instanceName + ' instance'); this.logger.verbose('requested connectionState from ' + instanceName + ' instance');
return { return {
@@ -643,11 +683,26 @@ export class InstanceController {
}; };
} }
public async fetchInstances({ instanceName, instanceId, number }: InstanceDto) { public async fetchInstances({ instanceName, instanceId, number }: InstanceDto, key: string) {
if (instanceName) { const env = this.configService.get<Auth>('AUTHENTICATION').API_KEY;
this.logger.verbose('requested fetchInstances from ' + instanceName + ' instance');
this.logger.verbose('instanceName: ' + instanceName); let name = instanceName;
return this.waMonitor.instanceInfo(instanceName); let arrayReturn = false;
if (env.KEY !== key) {
const instanceByKey = await this.repository.auth.findByKey(key);
if (instanceByKey) {
name = instanceByKey._id;
arrayReturn = true;
} else {
throw new UnauthorizedException();
}
}
if (name) {
this.logger.verbose('requested fetchInstances from ' + name + ' instance');
this.logger.verbose('instanceName: ' + name);
return this.waMonitor.instanceInfo(name, arrayReturn);
} else if (instanceId || number) { } else if (instanceId || number) {
return this.waMonitor.instanceInfoById(instanceId, number); return this.waMonitor.instanceInfoById(instanceId, number);
} }
@@ -698,7 +753,7 @@ export class InstanceController {
this.logger.verbose('deleting instance: ' + instanceName); this.logger.verbose('deleting instance: ' + instanceName);
try { try {
this.waMonitor.waInstances[instanceName].sendDataWebhook(Events.INSTANCE_DELETE, { this.waMonitor.waInstances[instanceName]?.sendDataWebhook(Events.INSTANCE_DELETE, {
instanceName, instanceName,
instanceId: (await this.repository.auth.find(instanceName))?.instanceId, instanceId: (await this.repository.auth.find(instanceName))?.instanceId,
}); });

View File

@@ -46,7 +46,7 @@ export class ProxyController {
return this.proxyService.find(instance); return this.proxyService.find(instance);
} }
private async testProxy(proxy: ProxyDto['proxy']) { public async testProxy(proxy: ProxyDto['proxy']) {
logger.verbose('requested testProxy'); logger.verbose('requested testProxy');
try { try {
const serverIp = await axios.get('https://icanhazip.com/'); const serverIp = await axios.get('https://icanhazip.com/');

View File

@@ -1,4 +1,4 @@
import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '@whiskeysockets/baileys'; import { proto, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from 'baileys';
export class OnWhatsAppDto { export class OnWhatsAppDto {
constructor( constructor(
@@ -73,6 +73,11 @@ export class ArchiveChatDto {
archive: boolean; archive: boolean;
} }
export class MarkChatUnreadDto {
lastMessage?: LastMessage;
chat?: string;
}
class PrivacySetting { class PrivacySetting {
readreceipts: WAReadReceiptsValue; readreceipts: WAReadReceiptsValue;
profile: WAPrivacyValue; profile: WAPrivacyValue;

View File

@@ -1,10 +1,13 @@
import { WAPresence } from "@whiskeysockets/baileys"; import { WAPresence } from 'baileys';
import { ProxyDto } from './proxy.dto';
export class InstanceDto { export class InstanceDto {
instanceName: string; instanceName: string;
instanceId?: string; instanceId?: string;
qrcode?: boolean; qrcode?: boolean;
number?: string; number?: string;
mobile?: boolean;
integration?: string; integration?: string;
token?: string; token?: string;
webhook?: string; webhook?: string;
@@ -24,9 +27,11 @@ export class InstanceDto {
chatwoot_sign_msg?: boolean; chatwoot_sign_msg?: boolean;
chatwoot_reopen_conversation?: boolean; chatwoot_reopen_conversation?: boolean;
chatwoot_conversation_pending?: boolean; chatwoot_conversation_pending?: boolean;
chatwoot_merge_brazil_contacts?: boolean;
chatwoot_import_contacts?: boolean; chatwoot_import_contacts?: boolean;
chatwoot_import_messages?: boolean; chatwoot_import_messages?: boolean;
chatwoot_days_limit_import_messages?: number; chatwoot_days_limit_import_messages?: number;
chatwoot_name_inbox?: string;
websocket_enabled?: boolean; websocket_enabled?: boolean;
websocket_events?: string[]; websocket_events?: string[];
rabbitmq_enabled?: boolean; rabbitmq_enabled?: boolean;
@@ -40,7 +45,7 @@ export class InstanceDto {
typebot_delay_message?: number; typebot_delay_message?: number;
typebot_unknown_message?: string; typebot_unknown_message?: string;
typebot_listening_from_me?: boolean; typebot_listening_from_me?: boolean;
proxy?: string; proxy?: ProxyDto['proxy'];
} }
export class SetPresenceDto { export class SetPresenceDto {

View File

@@ -1,4 +1,4 @@
import { proto, WAPresence } from '@whiskeysockets/baileys'; import { proto, WAPresence } from 'baileys';
export class Quoted { export class Quoted {
key: proto.IMessageKey; key: proto.IMessageKey;

View File

@@ -3,12 +3,12 @@ import { NextFunction, Request, Response } from 'express';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import { name } from '../../../package.json'; import { name } from '../../../package.json';
import { Auth, configService } from '../../config/env.config'; import { Auth, configService, Database } from '../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../config/logger.config';
import { ForbiddenException, UnauthorizedException } from '../../exceptions'; import { ForbiddenException, UnauthorizedException } from '../../exceptions';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../dto/instance.dto';
import { repository } from '../server.module';
import { JwtPayload } from '../services/auth.service'; import { JwtPayload } from '../services/auth.service';
import { repository } from '../whatsapp.module';
const logger = new Logger('GUARD'); const logger = new Logger('GUARD');
@@ -58,6 +58,11 @@ async function jwtGuard(req: Request, res: Response, next: NextFunction) {
async function apikey(req: Request, _: Response, next: NextFunction) { async function apikey(req: Request, _: Response, next: NextFunction) {
const env = configService.get<Auth>('AUTHENTICATION').API_KEY; const env = configService.get<Auth>('AUTHENTICATION').API_KEY;
const key = req.get('apikey'); const key = req.get('apikey');
const db = configService.get<Database>('DATABASE');
if (!key) {
throw new UnauthorizedException();
}
if (env.KEY === key) { if (env.KEY === key) {
return next(); return next();
@@ -66,12 +71,21 @@ async function apikey(req: Request, _: Response, next: NextFunction) {
if ((req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) && !key) { if ((req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) && !key) {
throw new ForbiddenException('Missing global api key', 'The global api key must be set'); throw new ForbiddenException('Missing global api key', 'The global api key must be set');
} }
const param = req.params as unknown as InstanceDto;
try { try {
const param = req.params as unknown as InstanceDto; if (param?.instanceName) {
const instanceKey = await repository.auth.find(param.instanceName); const instanceKey = await repository.auth.find(param.instanceName);
if (instanceKey.apikey === key) { if (instanceKey?.apikey === key) {
return next(); return next();
}
} else {
if (req.originalUrl.includes('/instance/fetchInstances') && db.ENABLED) {
const instanceByKey = await repository.auth.findByKey(key);
if (instanceByKey) {
return next();
}
}
} }
} catch (error) { } catch (error) {
logger.error(error); logger.error(error);

View File

@@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
import { existsSync } from 'fs'; import { existsSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { configService, Database, Redis } from '../../config/env.config'; import { CacheConf, configService, Database } from '../../config/env.config';
import { INSTANCE_DIR } from '../../config/path.config'; import { INSTANCE_DIR } from '../../config/path.config';
import { import {
BadRequestException, BadRequestException,
@@ -12,17 +12,18 @@ import {
} from '../../exceptions'; } from '../../exceptions';
import { dbserver } from '../../libs/db.connect'; import { dbserver } from '../../libs/db.connect';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../dto/instance.dto';
import { cache, waMonitor } from '../whatsapp.module'; import { cache, waMonitor } from '../server.module';
async function getInstance(instanceName: string) { async function getInstance(instanceName: string) {
try { try {
const db = configService.get<Database>('DATABASE'); const db = configService.get<Database>('DATABASE');
const redisConf = configService.get<Redis>('REDIS'); const cacheConf = configService.get<CacheConf>('CACHE');
const exists = !!waMonitor.waInstances[instanceName]; const exists = !!waMonitor.waInstances[instanceName];
if (redisConf.ENABLED) { if (cacheConf.REDIS.ENABLED && cacheConf.REDIS.SAVE_INSTANCES) {
const keyExists = await cache.keyExists(); const keyExists = await cache.has(instanceName);
return exists || keyExists; return exists || keyExists;
} }

View File

@@ -1,6 +1,6 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { ChamaaiDto } from '../dto/chamaai.dto'; import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { ChamaaiService } from '../services/chamaai.service'; import { ChamaaiService } from '../services/chamaai.service';
const logger = new Logger('ChamaaiController'); const logger = new Logger('ChamaaiController');

View File

@@ -1,6 +1,6 @@
import { Schema } from 'mongoose'; import { Schema } from 'mongoose';
import { dbserver } from '../../libs/db.connect'; import { dbserver } from '../../../../libs/db.connect';
export class ChamaaiRaw { export class ChamaaiRaw {
_id?: string; _id?: string;

View File

@@ -1,10 +1,10 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { ConfigService } from '../../config/env.config'; import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository'; import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { ChamaaiRaw, IChamaaiModel } from '../models'; import { ChamaaiRaw, IChamaaiModel } from '../../../models';
export class ChamaaiRepository extends Repository { export class ChamaaiRepository extends Repository {
constructor(private readonly chamaaiModel: IChamaaiModel, private readonly configService: ConfigService) { constructor(private readonly chamaaiModel: IChamaaiModel, private readonly configService: ConfigService) {

View File

@@ -1,12 +1,12 @@
import { RequestHandler, Router } from 'express'; import { RequestHandler, Router } from 'express';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { chamaaiSchema, instanceNameSchema } from '../../validate/validate.schema'; import { chamaaiSchema, instanceNameSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router'; import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { chamaaiController } from '../../../server.module';
import { ChamaaiDto } from '../dto/chamaai.dto'; import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { chamaaiController } from '../whatsapp.module';
import { HttpStatus } from './index.router';
const logger = new Logger('ChamaaiRouter'); const logger = new Logger('ChamaaiRouter');

View File

@@ -2,13 +2,13 @@ import axios from 'axios';
import { writeFileSync } from 'fs'; import { writeFileSync } from 'fs';
import path from 'path'; import path from 'path';
import { ConfigService, HttpServer } from '../../config/env.config'; import { ConfigService, HttpServer } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { ChamaaiRaw } from '../../../models';
import { WAMonitoringService } from '../../../services/monitor.service';
import { Events } from '../../../types/wa.types';
import { ChamaaiDto } from '../dto/chamaai.dto'; import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { ChamaaiRaw } from '../models';
import { Events } from '../types/wa.types';
import { WAMonitoringService } from './monitor.service';
export class ChamaaiService { export class ChamaaiService {
constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {} constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {}

View File

@@ -0,0 +1,35 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
export const chamaaiSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
url: { type: 'string' },
token: { type: 'string' },
waNumber: { type: 'string' },
answerByAudio: { type: 'boolean', enum: [true, false] },
},
required: ['enabled', 'url', 'token', 'waNumber', 'answerByAudio'],
...isNotEmpty('enabled', 'url', 'token', 'waNumber', 'answerByAudio'),
};

View File

@@ -1,15 +1,15 @@
import { isURL } from 'class-validator'; import { isURL } from 'class-validator';
import { ConfigService, HttpServer } from '../../config/env.config'; import { CacheEngine } from '../../../../cache/cacheengine';
import { Logger } from '../../config/logger.config'; import { ConfigService, HttpServer } from '../../../../config/env.config';
import { BadRequestException } from '../../exceptions'; import { Logger } from '../../../../config/logger.config';
import { CacheEngine } from '../../libs/cacheengine'; import { BadRequestException } from '../../../../exceptions';
import { InstanceDto } from '../../../dto/instance.dto';
import { RepositoryBroker } from '../../../repository/repository.manager';
import { waMonitor } from '../../../server.module';
import { CacheService } from '../../../services/cache.service';
import { ChatwootDto } from '../dto/chatwoot.dto'; import { ChatwootDto } from '../dto/chatwoot.dto';
import { InstanceDto } from '../dto/instance.dto';
import { RepositoryBroker } from '../repository/repository.manager';
import { CacheService } from '../services/cache.service';
import { ChatwootService } from '../services/chatwoot.service'; import { ChatwootService } from '../services/chatwoot.service';
import { waMonitor } from '../whatsapp.module';
const logger = new Logger('ChatwootController'); const logger = new Logger('ChatwootController');
@@ -53,11 +53,15 @@ export class ChatwootController {
data.conversation_pending = false; data.conversation_pending = false;
data.import_contacts = false; data.import_contacts = false;
data.import_messages = false; data.import_messages = false;
data.merge_brazil_contacts = false;
data.days_limit_import_messages = 0; data.days_limit_import_messages = 0;
data.auto_create = false; data.auto_create = false;
data.name_inbox = '';
} }
data.name_inbox = instance.instanceName; if (!data.name_inbox || data.name_inbox === '') {
data.name_inbox = instance.instanceName;
}
const result = await this.chatwootService.create(instance, data); const result = await this.chatwootService.create(instance, data);

View File

@@ -9,6 +9,7 @@ export class ChatwootDto {
number?: string; number?: string;
reopen_conversation?: boolean; reopen_conversation?: boolean;
conversation_pending?: boolean; conversation_pending?: boolean;
merge_brazil_contacts?: boolean;
import_contacts?: boolean; import_contacts?: boolean;
import_messages?: boolean; import_messages?: boolean;
days_limit_import_messages?: number; days_limit_import_messages?: number;

View File

@@ -1,7 +1,7 @@
import postgresql from 'pg'; import postgresql from 'pg';
import { Chatwoot, configService } from '../config/env.config'; import { Chatwoot, configService } from '../../../../config/env.config';
import { Logger } from '../config/logger.config'; import { Logger } from '../../../../config/logger.config';
const { Pool } = postgresql; const { Pool } = postgresql;

View File

@@ -1,6 +1,6 @@
import { Schema } from 'mongoose'; import { Schema } from 'mongoose';
import { dbserver } from '../../libs/db.connect'; import { dbserver } from '../../../../libs/db.connect';
export class ChatwootRaw { export class ChatwootRaw {
_id?: string; _id?: string;
@@ -14,6 +14,7 @@ export class ChatwootRaw {
number?: string; number?: string;
reopen_conversation?: boolean; reopen_conversation?: boolean;
conversation_pending?: boolean; conversation_pending?: boolean;
merge_brazil_contacts?: boolean;
import_contacts?: boolean; import_contacts?: boolean;
import_messages?: boolean; import_messages?: boolean;
days_limit_import_messages?: number; days_limit_import_messages?: number;
@@ -31,6 +32,7 @@ const chatwootSchema = new Schema<ChatwootRaw>({
number: { type: String, required: true }, number: { type: String, required: true },
reopen_conversation: { type: Boolean, required: true }, reopen_conversation: { type: Boolean, required: true },
conversation_pending: { type: Boolean, required: true }, conversation_pending: { type: Boolean, required: true },
merge_brazil_contacts: { type: Boolean, required: true },
import_contacts: { type: Boolean, required: true }, import_contacts: { type: Boolean, required: true },
import_messages: { type: Boolean, required: true }, import_messages: { type: Boolean, required: true },
days_limit_import_messages: { type: Number, required: true }, days_limit_import_messages: { type: Number, required: true },

View File

@@ -1,10 +1,10 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { ConfigService } from '../../config/env.config'; import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository'; import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { ChatwootRaw, IChatwootModel } from '../models'; import { ChatwootRaw, IChatwootModel } from '../../../models';
export class ChatwootRepository extends Repository { export class ChatwootRepository extends Repository {
constructor(private readonly chatwootModel: IChatwootModel, private readonly configService: ConfigService) { constructor(private readonly chatwootModel: IChatwootModel, private readonly configService: ConfigService) {

View File

@@ -1,12 +1,12 @@
import { RequestHandler, Router } from 'express'; import { RequestHandler, Router } from 'express';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { chatwootSchema, instanceNameSchema } from '../../validate/validate.schema'; import { chatwootSchema, instanceNameSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router'; import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { chatwootController } from '../../../server.module';
import { ChatwootDto } from '../dto/chatwoot.dto'; import { ChatwootDto } from '../dto/chatwoot.dto';
import { InstanceDto } from '../dto/instance.dto';
import { chatwootController } from '../whatsapp.module';
import { HttpStatus } from './index.router';
const logger = new Logger('ChatwootRouter'); const logger = new Logger('ChatwootRouter');

View File

@@ -1,24 +1,33 @@
import ChatwootClient, { ChatwootAPIConfig, contact, conversation, generic_id, inbox } from '@figuro/chatwoot-sdk'; import ChatwootClient, {
ChatwootAPIConfig,
contact,
contact_inboxes,
conversation,
conversation_show,
generic_id,
inbox,
} from '@figuro/chatwoot-sdk';
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request'; import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
import axios from 'axios'; import axios from 'axios';
import { proto } from 'baileys';
import FormData from 'form-data'; import FormData from 'form-data';
import { createReadStream, unlinkSync, writeFileSync } from 'fs'; import { createReadStream, unlinkSync, writeFileSync } from 'fs';
import Jimp from 'jimp'; import Jimp from 'jimp';
import mimeTypes from 'mime-types'; import mimeTypes from 'mime-types';
import path from 'path'; import path from 'path';
import { Chatwoot, ConfigService, HttpServer } from '../../config/env.config'; import { Chatwoot, ConfigService, HttpServer } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { chatwootImport } from '../../utils/chatwoot-import-helper'; import i18next from '../../../../utils/i18n';
import i18next from '../../utils/i18n'; import { ICache } from '../../../abstract/abstract.cache';
import { ICache } from '../abstract/abstract.cache'; import { InstanceDto } from '../../../dto/instance.dto';
import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '../../../dto/sendMessage.dto';
import { ChatwootRaw, ContactRaw, MessageRaw } from '../../../models';
import { RepositoryBroker } from '../../../repository/repository.manager';
import { WAMonitoringService } from '../../../services/monitor.service';
import { Events } from '../../../types/wa.types';
import { ChatwootDto } from '../dto/chatwoot.dto'; import { ChatwootDto } from '../dto/chatwoot.dto';
import { InstanceDto } from '../dto/instance.dto'; import { chatwootImport } from '../utils/chatwoot-import-helper';
import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '../dto/sendMessage.dto';
import { ChatwootRaw, ContactRaw, MessageRaw } from '../models';
import { RepositoryBroker } from '../repository/repository.manager';
import { Events } from '../types/wa.types';
import { WAMonitoringService } from './monitor.service';
export class ChatwootService { export class ChatwootService {
private readonly logger = new Logger(ChatwootService.name); private readonly logger = new Logger(ChatwootService.name);
@@ -77,12 +86,14 @@ export class ChatwootService {
return client; return client;
} }
public getClientCwConfig(): ChatwootAPIConfig { public getClientCwConfig(): ChatwootAPIConfig & { name_inbox: string; merge_brazil_contacts: boolean } {
return { return {
basePath: this.provider.url, basePath: this.provider.url,
with_credentials: true, with_credentials: true,
credentials: 'include', credentials: 'include',
token: this.provider.token, token: this.provider.token,
name_inbox: this.provider.name_inbox,
merge_brazil_contacts: this.provider.merge_brazil_contacts,
}; };
} }
@@ -102,7 +113,7 @@ export class ChatwootService {
await this.initInstanceChatwoot( await this.initInstanceChatwoot(
instance, instance,
instance.instanceName.split('-cwId-')[0], data.name_inbox ?? instance.instanceName.split('-cwId-')[0],
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
true, true,
data.number, data.number,
@@ -408,10 +419,48 @@ export class ChatwootService {
} }
} }
private async mergeBrazilianContacts(contacts: any[]) {
try {
//sdk chatwoot não tem função merge
this.logger.verbose('merging contacts');
const contact = await chatwootRequest(this.getClientCwConfig(), {
method: 'POST',
url: `/api/v1/accounts/${this.provider.account_id}/actions/contact_merge`,
body: {
base_contact_id: contacts.find((contact) => contact.phone_number.length === 14)?.id,
mergee_contact_id: contacts.find((contact) => contact.phone_number.length === 13)?.id,
},
});
return contact;
} catch {
this.logger.error('Error merging contacts');
return null;
}
}
private findContactInContactList(contacts: any[], query: string) { private findContactInContactList(contacts: any[], query: string) {
const phoneNumbers = this.getNumbers(query); const phoneNumbers = this.getNumbers(query);
const searchableFields = this.getSearchableFields(); const searchableFields = this.getSearchableFields();
// eslint-disable-next-line prettier/prettier
if (contacts.length === 2 && this.getClientCwConfig().merge_brazil_contacts && query.startsWith('+55')) {
const contact = this.mergeBrazilianContacts(contacts);
if (contact) {
return contact;
}
}
const phone = phoneNumbers.reduce(
(savedNumber, number) => (number.length > savedNumber.length ? number : savedNumber),
'',
);
const contact_with9 = contacts.find((contact) => contact.phone_number === phone);
if (contact_with9) {
return contact_with9;
}
for (const contact of contacts) { for (const contact of contacts) {
for (const field of searchableFields) { for (const field of searchableFields) {
if (contact[field] && phoneNumbers.includes(contact[field])) { if (contact[field] && phoneNumbers.includes(contact[field])) {
@@ -439,7 +488,7 @@ export class ChatwootService {
} }
private getSearchableFields() { private getSearchableFields() {
return ['phone_number', 'identifier']; return ['phone_number'];
} }
private getFilterPayload(query: string) { private getFilterPayload(query: string) {
@@ -453,7 +502,7 @@ export class ChatwootService {
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR'; const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
filterPayload.push({ filterPayload.push({
attribute_key: field, attribute_key: field,
filter_operator: field == 'phone_number' ? 'equal_to' : 'contains', filter_operator: 'equal_to',
values: [number.replace('+', '')], values: [number.replace('+', '')],
query_operator: queryOperator, query_operator: queryOperator,
}); });
@@ -551,53 +600,44 @@ export class ChatwootService {
const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(chatId); const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(chatId);
const findContact = await this.findContact(instance, chatId); let contact = await this.findContact(instance, chatId);
let contact: any; if (contact) {
if (body.key.fromMe) { if (!body.key.fromMe) {
if (findContact) { const waProfilePictureFile =
contact = await this.updateContact(instance, findContact.id, { picture_url?.profilePictureUrl?.split('#')[0].split('?')[0].split('/').pop() || '';
avatar_url: picture_url.profilePictureUrl || null, const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop() || '';
}); const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile;
} else { const nameNeedsUpdate =
const jid = isGroup ? null : body.key.remoteJid; !contact.name ||
contact = await this.createContact( contact.name === chatId ||
instance, (`+${chatId}`.startsWith('+55')
chatId, ? this.getNumbers(`+${chatId}`).some(
filterInbox.id, (v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1),
isGroup, )
nameContact, : false);
picture_url.profilePictureUrl || null,
jid, const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate;
); if (contactNeedsUpdate) {
this.logger.verbose('update contact in chatwoot');
contact = await this.updateContact(instance, contact.id, {
...(nameNeedsUpdate && { name: nameContact }),
...(waProfilePictureFile === '' && { avatar: null }),
...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
});
}
} }
} else { } else {
if (findContact) { const jid = isGroup ? null : body.key.remoteJid;
if (!findContact.name || findContact.name === chatId) { contact = await this.createContact(
contact = await this.updateContact(instance, findContact.id, { instance,
name: nameContact, chatId,
avatar_url: picture_url.profilePictureUrl || null, filterInbox.id,
}); isGroup,
} else { nameContact,
contact = await this.updateContact(instance, findContact.id, { picture_url.profilePictureUrl || null,
avatar_url: picture_url.profilePictureUrl || null, jid,
}); );
}
if (!contact) {
contact = await this.findContact(instance, chatId);
}
} else {
const jid = isGroup ? null : body.key.remoteJid;
contact = await this.createContact(
instance,
chatId,
filterInbox.id,
isGroup,
nameContact,
picture_url.profilePictureUrl || null,
jid,
);
}
} }
if (!contact) { if (!contact) {
@@ -607,20 +647,13 @@ export class ChatwootService {
const contactId = contact?.payload?.id || contact?.payload?.contact?.id || contact?.id; const contactId = contact?.payload?.id || contact?.payload?.contact?.id || contact?.id;
if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) {
this.logger.verbose('update contact name in chatwoot');
await this.updateContact(instance, contactId, {
name: nameContact,
});
}
this.logger.verbose('get contact conversations in chatwoot'); this.logger.verbose('get contact conversations in chatwoot');
const contactConversations = (await client.contacts.listConversations({ const contactConversations = (await client.contacts.listConversations({
accountId: this.provider.account_id, accountId: this.provider.account_id,
id: contactId, id: contactId,
})) as any; })) as any;
if (contactConversations) { if (contactConversations?.payload?.length) {
let conversation: any; let conversation: any;
if (this.provider.reopen_conversation) { if (this.provider.reopen_conversation) {
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id); conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
@@ -702,7 +735,12 @@ export class ChatwootService {
} }
this.logger.verbose('find inbox by name'); this.logger.verbose('find inbox by name');
const findByName = inbox.payload.find((inbox) => inbox.name === instance.instanceName.split('-cwId-')[0]); let findByName = inbox.payload.find((inbox) => inbox.name === this.getClientCwConfig().name_inbox);
if (!findByName) {
findByName = inbox.payload.find((inbox) => inbox.name === this.getClientCwConfig().name_inbox.split('-cwId-')[0]);
}
if (!findByName) { if (!findByName) {
this.logger.warn('inbox not found'); this.logger.warn('inbox not found');
@@ -779,26 +817,15 @@ export class ChatwootService {
return null; return null;
} }
const payload = [ const conversations = (await client.contacts.listConversations({
['inbox_id', inbox.id.toString()], accountId: this.provider.account_id,
['contact_id', contact.id.toString()], id: contact.id,
['status', 'open'], })) as any;
];
return ( return (
( conversations.payload.find(
(await client.conversations.filter({ (conversation) => conversation.inbox_id === inbox.id && conversation.status === 'open',
accountId: this.provider.account_id, ) || undefined
payload: payload.map((item, i, payload) => {
return {
attribute_key: item[0],
filter_operator: 'equal_to',
values: [item[1]],
query_operator: i < payload.length - 1 ? 'AND' : null,
};
}),
})) as { payload: conversation[] }
).payload[0] || undefined
); );
} }
@@ -1069,6 +1096,10 @@ export class ChatwootService {
return messageSent; return messageSent;
} }
if (type === 'image' && parsedMedia && parsedMedia?.ext === '.gif') {
type = 'document';
}
this.logger.verbose('send media to instance: ' + waInstance.instanceName); this.logger.verbose('send media to instance: ' + waInstance.instanceName);
const data: SendMediaDto = { const data: SendMediaDto = {
number: number, number: number,
@@ -1098,6 +1129,26 @@ export class ChatwootService {
} }
} }
public async onSendMessageError(instance: InstanceDto, conversation: number, error?: string) {
const client = await this.clientCw(instance);
if (!client) {
return;
}
client.messages.create({
accountId: this.provider.account_id,
conversationId: conversation,
data: {
content: i18next.t('cw.message.notsent', {
error: error?.length > 0 ? `_${error}_` : '',
}),
message_type: 'outgoing',
private: true,
},
});
}
public async receiveWebhook(instance: InstanceDto, body: any) { public async receiveWebhook(instance: InstanceDto, body: any) {
try { try {
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
@@ -1266,6 +1317,11 @@ export class ChatwootService {
return { message: 'bot' }; return { message: 'bot' };
} }
if (!waInstance && body.conversation?.id) {
this.onSendMessageError(instance, body.conversation?.id, 'Instance not found');
return { message: 'bot' };
}
this.logger.verbose('Format message to send'); this.logger.verbose('Format message to send');
let formatText: string; let formatText: string;
if (senderName === null || senderName === undefined) { if (senderName === null || senderName === undefined) {
@@ -1302,6 +1358,9 @@ export class ChatwootService {
formatText, formatText,
options, options,
); );
if (!messageSent && body.conversation?.id) {
this.onSendMessageError(instance, body.conversation?.id);
}
this.updateChatwootMessageId( this.updateChatwootMessageId(
{ {
@@ -1335,23 +1394,34 @@ export class ChatwootService {
}, },
}; };
const messageSent = await waInstance?.textMessage(data, true); let messageSent: MessageRaw | proto.WebMessageInfo;
try {
messageSent = await waInstance?.textMessage(data, true);
if (!messageSent) {
throw new Error('Message not sent');
}
this.updateChatwootMessageId( this.updateChatwootMessageId(
{ {
...messageSent, ...messageSent,
owner: instance.instanceName, owner: instance.instanceName,
},
{
messageId: body.id,
inboxId: body.inbox?.id,
conversationId: body.conversation?.id,
contactInbox: {
sourceId: body.conversation?.contact_inbox?.source_id,
}, },
}, {
instance, messageId: body.id,
); inboxId: body.inbox?.id,
conversationId: body.conversation?.id,
contactInbox: {
sourceId: body.conversation?.contact_inbox?.source_id,
},
},
instance,
);
} catch (error) {
if (!messageSent && body.conversation?.id) {
this.onSendMessageError(instance, body.conversation?.id, error.toString());
}
throw error;
}
} }
} }
@@ -1774,6 +1844,13 @@ export class ChatwootService {
return; return;
} }
// fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled
if (body.message?.ephemeralMessage?.message) {
body.message = {
...body.message?.ephemeralMessage?.message,
};
}
this.logger.verbose('get conversation message'); this.logger.verbose('get conversation message');
// Whatsapp to Chatwoot // Whatsapp to Chatwoot
@@ -2123,12 +2200,13 @@ export class ChatwootService {
}; };
if (!sourceId && inbox) { if (!sourceId && inbox) {
const contact = (await this.findContact( const conversation = (await client.conversations.get({
instance, accountId: this.provider.account_id,
this.getNumberFromRemoteJid(body.key.remoteJid), conversationId: conversationId,
)) as contact; })) as conversation_show & {
const contactInbox = contact?.contact_inboxes?.find((contactInbox) => contactInbox?.inbox?.id === inbox.id); last_non_activity_message: { conversation: { contact_inbox: contact_inboxes } };
sourceId = contactInbox?.source_id; };
sourceId = conversation.last_non_activity_message?.conversation?.contact_inbox?.source_id;
} }
if (sourceId && inbox?.inbox_identifier) { if (sourceId && inbox?.inbox_identifier) {

View File

@@ -1,12 +1,12 @@
import { inbox } from '@figuro/chatwoot-sdk'; import { inbox } from '@figuro/chatwoot-sdk';
import { proto } from '@whiskeysockets/baileys'; import { proto } from 'baileys';
import { Chatwoot, configService } from '../config/env.config'; import { InstanceDto } from '../../../../api/dto/instance.dto';
import { Logger } from '../config/logger.config'; import { ChatwootRaw, ContactRaw, MessageRaw } from '../../../../api/models';
import { Chatwoot, configService } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { postgresClient } from '../libs/postgres.client'; import { postgresClient } from '../libs/postgres.client';
import { InstanceDto } from '../whatsapp/dto/instance.dto'; import { ChatwootService } from '../services/chatwoot.service';
import { ChatwootRaw, ContactRaw, MessageRaw } from '../whatsapp/models';
import { ChatwootService } from '../whatsapp/services/chatwoot.service';
type ChatwootUser = { type ChatwootUser = {
user_type: string; user_type: string;

View File

@@ -0,0 +1,44 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
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] },
sign_delimiter: { type: ['string', 'null'] },
name_inbox: { type: ['string', 'null'] },
reopen_conversation: { type: 'boolean', enum: [true, false] },
conversation_pending: { type: 'boolean', enum: [true, false] },
auto_create: { type: 'boolean', enum: [true, false] },
import_contacts: { type: 'boolean', enum: [true, false] },
merge_brazil_contacts: { type: 'boolean', enum: [true, false] },
import_messages: { type: 'boolean', enum: [true, false] },
days_limit_import_messages: { type: 'number' },
},
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'],
...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'),
};

View File

@@ -1,5 +1,5 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { RabbitmqDto } from '../dto/rabbitmq.dto'; import { RabbitmqDto } from '../dto/rabbitmq.dto';
import { RabbitmqService } from '../services/rabbitmq.service'; import { RabbitmqService } from '../services/rabbitmq.service';

View File

@@ -1,7 +1,7 @@
import * as amqp from 'amqplib/callback_api'; import * as amqp from 'amqplib/callback_api';
import { configService, Rabbitmq } from '../config/env.config'; import { configService, Rabbitmq } from '../../../../config/env.config';
import { Logger } from '../config/logger.config'; import { Logger } from '../../../../config/logger.config';
const logger = new Logger('AMQP'); const logger = new Logger('AMQP');
@@ -42,6 +42,41 @@ export const getAMQP = (): amqp.Channel | null => {
return amqpChannel; return amqpChannel;
}; };
export const initGlobalQueues = () => {
logger.info('Initializing global queues');
const events = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
if (!events) {
logger.warn('No events to initialize on AMQP');
return;
}
const eventKeys = Object.keys(events);
eventKeys.forEach((event) => {
if (events[event] === false) return;
const queueName = `${event.replace(/_/g, '.').toLowerCase()}`;
const amqp = getAMQP();
const exchangeName = 'evolution_exchange';
amqp.assertExchange(exchangeName, 'topic', {
durable: true,
autoDelete: false,
});
amqp.assertQueue(queueName, {
durable: true,
autoDelete: false,
arguments: {
'x-queue-type': 'quorum',
},
});
amqp.bindQueue(queueName, exchangeName, event);
});
};
export const initQueues = (instanceName: string, events: string[]) => { export const initQueues = (instanceName: string, events: string[]) => {
if (!events || !events.length) return; if (!events || !events.length) return;

View File

@@ -1,6 +1,6 @@
import { Schema } from 'mongoose'; import { Schema } from 'mongoose';
import { dbserver } from '../../libs/db.connect'; import { dbserver } from '../../../../libs/db.connect';
export class RabbitmqRaw { export class RabbitmqRaw {
_id?: string; _id?: string;

View File

@@ -1,10 +1,10 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { ConfigService } from '../../config/env.config'; import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository'; import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { IRabbitmqModel, RabbitmqRaw } from '../models'; import { IRabbitmqModel, RabbitmqRaw } from '../../../models';
export class RabbitmqRepository extends Repository { export class RabbitmqRepository extends Repository {
constructor(private readonly rabbitmqModel: IRabbitmqModel, private readonly configService: ConfigService) { constructor(private readonly rabbitmqModel: IRabbitmqModel, private readonly configService: ConfigService) {

View File

@@ -1,12 +1,12 @@
import { RequestHandler, Router } from 'express'; import { RequestHandler, Router } from 'express';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { instanceNameSchema, rabbitmqSchema } from '../../validate/validate.schema'; import { instanceNameSchema, rabbitmqSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router'; import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { rabbitmqController } from '../../../server.module';
import { RabbitmqDto } from '../dto/rabbitmq.dto'; import { RabbitmqDto } from '../dto/rabbitmq.dto';
import { rabbitmqController } from '../whatsapp.module';
import { HttpStatus } from './index.router';
const logger = new Logger('RabbitmqRouter'); const logger = new Logger('RabbitmqRouter');

View File

@@ -1,9 +1,9 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { initQueues } from '../../libs/amqp.server'; import { InstanceDto } from '../../../dto/instance.dto';
import { InstanceDto } from '../dto/instance.dto'; import { RabbitmqRaw } from '../../../models';
import { WAMonitoringService } from '../../../services/monitor.service';
import { RabbitmqDto } from '../dto/rabbitmq.dto'; import { RabbitmqDto } from '../dto/rabbitmq.dto';
import { RabbitmqRaw } from '../models'; import { initQueues } from '../libs/amqp.server';
import { WAMonitoringService } from './monitor.service';
export class RabbitmqService { export class RabbitmqService {
constructor(private readonly waMonitor: WAMonitoringService) {} constructor(private readonly waMonitor: WAMonitoringService) {}

View File

@@ -0,0 +1,66 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
export const rabbitmqSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
events: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: [
'APPLICATION_STARTUP',
'QRCODE_UPDATED',
'MESSAGES_SET',
'MESSAGES_UPSERT',
'MESSAGES_UPDATE',
'MESSAGES_DELETE',
'SEND_MESSAGE',
'CONTACTS_SET',
'CONTACTS_UPSERT',
'CONTACTS_UPDATE',
'PRESENCE_UPDATE',
'CHATS_SET',
'CHATS_UPSERT',
'CHATS_UPDATE',
'CHATS_DELETE',
'GROUPS_UPSERT',
'GROUP_UPDATE',
'GROUP_PARTICIPANTS_UPDATE',
'CONNECTION_UPDATE',
'LABELS_EDIT',
'LABELS_ASSOCIATION',
'CALL',
'NEW_JWT_TOKEN',
'TYPEBOT_START',
'TYPEBOT_CHANGE_STATUS',
'CHAMA_AI_ACTION',
],
},
},
},
required: ['enabled'],
...isNotEmpty('enabled'),
};

View File

@@ -1,5 +1,5 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { SqsDto } from '../dto/sqs.dto'; import { SqsDto } from '../dto/sqs.dto';
import { SqsService } from '../services/sqs.service'; import { SqsService } from '../services/sqs.service';

View File

@@ -1,7 +1,7 @@
import { SQS } from 'aws-sdk'; import { SQS } from '@aws-sdk/client-sqs';
import { configService, Sqs } from '../config/env.config'; import { configService, Sqs } from '../../../../config/env.config';
import { Logger } from '../config/logger.config'; import { Logger } from '../../../../config/logger.config';
const logger = new Logger('SQS'); const logger = new Logger('SQS');
@@ -12,8 +12,11 @@ export const initSQS = () => {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const awsConfig = configService.get<Sqs>('SQS'); const awsConfig = configService.get<Sqs>('SQS');
sqs = new SQS({ sqs = new SQS({
accessKeyId: awsConfig.ACCESS_KEY_ID, credentials: {
secretAccessKey: awsConfig.SECRET_ACCESS_KEY, accessKeyId: awsConfig.ACCESS_KEY_ID,
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
},
region: awsConfig.REGION, region: awsConfig.REGION,
}); });

View File

@@ -1,6 +1,6 @@
import { Schema } from 'mongoose'; import { Schema } from 'mongoose';
import { dbserver } from '../../libs/db.connect'; import { dbserver } from '../../../../libs/db.connect';
export class SqsRaw { export class SqsRaw {
_id?: string; _id?: string;

View File

@@ -1,10 +1,10 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { ConfigService } from '../../config/env.config'; import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository'; import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { ISqsModel, SqsRaw } from '../models'; import { ISqsModel, SqsRaw } from '../../../models';
export class SqsRepository extends Repository { export class SqsRepository extends Repository {
constructor(private readonly sqsModel: ISqsModel, private readonly configService: ConfigService) { constructor(private readonly sqsModel: ISqsModel, private readonly configService: ConfigService) {

View File

@@ -1,12 +1,12 @@
import { RequestHandler, Router } from 'express'; import { RequestHandler, Router } from 'express';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { instanceNameSchema, sqsSchema } from '../../validate/validate.schema'; import { instanceNameSchema, sqsSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router'; import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { sqsController } from '../../../server.module';
import { SqsDto } from '../dto/sqs.dto'; import { SqsDto } from '../dto/sqs.dto';
import { sqsController } from '../whatsapp.module';
import { HttpStatus } from './index.router';
const logger = new Logger('SqsRouter'); const logger = new Logger('SqsRouter');

View File

@@ -1,9 +1,9 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { initQueues } from '../../libs/sqs.server'; import { InstanceDto } from '../../../dto/instance.dto';
import { InstanceDto } from '../dto/instance.dto'; import { SqsRaw } from '../../../models';
import { WAMonitoringService } from '../../../services/monitor.service';
import { SqsDto } from '../dto/sqs.dto'; import { SqsDto } from '../dto/sqs.dto';
import { SqsRaw } from '../models'; import { initQueues } from '../libs/sqs.server';
import { WAMonitoringService } from './monitor.service';
export class SqsService { export class SqsService {
constructor(private readonly waMonitor: WAMonitoringService) {} constructor(private readonly waMonitor: WAMonitoringService) {}

View File

@@ -0,0 +1,66 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
export const sqsSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
events: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: [
'APPLICATION_STARTUP',
'QRCODE_UPDATED',
'MESSAGES_SET',
'MESSAGES_UPSERT',
'MESSAGES_UPDATE',
'MESSAGES_DELETE',
'SEND_MESSAGE',
'CONTACTS_SET',
'CONTACTS_UPSERT',
'CONTACTS_UPDATE',
'PRESENCE_UPDATE',
'CHATS_SET',
'CHATS_UPSERT',
'CHATS_UPDATE',
'CHATS_DELETE',
'GROUPS_UPSERT',
'GROUP_UPDATE',
'GROUP_PARTICIPANTS_UPDATE',
'CONNECTION_UPDATE',
'LABELS_EDIT',
'LABELS_ASSOCIATION',
'CALL',
'NEW_JWT_TOKEN',
'TYPEBOT_START',
'TYPEBOT_CHANGE_STATUS',
'CHAMA_AI_ACTION',
],
},
},
},
required: ['enabled'],
...isNotEmpty('enabled'),
};

View File

@@ -1,5 +1,5 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { TypebotDto } from '../dto/typebot.dto'; import { TypebotDto } from '../dto/typebot.dto';
import { TypebotService } from '../services/typebot.service'; import { TypebotService } from '../services/typebot.service';

View File

@@ -1,6 +1,6 @@
import { Schema } from 'mongoose'; import { Schema } from 'mongoose';
import { dbserver } from '../../libs/db.connect'; import { dbserver } from '../../../../libs/db.connect';
class Session { class Session {
remoteJid?: string; remoteJid?: string;

View File

@@ -1,10 +1,10 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { ConfigService } from '../../config/env.config'; import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository'; import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { ITypebotModel, TypebotRaw } from '../models'; import { ITypebotModel, TypebotRaw } from '../../../models';
export class TypebotRepository extends Repository { export class TypebotRepository extends Repository {
constructor(private readonly typebotModel: ITypebotModel, private readonly configService: ConfigService) { constructor(private readonly typebotModel: ITypebotModel, private readonly configService: ConfigService) {

View File

@@ -1,17 +1,17 @@
import { RequestHandler, Router } from 'express'; import { RequestHandler, Router } from 'express';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { import {
instanceNameSchema, instanceNameSchema,
typebotSchema, typebotSchema,
typebotStartSchema, typebotStartSchema,
typebotStatusSchema, typebotStatusSchema,
} from '../../validate/validate.schema'; } from '../../../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router'; import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { typebotController } from '../../../server.module';
import { TypebotDto } from '../dto/typebot.dto'; import { TypebotDto } from '../dto/typebot.dto';
import { typebotController } from '../whatsapp.module';
import { HttpStatus } from './index.router';
const logger = new Logger('TypebotRouter'); const logger = new Logger('TypebotRouter');

View File

@@ -1,13 +1,13 @@
import axios from 'axios'; import axios from 'axios';
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from 'eventemitter2';
import { ConfigService, Typebot } from '../../config/env.config'; import { ConfigService, Typebot } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { MessageRaw } from '../../../models';
import { WAMonitoringService } from '../../../services/monitor.service';
import { Events } from '../../../types/wa.types';
import { Session, TypebotDto } from '../dto/typebot.dto'; import { Session, TypebotDto } from '../dto/typebot.dto';
import { MessageRaw } from '../models';
import { Events } from '../types/wa.types';
import { WAMonitoringService } from './monitor.service';
export class TypebotService { export class TypebotService {
constructor( constructor(
@@ -269,27 +269,30 @@ export class TypebotService {
} }
private getTypeMessage(msg: any) { private getTypeMessage(msg: any) {
this.logger.verbose('get type message'); this.logger.verbose('get type message');
const types = { const types = {
conversation: msg.conversation, conversation: msg.conversation,
extendedTextMessage: msg.extendedTextMessage?.text, extendedTextMessage: msg.extendedTextMessage?.text,
audioMessage: msg.audioMessage?.url, audioMessage: msg.audioMessage?.url,
imageMessage: msg.imageMessage?.url, imageMessage: msg.imageMessage?.url,
videoMessage: msg.videoMessage?.url, videoMessage: msg.videoMessage?.url,
documentMessage: msg.documentMessage?.fileName, documentMessage: msg.documentMessage?.fileName,
contactMessage: msg.contactMessage?.displayName, contactMessage: msg.contactMessage?.displayName,
locationMessage: msg.locationMessage?.degreesLatitude, locationMessage: msg.locationMessage?.degreesLatitude,
viewOnceMessageV2: msg.viewOnceMessageV2?.message?.imageMessage?.url || msg.viewOnceMessageV2?.message?.videoMessage?.url || msg.viewOnceMessageV2?.message?.audioMessage?.url, viewOnceMessageV2:
listResponseMessage: msg.listResponseMessage?.singleSelectReply?.selectedRowId, msg.viewOnceMessageV2?.message?.imageMessage?.url ||
responseRowId: msg.listResponseMessage?.singleSelectReply?.selectedRowId, msg.viewOnceMessageV2?.message?.videoMessage?.url ||
}; msg.viewOnceMessageV2?.message?.audioMessage?.url,
listResponseMessage: msg.listResponseMessage?.singleSelectReply?.selectedRowId,
responseRowId: msg.listResponseMessage?.singleSelectReply?.selectedRowId,
};
const messageType = Object.keys(types).find(key => types[key] !== undefined) || 'unknown'; const messageType = Object.keys(types).find((key) => types[key] !== undefined) || 'unknown';
this.logger.verbose('Type message: ' + JSON.stringify(types)); this.logger.verbose('Type message: ' + JSON.stringify(types));
return { ...types, messageType }; return { ...types, messageType };
} }
private getMessageContent(types: any) { private getMessageContent(types: any) {
this.logger.verbose('get message content'); this.logger.verbose('get message content');
const typeKey = Object.keys(types).find((key) => types[key] !== undefined); const typeKey = Object.keys(types).find((key) => types[key] !== undefined);
@@ -317,7 +320,7 @@ export class TypebotService {
this.logger.verbose('get audio message content'); this.logger.verbose('get audio message content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const audioContent = types.audioMessage; const audioContent = types.audioMessage;
this.logger.verbose('audio message URL: ' + audioContent); this.logger.verbose('audio message URL: ' + audioContent);
@@ -327,85 +330,85 @@ export class TypebotService {
private getImageMessageContent(msg: any) { private getImageMessageContent(msg: any) {
this.logger.verbose('get image message content'); this.logger.verbose('get image message content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const imageContent = types.imageMessage; const imageContent = types.imageMessage;
this.logger.verbose('image message URL: ' + imageContent); this.logger.verbose('image message URL: ' + imageContent);
return imageContent; return imageContent;
} }
private getVideoMessageContent(msg: any) { private getVideoMessageContent(msg: any) {
this.logger.verbose('get video message content'); this.logger.verbose('get video message content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const videoContent = types.videoMessage; const videoContent = types.videoMessage;
this.logger.verbose('video message URL: ' + videoContent); this.logger.verbose('video message URL: ' + videoContent);
return videoContent; return videoContent;
} }
private getDocumentMessageContent(msg: any) { private getDocumentMessageContent(msg: any) {
this.logger.verbose('get document message content'); this.logger.verbose('get document message content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const documentContent = types.documentMessage; const documentContent = types.documentMessage;
this.logger.verbose('document message fileName: ' + documentContent); this.logger.verbose('document message fileName: ' + documentContent);
return documentContent; return documentContent;
} }
private getContactMessageContent(msg: any) { private getContactMessageContent(msg: any) {
this.logger.verbose('get contact message content'); this.logger.verbose('get contact message content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const contactContent = types.contactMessage; const contactContent = types.contactMessage;
this.logger.verbose('contact message displayName: ' + contactContent); this.logger.verbose('contact message displayName: ' + contactContent);
return contactContent; return contactContent;
} }
private getLocationMessageContent(msg: any) { private getLocationMessageContent(msg: any) {
this.logger.verbose('get location message content'); this.logger.verbose('get location message content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const locationContent = types.locationMessage; const locationContent = types.locationMessage;
this.logger.verbose('location message degreesLatitude: ' + locationContent); this.logger.verbose('location message degreesLatitude: ' + locationContent);
return locationContent; return locationContent;
} }
private getViewOnceMessageV2Content(msg: any) { private getViewOnceMessageV2Content(msg: any) {
this.logger.verbose('get viewOnceMessageV2 content'); this.logger.verbose('get viewOnceMessageV2 content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const viewOnceContent = types.viewOnceMessageV2; const viewOnceContent = types.viewOnceMessageV2;
this.logger.verbose('viewOnceMessageV2 URL: ' + viewOnceContent); this.logger.verbose('viewOnceMessageV2 URL: ' + viewOnceContent);
return viewOnceContent; return viewOnceContent;
} }
private getListResponseMessageContent(msg: any) { private getListResponseMessageContent(msg: any) {
this.logger.verbose('get listResponseMessage content'); this.logger.verbose('get listResponseMessage content');
const types = this.getTypeMessage(msg); const types = this.getTypeMessage(msg);
const listResponseContent = types.listResponseMessage || types.responseRowId; const listResponseContent = types.listResponseMessage || types.responseRowId;
this.logger.verbose('listResponseMessage selectedRowId: ' + listResponseContent); this.logger.verbose('listResponseMessage selectedRowId: ' + listResponseContent);
return listResponseContent; return listResponseContent;
} }
public async createNewSession(instance: InstanceDto, data: any) { public async createNewSession(instance: InstanceDto, data: any) {
@@ -516,18 +519,36 @@ export class TypebotService {
text += element.text; text += element.text;
} }
if ( if (element.children && element.type !== 'a') {
element.children &&
(element.type === 'p' ||
element.type === 'a' ||
element.type === 'inline-variable' ||
element.type === 'variable')
) {
for (const child of element.children) { for (const child of element.children) {
text += applyFormatting(child); text += applyFormatting(child);
} }
} }
if (element.type === 'p' && element.type !== 'inline-variable') {
text = text.trim() + '\n';
}
if (element.type === 'inline-variable') {
text = text.trim();
}
if (element.type === 'ol') {
text =
'\n' +
text
.split('\n')
.map((line, index) => (line ? `${index + 1}. ${line}` : ''))
.join('\n');
}
if (element.type === 'li') {
text = text
.split('\n')
.map((line) => (line ? ` ${line}` : ''))
.join('\n');
}
let formats = ''; let formats = '';
if (element.bold) { if (element.bold) {
@@ -565,6 +586,8 @@ export class TypebotService {
formattedText = formattedText.replace(/\*\*/g, '').replace(/__/, '').replace(/~~/, '').replace(/\n$/, ''); formattedText = formattedText.replace(/\*\*/g, '').replace(/__/, '').replace(/~~/, '').replace(/\n$/, '');
formattedText = formattedText.replace(/\n$/, '');
await instance.textMessage({ await instance.textMessage({
number: remoteJid.split('@')[0], number: remoteJid.split('@')[0],
options: { options: {
@@ -791,7 +814,7 @@ export class TypebotService {
sessions: sessions, sessions: sessions,
remoteJid: remoteJid, remoteJid: remoteJid,
pushName: msg.pushName, pushName: msg.pushName,
prefilledVariables: { prefilledVariables: {
messageType: messageType, messageType: messageType,
}, },
}); });

View File

@@ -0,0 +1,60 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
export const typebotSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
url: { type: 'string' },
typebot: { type: 'string' },
expire: { type: 'integer' },
delay_message: { type: 'integer' },
unknown_message: { type: 'string' },
listening_from_me: { type: 'boolean', enum: [true, false] },
},
required: ['enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'],
...isNotEmpty('enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'),
};
export const typebotStatusSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
remoteJid: { type: 'string' },
status: { type: 'string', enum: ['opened', 'closed', 'paused'] },
},
required: ['remoteJid', 'status'],
...isNotEmpty('remoteJid', 'status'),
};
export const typebotStartSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
remoteJid: { type: 'string' },
url: { type: 'string' },
typebot: { type: 'string' },
},
required: ['remoteJid', 'url', 'typebot'],
...isNotEmpty('remoteJid', 'url', 'typebot'),
};

View File

@@ -1,5 +1,5 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { WebsocketDto } from '../dto/websocket.dto'; import { WebsocketDto } from '../dto/websocket.dto';
import { WebsocketService } from '../services/websocket.service'; import { WebsocketService } from '../services/websocket.service';

View File

@@ -1,8 +1,8 @@
import { Server } from 'http'; import { Server } from 'http';
import { Server as SocketIO } from 'socket.io'; import { Server as SocketIO } from 'socket.io';
import { configService, Cors, Websocket } from '../config/env.config'; import { configService, Cors, Websocket } from '../../../../config/env.config';
import { Logger } from '../config/logger.config'; import { Logger } from '../../../../config/logger.config';
const logger = new Logger('Socket'); const logger = new Logger('Socket');

View File

@@ -1,6 +1,6 @@
import { Schema } from 'mongoose'; import { Schema } from 'mongoose';
import { dbserver } from '../../libs/db.connect'; import { dbserver } from '../../../../libs/db.connect';
export class WebsocketRaw { export class WebsocketRaw {
_id?: string; _id?: string;

View File

@@ -1,10 +1,10 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { ConfigService } from '../../config/env.config'; import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository'; import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { IWebsocketModel, WebsocketRaw } from '../models'; import { IWebsocketModel, WebsocketRaw } from '../../../models';
export class WebsocketRepository extends Repository { export class WebsocketRepository extends Repository {
constructor(private readonly websocketModel: IWebsocketModel, private readonly configService: ConfigService) { constructor(private readonly websocketModel: IWebsocketModel, private readonly configService: ConfigService) {

View File

@@ -1,12 +1,12 @@
import { RequestHandler, Router } from 'express'; import { RequestHandler, Router } from 'express';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { instanceNameSchema, websocketSchema } from '../../validate/validate.schema'; import { instanceNameSchema, websocketSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router'; import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { websocketController } from '../../../server.module';
import { WebsocketDto } from '../dto/websocket.dto'; import { WebsocketDto } from '../dto/websocket.dto';
import { websocketController } from '../whatsapp.module';
import { HttpStatus } from './index.router';
const logger = new Logger('WebsocketRouter'); const logger = new Logger('WebsocketRouter');

View File

@@ -1,8 +1,8 @@
import { Logger } from '../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { WebsocketRaw } from '../../../models';
import { WAMonitoringService } from '../../../services/monitor.service';
import { WebsocketDto } from '../dto/websocket.dto'; import { WebsocketDto } from '../dto/websocket.dto';
import { WebsocketRaw } from '../models';
import { WAMonitoringService } from './monitor.service';
export class WebsocketService { export class WebsocketService {
constructor(private readonly waMonitor: WAMonitoringService) {} constructor(private readonly waMonitor: WAMonitoringService) {}

View File

@@ -0,0 +1,66 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
export const websocketSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
events: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: [
'APPLICATION_STARTUP',
'QRCODE_UPDATED',
'MESSAGES_SET',
'MESSAGES_UPSERT',
'MESSAGES_UPDATE',
'MESSAGES_DELETE',
'SEND_MESSAGE',
'CONTACTS_SET',
'CONTACTS_UPSERT',
'CONTACTS_UPDATE',
'PRESENCE_UPDATE',
'CHATS_SET',
'CHATS_UPSERT',
'CHATS_UPDATE',
'CHATS_DELETE',
'GROUPS_UPSERT',
'GROUP_UPDATE',
'GROUP_PARTICIPANTS_UPDATE',
'CONNECTION_UPDATE',
'LABELS_EDIT',
'LABELS_ASSOCIATION',
'CALL',
'NEW_JWT_TOKEN',
'TYPEBOT_START',
'TYPEBOT_CHANGE_STATUS',
'CHAMA_AI_ACTION',
],
},
},
},
required: ['enabled'],
...isNotEmpty('enabled'),
};

15
src/api/models/index.ts Normal file
View File

@@ -0,0 +1,15 @@
export * from '../integrations/chamaai/models/chamaai.model';
export * from '../integrations/chatwoot/models/chatwoot.model';
export * from '../integrations/rabbitmq/models/rabbitmq.model';
export * from '../integrations/sqs/models/sqs.model';
export * from '../integrations/typebot/models/typebot.model';
export * from '../integrations/websocket/models/websocket.model';
export * from './auth.model';
export * from './chat.model';
export * from './contact.model';
export * from './integration.model';
export * from './label.model';
export * from './message.model';
export * from './proxy.model';
export * from './settings.model';
export * from './webhook.model';

View File

@@ -9,12 +9,12 @@ export class IntegrationRaw {
token?: string; token?: string;
} }
const sqsSchema = new Schema<IntegrationRaw>({ const integrationSchema = new Schema<IntegrationRaw>({
_id: { type: String, _id: true }, _id: { type: String, _id: true },
integration: { type: String, required: true }, integration: { type: String, required: true },
number: { type: String, required: true }, number: { type: String, required: true },
token: { type: String, required: true }, token: { type: String, required: true },
}); });
export const IntegrationModel = dbserver?.model(IntegrationRaw.name, sqsSchema, 'integration'); export const IntegrationModel = dbserver?.model(IntegrationRaw.name, integrationSchema, 'integration');
export type IntegrationModel = typeof IntegrationModel; export type IntegrationModel = typeof IntegrationModel;

View File

@@ -32,6 +32,7 @@ export class MessageRaw {
source_reply_id?: string; source_reply_id?: string;
chatwoot?: ChatwootMessage; chatwoot?: ChatwootMessage;
contextInfo?: any; contextInfo?: any;
status?: wa.StatusMessage | any;
} }
type MessageRawBoolean<T> = { type MessageRawBoolean<T> = {

View File

@@ -0,0 +1,150 @@
import axios from 'axios';
import { execSync } from 'child_process';
import { Auth, ConfigService, ProviderSession } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
type ResponseSuccess = { status: number; data?: any };
type ResponseProvider = Promise<[ResponseSuccess?, Error?]>;
export class ProviderFiles {
constructor(private readonly configService: ConfigService) {
this.baseUrl = `http://${this.config.HOST}:${this.config.PORT}/session/${this.config.PREFIX}`;
this.globalApiToken = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
}
private readonly logger = new Logger(ProviderFiles.name);
private baseUrl: string;
private globalApiToken: string;
private readonly config = Object.freeze(this.configService.get<ProviderSession>('PROVIDER'));
get isEnabled() {
return !!this.config?.ENABLED;
}
public async onModuleInit() {
if (this.config.ENABLED) {
const url = `http://${this.config.HOST}:${this.config.PORT}`;
try {
const response = await axios.options(url + '/ping');
if (response?.data != 'pong') {
throw new Error('Offline file provider.');
}
await axios.post(`${url}/session`, { group: this.config.PREFIX }, { headers: { apikey: this.globalApiToken } });
} catch (error) {
this.logger.error(['Failed to connect to the file server', error?.message, error?.stack]);
const pid = process.pid;
execSync(`kill -9 ${pid}`);
}
}
}
public async onModuleDestroy() {
//
}
public async create(instance: string): ResponseProvider {
try {
const response = await axios.post(
`${this.baseUrl}`,
{
instance,
},
{ headers: { apikey: this.globalApiToken } },
);
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}
public async write(instance: string, key: string, data: any): ResponseProvider {
try {
const response = await axios.post(`${this.baseUrl}/${instance}/${key}`, data, {
headers: { apikey: this.globalApiToken },
});
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}
public async read(instance: string, key: string): ResponseProvider {
try {
const response = await axios.get(`${this.baseUrl}/${instance}/${key}`, {
headers: { apikey: this.globalApiToken },
});
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}
public async delete(instance: string, key: string): ResponseProvider {
try {
const response = await axios.delete(`${this.baseUrl}/${instance}/${key}`, {
headers: { apikey: this.globalApiToken },
});
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}
public async allInstances(): ResponseProvider {
try {
const response = await axios.get(`${this.baseUrl}/list-instances`, { headers: { apikey: this.globalApiToken } });
return [{ status: response.status, data: response?.data as string[] }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}
public async removeSession(instance: string): ResponseProvider {
try {
const response = await axios.delete(`${this.baseUrl}/${instance}`, { headers: { apikey: this.globalApiToken } });
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}
}

View File

@@ -68,6 +68,20 @@ export class AuthRepository extends Repository {
} }
} }
public async findByKey(key: string): Promise<AuthRaw> {
try {
this.logger.verbose('finding auth');
if (this.dbSettings.ENABLED) {
this.logger.verbose('finding auth in db');
return await this.authModel.findOne({ apikey: key });
}
return {};
} catch (error) {
return {};
}
}
public async list(): Promise<AuthRaw[]> { public async list(): Promise<AuthRaw[]> {
try { try {
if (this.dbSettings.ENABLED) { if (this.dbSettings.ENABLED) {

Some files were not shown because too many files have changed in this diff Show More