Compare commits

..

145 Commits
2.3.0 ... 2.3.2

Author SHA1 Message Date
Davidson Gomes
c2085b59ea Merge branch 'release/2.3.2'
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
2025-09-02 13:33:39 -03:00
Davidson Gomes
2513f96178 chore: bump version to 2.3.2 in package.json and package-lock.json
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
2025-09-02 13:33:34 -03:00
Davidson Gomes
70a2c18146 Merge branch 'release/2.3.2' 2025-09-02 10:53:10 -03:00
Davidson Gomes
b8953f1431 chore: update CHANGELOG for version 2.3.2
- Added support for socks proxy.
- Included key id in webhook payload for n8n service.
- Enhanced RabbitMQ controller with improved connection management and shutdown procedures.
- Converted outgoing images to JPEG format before sending with Chatwoot.
- Updated baileys dependency to version 6.7.19.
2025-09-02 10:53:00 -03:00
Davidson Gomes
a91a4ad19c Merge pull request #1889 from codingbox2022/main
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
update version
2025-09-01 11:00:37 -03:00
Davidson Gomes
00ba227e15 chore: update baileys dependency to version 6.7.19 2025-09-01 10:43:12 -03:00
codingbox2022
c02d37028b Merge branch 'main' into main 2025-08-29 22:08:52 -05:00
Davidson Gomes
14771ab84e Merge pull request #1851 from caiquezanetoni/patch-1
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
Update 20250116001415_add_wavoip_token_to_settings_table
2025-08-29 07:17:02 -03:00
Davidson Gomes
20352e77ef Merge pull request #1878 from LuisSantosJS/reconnect-rabbitmq
Reconnect rabbitmq
2025-08-29 07:16:13 -03:00
Davidson Gomes
78f7618d04 Merge pull request #1884 from nestordavalos/feat/whatsapp/convert-to-jpeg
Feat/whatsapp/convert-to-jpeg
2025-08-29 07:14:56 -03:00
nestordavalos
57b19d85d5 feat(whatsapp): Convert outgoing images to JPEG before sending
All images sent via the Baileys integration are now pre-processed and converted to JPEG format using the `sharp` library. This ensures better compatibility and prevents potential issues with unsupported formats.

- Images from URLs are now downloaded via axios before processing, which allows for the use of a proxy.
- The default filename and mimetype are updated to `image.jpg` and `image/jpeg` to reflect the conversion.
2025-08-28 00:17:15 -03:00
luissantosjs
b325500310 improve rabbit controller 2025-08-26 19:15:59 +01:00
luissantosjs
4681576cfc up 2025-08-22 22:49:40 +01:00
luissantosjs
7a99fba556 feat: enhance RabbitMQ controller with improved connection management and shutdown procedures 2025-08-20 12:29:45 +01:00
Caíque Zanetoni Fim
6e652d6ea2 Update migration.sql 2025-08-18 08:43:21 -03:00
Davidson Gomes
33a922995b Merge pull request #1838 from bilaliqbalr/patch-2
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
Added key id into webhook payload in n8n service
2025-08-15 12:49:10 -03:00
Bilal Iqbal
74cb65c4ea Added key id into webhook payload in n8n service 2025-08-14 00:51:41 +05:00
Davidson Gomes
f9c4255500 Merge pull request #1809 from neto-developer/patch-1
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
docs(readme): corrigidos badge Docker image no README
2025-08-07 08:22:26 -03:00
Davidson Gomes
af423cef28 Merge pull request #1793 from henrybarreto/feat/add-support-socks-proxy
feat: add support to socks proxy
2025-08-07 08:22:00 -03:00
Davidson Gomes
40ce6b56ca Merge pull request #1790 from henrybarreto/feat/improve-test-proxy-error
feat: enhance logging for proxy testing errors
2025-08-07 08:21:48 -03:00
Neto, Aristides da Silva
4945345519 docs(readme): corrigidos badge Docker image no README
Corrigida formatação do badge Docker image no README
2025-08-05 22:07:20 -03:00
Henry Barreto
ab9e0edad6 feat: enhance logging for proxy testing errors
This commit improves the logging in the testProxy method of the
ProxyController class. Now, when an Axios error occurs, the specific
error message will be logged if available. For unexpected errors, the
error object is included for better insight.

For reference, see the "message" field in the Axios documentation:
[Axios Error Handling](https://axios-http.com/docs/handling_errors).
2025-08-05 07:08:49 -03:00
Henry Barreto
3390958314 feat: add support to socks proxy 2025-08-05 07:08:00 -03:00
Davidson Gomes
a8343a8739 Merge pull request #1802 from frieck/main
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
Securing websockets
2025-08-04 19:18:30 -03:00
Davidson Gomes
dab66fc8c8 Merge pull request #1786 from bilaliqbalr/patch-1
Fixed boolean and integer type attributes for MySQL
2025-08-04 19:17:49 -03:00
Davidson Gomes
03a44cf9b2 Merge pull request #1798 from apresentame/fix/webhook_event
Permitir correta utilização da evolution quando mensagens não são persistidas no DB
2025-08-04 18:52:58 -03:00
Felipe Augusto Rieck
fb11f3f99c Code quality 2025-08-04 18:19:14 -03:00
Felipe Augusto Rieck
d4eb61f64d Improving localhost check 2025-08-04 18:14:33 -03:00
Felipe Augusto Rieck
4f043f9576 Securing websockets 2025-08-04 16:34:20 -03:00
William Dumes
79f4a22217 refactor: lint check 2025-08-04 13:56:16 -03:00
William Dumes
20dd1b1660 Merge branch 'develop' of github.com:apresentame/evolution-api into fix/webhook_event 2025-08-04 13:52:07 -03:00
William Dumes
fe8280ab7b Merge branch 'main' of github.com:apresentame/evolution-api into fix/webhook_event 2025-08-01 09:41:28 -03:00
William Dumes
bc11d0f751 fix: corrigido delete de mensagem quando nao salvo no banco de dados 2025-07-31 17:27:06 -03:00
Bilal Iqbal
095e435561 Fixed boolean and integer type attributes 2025-07-31 14:26:05 +05:00
Davidson Gomes
96f4b80d46 Merge branch 'release/2.3.1' into develop
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
2025-07-29 09:20:29 -03:00
Davidson Gomes
9cdb897a0f Merge branch 'release/1.3.1'
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
2025-07-29 09:20:16 -03:00
Davidson Gomes
b5c67774dc chore: remove CONFIG_SESSION_PHONE_VERSION and update related code
- Removed the CONFIG_SESSION_PHONE_VERSION environment variable from the configuration and Docker files.
- Updated the BaileysStartupService to directly fetch the latest WhatsApp Web version without relying on the removed environment variable.
- Adjusted the index router to reflect the changes in the WhatsApp Web version retrieval.
2025-07-29 09:20:08 -03:00
Davidson Gomes
7f8293f4c6 changelog: v2.3.1 2025-07-29 09:16:19 -03:00
William Dumes
a62f9ebe46 chore: voltar porta do dockerfile 2025-07-28 11:19:07 -03:00
William Dumes
69726f0dc2 fix(evo): melhorado controle de recebimento do ack das msgs 2025-07-28 09:24:22 -03:00
William Dumes
6101c8d651 fix: corrigido disparo de eventos quando nao usa a opcao da ENV de salvar mensagens no banco 2025-07-25 17:08:14 -03:00
Davidson Gomes
c66485ef98 Merge pull request #1748 from coreh/fix-url-corruption-querystring
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
Avoid corrupting media URLs with query strings
2025-07-25 16:56:06 -03:00
Davidson Gomes
4a25cd1ff7 Merge pull request #1757 from KokeroO/develop
fix: atualizar o handle de erros de eventos
2025-07-25 16:54:28 -03:00
Willian Coqueiro
23f54d1d96 lint 2025-07-25 12:13:56 +00:00
Willian Coqueiro
5191438acf fix: update error handling messages and correct group parameter in createContact method 2025-07-25 12:02:17 +00:00
Marco Buono
96d3ec2017 fix: avoid corrupting URLs with query strings 2025-07-23 16:06:14 -03:00
Davidson Gomes
cf95c027eb chore: update package dependencies and scripts
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
- Changed the `baileys` dependency source from `EvolutionAPI` to `WhiskeySockets`.
- Updated the start and development server scripts to use `tsx` instead of `tsnd`.
- Added `tsx` as a new dependency and removed `ts-node-dev`.
- Updated `music-metadata` to version 11.7.1 and adjusted its dependencies.
- Cleaned up the package-lock by removing unused modules and adding new ones like `fflate` and `uint8array-extras`.
2025-07-22 18:21:46 -03:00
Davidson Gomes
9b7ca4bfb7 Merge pull request #1743 from foqc/foqc/develop
Some checks are pending
Build Docker image / Build and Deploy (push) Waiting to run
Add  endpoint to retrieve chat data by remoteJid
2025-07-21 16:13:59 -03:00
foqc
d490f8f576 feature: run lint to clean up codebase 2025-07-21 12:26:08 -05:00
foqc
68e847d10e feature: add endpoint to retrieve chat data by phone number 2025-07-21 12:21:45 -05:00
Davidson Gomes
b98cd11fb1 Merge pull request #1736 from juniortopanotti/main
Some checks are pending
Build Docker image / Build and Deploy (push) Waiting to run
remove lógica de paginação duplicada no fetchChats que causa resultados vazios quando skip > 0
2025-07-21 13:16:22 -03:00
Davidson Gomes
5386d7171b Merge pull request #1732 from rafwell/testmsg
Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE)
2025-07-21 13:15:38 -03:00
Davidson Gomes
f59cae7ee2 Merge pull request #1729 from ricaelchiquetti/main
improv: Ajustado isEmoji para aceitar todos os emojis.
2025-07-21 13:15:17 -03:00
Davidson Gomes
0e358cf9c1 Merge pull request #1696 from foqc/foqc/develop
Preserve alias casing in chat fetch query
2025-07-21 13:14:33 -03:00
Gilberto Topanotti Junior
6954472070 remove lógica de paginação duplicada no fetchChats que causa resultados vazios quando skip > 0
Problema:
O método fetchChats estava aplicando a lógica de paginação duas vezes, causando resultados vazios ao usar o parâmetro skip com valores maiores que 0.
Causa Raiz:
A query SQL já aplica LIMIT e OFFSET corretamente
O código JavaScript então aplica .slice(skip, skip + take) nos resultados já paginados
Este "offset duplo" faz com que o slice tente acessar posições do array que não existem
Exemplo do bug:
Requisição: {"take": 10, "skip": 10}
SQL: LIMIT 10 OFFSET 10 → retorna chats 11-20 (10 itens)
JS: .slice(10, 20) → tenta pegar posições 10-20 de um array com apenas 10 itens
Resultado: [] (array vazio)
Solução:
Removida a lógica de paginação JavaScript redundante (linhas 796-800) já que a query SQL já manipula a paginação corretamente com LIMIT e OFFSET.
Arquivos Alterados:
src/api/services/channel.service.ts
Testes:
 {"take": 10, "skip": 0} - Retorna os primeiros 10 chats
 {"take": 10, "skip": 10} - Retorna chats 11-20 (anteriormente retornava [])
 {"take": 5, "skip": 15} - Retorna chats 16-20 (anteriormente retornava [])
Impacto:
Corrige a funcionalidade de paginação para todos os valores de skip > 0
Mantém compatibilidade com versões anteriores
Sem mudanças que quebrem implementações existentes
2025-07-18 14:20:22 -03:00
Rafael Souza
afd0e01ddb fix lint 2025-07-17 15:59:33 -03:00
Rafael Souza
b3dae7a68e Ignore events that are not messages 2025-07-17 15:40:31 -03:00
Rafael Souza
44d4781f6f Ignore events that are not messages 2025-07-17 15:37:37 -03:00
Rafael Souza
e304b1dcdf Fix erro key 2025-07-17 15:32:25 -03:00
Rafael Souza
f8f2153cb4 Fix erro key 2025-07-17 15:29:04 -03:00
codingbox2022
192c34caa0 Update docker-compose.yaml 2025-07-17 12:47:36 -05:00
Davidson Gomes
cdef7dc9f9 Merge pull request #1728 from KokeroO/develop
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
Fix: [Chatwoot] Corrige mensagens editas
2025-07-17 11:55:55 -03:00
ricael
85798b209c improv: remover o emojiRefex() da função isEmoji. 2025-07-17 09:43:52 -03:00
ricael
71ebecbed3 improv: ajustado a validação aceitar todos os emojis. 2025-07-17 09:17:06 -03:00
Willian Coqueiro
419300b31f refactor: simplify edited message check in BaileysStartupService 2025-07-17 02:24:21 +00:00
Davidson Gomes
9fd40a411a Merge pull request #1726 from Santosl2/feat/add-async-lock
Some checks are pending
Build Docker image / Build and Deploy (push) Waiting to run
feat: add BaileysMessageProcessor for improved message handling
2025-07-16 19:24:23 -03:00
Davidson Gomes
d98fa5259e Merge branch 'develop' into feat/add-async-lock 2025-07-16 19:22:44 -03:00
Santosl2
05886ec684 feat: enhance message processing with retry logic for error handling 2025-07-15 21:41:25 -03:00
Santosl2
89d4d341f6 feat: add BaileysMessageProcessor for improved message handling and integrate rxjs for asynchronous processing 2025-07-15 21:35:25 -03:00
foqc
1ca829c00b feature: run lint to clean up codebase 2025-07-15 16:40:17 -05:00
Davidson Gomes
e321609b93 refactor: Simplify conditional check for contact updates in ChatwootService
Some checks failed
Build Docker image / Build and Deploy (push) Has been cancelled
2025-07-14 14:52:02 -03:00
Davidson Gomes
196617507e Merge pull request #1700 from guilherme-aguilar/guilheme_aguilar/develop
feat(database): add pgbouncer support and optimize postgres config
2025-07-14 14:51:49 -03:00
Davidson Gomes
6da71f5161 Merge pull request #1683 from pauloboc/develop
added missing migrations in mysql prisma
2025-07-14 14:51:21 -03:00
Davidson Gomes
5d0278a589 Merge branch 'develop' into foqc/develop 2025-07-14 14:46:36 -03:00
Davidson Gomes
2fb3eac383 Merge pull request #1715 from AlexisJusviack/fix/getBase64-template-support
Fix: Support media extraction from templateMessage in getBase64FromMediaMessage
2025-07-14 14:44:43 -03:00
Davidson Gomes
4a5696eda9 Merge pull request #1704 from rafwell/develop
Throw exception if download media fail
2025-07-14 14:44:29 -03:00
Davidson Gomes
11520481ba Merge pull request #1705 from KokeroO/develop
fix: Tratar conversas @lid no inicio do recebimento dos eventos e novo erro da libsignal
2025-07-14 14:43:57 -03:00
Davidson Gomes
95a53d33ef Merge pull request #1701 from leonardocintra/patch-1
Update README.md - 2025
2025-07-14 14:43:20 -03:00
Davidson Gomes
d458c978f3 Merge branch 'develop' into develop 2025-07-14 14:42:18 -03:00
AlexisJusviack
bd35d7977c Fix: Support media extraction from templateMessage in getBase64FromMediaMessage
### Fix: Add support for templateMessage media in getBase64FromMediaMessage

#### What this does
Adds support to download media from `templateMessage` structures in `getBase64FromMediaMessage`, by checking for `hydratedTemplate` and `hydratedFourRowTemplate`.

#### Why it's needed
Currently, media inside templates (e.g. `imageMessage`, `videoMessage`, `documentMessage`) is not processed by the method, which leads to errors or media being skipped.

#### How it works
If a `templateMessage` is detected, the code looks into the inner hydrated template and assigns the correct `mediaMessage` and `mediaType`. Then it proceeds as usual with the download logic.

#### Example message
```json
{
  "message": {
    "templateMessage": {
      "hydratedTemplate": {
        "imageMessage": {
          "mimetype": "image/jpeg",
          "fileLength": 123456,
          "url": "https://..."
        }
      }
    }
  }
}
2025-07-11 23:50:58 -03:00
guilherme
e92961e7b0 feat(database): add psql_bouncer support and simplify postgresql config
- Add new psql_bouncer database provider option
- Update database scripts to handle psql_bouncer provider
- Comment out pgbouncer service in docker-compose
- Simplify postgresql schema by removing directUrl
- Add new psql_bouncer-schema.prisma file
- Update .env.example with psql_bouncer configuration
- Modify runWithProvider.js to handle psql_bouncer migrations
2025-07-10 01:08:08 -03:00
Rafael Souza
f11d490f7a Remove package-lock.json do .gititnore 2025-07-09 18:56:32 -03:00
Willian Coqueiro
37319966db Remove redudantent code 2025-07-09 18:42:35 +00:00
Willian Coqueiro
630f5c5624 fix:
- [Baileys] Trocar @lids em remoteJid por senderPn em todos os serviços;
 - [Baileys] Adicionar valor @lid recebido em remoteJid para previousRemoteJid (Posteriormente utilizasse em ChatwootService);
 - Minors fixes;
2025-07-09 18:35:57 +00:00
Leonardo Nascimento Cintra
3e690fe9e2 Update README.md - 2025 2025-07-08 20:00:42 -03:00
guilherme
09429e68fe docs: update database name in .env.example from evolution to evolution_db 2025-07-08 18:09:59 -03:00
Rafael Souza
9acccf723d Throw exception if download media fail 2025-07-08 17:43:21 -03:00
guilherme
3b920f93c5 feat(database): add pgbouncer support and optimize postgres config
- Add pgbouncer service to handle connection pooling
- Update database connection URIs to support direct and pooled connections
- Optimize postgres configuration with better memory settings
- Update prisma schema to support directUrl connection
2025-07-08 17:14:37 -03:00
foqc
85936dcaed feature: Correctly map SQL query results by enforcing quoted column aliases (update missing mappings) 2025-07-07 17:40:30 -05:00
foqc
333ef3eeb8 feature: Correctly map SQL query results by enforcing quoted column aliases 2025-07-07 17:31:49 -05:00
Paulo Ferreira
8dd51b0302 added missing migrations in mysql prisma 2025-07-03 15:20:03 -03:00
Davidson Gomes
e6ec706a38 Merge pull request #1665 from pauloboc/fix-prisma-type-mysql
Fix prisma type mysql
2025-07-02 11:22:48 -03:00
Davidson Gomes
53101d4571 Merge pull request #1664 from pauloboc/fix-setup-mysql
(mysql): remove out-of-order wavoipToken migration
2025-07-01 08:15:26 -03:00
Davidson Gomes
c7b5abce6e Merge pull request #1670 from Santosl2/fix/typebot-variables
fix: correçao do typebot não conseguir ouvir mensagens de input
2025-07-01 08:14:28 -03:00
Santosl2
5b1b5ff9d2 fix: bind applyFormatting method in processMessages to maintain context 2025-06-29 20:23:31 -03:00
codingbox2022
505490d237 Update docker-compose.yaml 2025-06-28 22:36:21 -05:00
codingbox2022
675745ae3c Update docker-compose.yaml 2025-06-28 22:28:42 -05:00
codingbox2022
6dfbfe2d83 Update docker-compose.yaml 2025-06-28 22:27:42 -05:00
codingbox2022
1c247498d8 Update docker-compose.yaml 2025-06-28 22:25:44 -05:00
codingbox2022
419324837c Update docker-compose.yaml 2025-06-28 22:05:12 -05:00
codingbox2022
17f97fb051 Update docker-compose.yaml 2025-06-28 22:03:45 -05:00
codingbox2022
f7e7a6c901 Update docker-compose.yaml 2025-06-28 22:02:34 -05:00
codingbox2022
b35b33ca50 Update docker-compose.yaml 2025-06-28 22:00:52 -05:00
Paulo Ferreira
3efe69ada3 fix(prisma) Mysql: update data types for N8n, N8nSetting, Evoai, and EvoaiSetting models 2025-06-28 09:34:52 -03:00
Paulo Ferreira
287c679ce4 (mysql): remove out-of-order wavoipToken migration
Delete prisma/mysql-migrations/1707735894523_add_wavoip_token_to_settings_table, which executes before the initial Setting table is created and breaks fresh MySQL installs.

The later migration 20250214181954_add_wavoip_token_column, line 145, already adds the column correctly, so keeping only that directory guarantees a clean deploy.
2025-06-28 09:27:13 -03:00
Davidson Gomes
918697866f fix(package-lock): update baileys dependency to latest commit hash 2025-06-27 09:59:40 -03:00
Davidson Gomes
3c917af602 Merge pull request #1660 from KokeroO/develop
fix(whatsapp-baileys): Verifica eventos com falhas e fallback para erro ao baixar mídias
2025-06-27 09:55:22 -03:00
KokeroO
52798fd761 fix(whatsapp-baileys): adjust indentation and access modifier for getBase64FromMediaMessage method 2025-06-27 09:29:12 -03:00
KokeroO
34446d188e fix(whatsapp-baileys):
- Implement broken event checking before duplicate message checking. (Do not process failed events).
- Implement error handling when downloading media with a fallback mechanism.
2025-06-27 09:03:32 -03:00
Davidson Gomes
ef31b6de1f Merge pull request #1655 from KokeroO/develop
fix/references-instanceName-typebot
2025-06-26 17:10:58 -03:00
KokeroO
d7afe5d7ab fix(typebot): update instance query to use instance name instead of instance ID 2025-06-26 14:53:54 -03:00
Davidson Gomes
72fb2f408b feat(rabbitmq): implement robust connection handling with reconnection logic and error logging 2025-06-26 14:25:37 -03:00
KokeroO
e4f7856ca9 fix(typebot): update instance query to use instanceName instead of instanceId 2025-06-26 14:05:28 -03:00
Davidson Gomes
e86b6463fd Merge pull request #1652 from KokeroO/patch-1
Corrige ref. instance typebot.controller.ts
2025-06-26 11:49:41 -03:00
Willian Coqueiro
0302944654 Corrige ref. instance typebot.controller.ts 2025-06-26 11:42:27 -03:00
Davidson Gomes
1b0d81b022 Merge pull request #1641 from caduzin02/patch-1
Create railway.json
2025-06-25 16:32:30 -03:00
Davidson Gomes
854d357518 chore(package-lock): update Baileys dependency to version 6.7.18 2025-06-25 16:25:16 -03:00
caduzin02
6e8da4a8dc Create railway.json 2025-06-24 11:02:00 -03:00
Davidson Gomes
e92e98dd22 chore: optimize Dockerfile by using npm ci for dependency installation and streamlining file copy operations 2025-06-23 16:55:04 -03:00
Davidson Gomes
cdd2e59755 chore: update CHANGELOG for version 2.3.1 to include fix for S3 media upload 2025-06-23 16:51:54 -03:00
Davidson Gomes
1a1d9fc957 refactor: add validation for media content in Evolution and Business services to enhance error handling 2025-06-23 16:42:29 -03:00
Davidson Gomes
8ea4d65bc2 refactor: enhance media handling in Baileys service with validation for valid media content 2025-06-23 16:42:24 -03:00
Davidson Gomes
af713dee55 chore: update Dockerfile to use npm run build instead of npm run build:docker 2025-06-23 16:00:01 -03:00
Davidson Gomes
ee9ccb55ca chore: update version to 2.3.1 in Dockerfile, package.json, and package-lock.json 2025-06-23 15:41:49 -03:00
Davidson Gomes
977f686233 chore: update CHANGELOG for version 2.3.1 and fix package.json formatting 2025-06-23 15:38:54 -03:00
Davidson Gomes
a38caeaf5f chore(package-lock): update Baileys dependency to version 6.7.18 2025-06-23 15:36:54 -03:00
Davidson Gomes
873fdcb22a Merge pull request #1633 from VCalazans/FIX/ISSUE-28
🐛 fix: Phone number as message ID for Evo AI #ISSUE 28
2025-06-23 15:35:56 -03:00
Davidson Gomes
2e077a77ef Merge pull request #1626 from fernandeshenrique15/main
add unreadMessages in the response
2025-06-23 15:35:44 -03:00
Davidson Gomes
4be818a436 Merge pull request #1605 from ToniShelby/patch-2
Update Dockerfile
2025-06-23 15:35:33 -03:00
Davidson Gomes
a7badb9af5 Merge pull request #1624 from matheusfterra/main
Correção do envio de variáveis pelo typeboy
2025-06-23 15:35:20 -03:00
Davidson Gomes
ba5fb567eb Merge branch 'develop' into patch-2 2025-06-23 15:34:54 -03:00
Davidson Gomes
1070caf131 Merge pull request #1609 from KokeroO/feat/merge-contacts-lid-in-message-upsert
feat: Adiciona mesclagem de contatos @lid no Chatwoot
2025-06-23 15:32:46 -03:00
Davidson Gomes
9766e10ce9 Merge pull request #1623 from skarious/main
Update Dockerhub Repository and Delete Config Session Variable
2025-06-23 15:32:00 -03:00
Davidson Gomes
cc5612822f Merge pull request #1635 from autonomaia/patch-8
fix: corrige versão inválida do swagger-ui-express
2025-06-23 15:30:58 -03:00
autonomaia
83c1040114 fix: corrige versão inválida do swagger-ui-express 2025-06-22 22:10:51 -03:00
Victor Calazans
b4d1148d6a 🐛 fix: Phone number as message ID for Evo AI 2025-06-22 09:40:14 -03:00
Henrique Fernandes Neto
bd94423e5b add unreadMessages in the response 2025-06-19 16:30:57 -03:00
Matheus Terra
94670cbca3 Merge pull request #1 from matheusfterra/codex/corrigir-erro-ao-processar-mensagens-com-variáveis
Fix Typebot formatting function
2025-06-19 12:45:33 -03:00
Matheus Terra
bda3f5f146 Fix applyFormatting context in Typebot service 2025-06-19 12:45:09 -03:00
Ron Schneider
7724fe3a4f Merge branch 'main' into main 2025-06-19 02:11:50 -03:00
Ron Schneider
8b5f49592a Update evolution_api_v2.yaml
Update EvolutionApi DockerHub Repository and Delete Config Session Variable
2025-06-19 02:02:59 -03:00
Willian Coqueiro
6c0082cd7a feat: adicionar funcionalidade de mesclagem de contatos no Chatwoot 2025-06-17 22:33:51 +00:00
ToniShelby
3391b2ce4b Update Dockerfile 2025-06-17 16:33:50 +01:00
Ron Schneider
9db56560e4 Merge pull request #1 from skarious/skarious-patch-1
CONFIG_SESSION_PHONE_VERSION Updated
2025-05-29 14:06:12 -03:00
Ron Schneider
786e57603f CONFIG_SESSION_PHONE_VERSION Updated
CONFIG_SESSION_PHONE_VERSION updated
2025-05-29 14:05:42 -03:00
43 changed files with 4061 additions and 2623 deletions

View File

@@ -1,7 +1,6 @@
.git
*Dockerfile*
*docker-compose*
package-lock.json
.env
node_modules
dist

View File

@@ -27,13 +27,17 @@ EVENT_EMITTER_MAX_LISTENERS=50
# If you don't even want an expiration, enter the value false
DEL_INSTANCE=false
# Provider: postgresql | mysql
# Provider: postgresql | mysql | psql_bouncer
DATABASE_PROVIDER=postgresql
DATABASE_CONNECTION_URI='postgresql://user:pass@postgres:5432/evolution?schema=public'
DATABASE_CONNECTION_URI='postgresql://user:pass@postgres:5432/evolution_db?schema=evolution_api'
# Client name for the database connection
# It is used to separate an API installation from another that uses the same database.
DATABASE_CONNECTION_CLIENT_NAME=evolution_exchange
# Bouncer connection: used only when the database provider is set to 'psql_bouncer'.
# Defines the PostgreSQL URL with pgbouncer enabled (pgbouncer=true).
# DATABASE_BOUNCER_CONNECTION_URI=postgresql://user:pass@pgbouncer:5432/evolution_db?pgbouncer=true&schema=evolution_api
# Choose the data you want to save in the application's database
DATABASE_SAVE_DATA_INSTANCE=true
DATABASE_SAVE_DATA_NEW_MESSAGE=true
@@ -196,7 +200,7 @@ CONFIG_SESSION_PHONE_NAME=Chrome
# Whatsapp Web version for baileys channel
# https://web.whatsapp.com/check-update?version=0&platform=web
# CONFIG_SESSION_PHONE_VERSION=2.3000.1023204200
# Set qrcode display limit
QRCODE_LIMIT=30

View File

@@ -1,3 +1,35 @@
# 2.3.2 (2025-09-02)
### Features
* Add support to socks proxy
### Fixed
* Added key id into webhook payload in n8n service
* Enhance RabbitMQ controller with improved connection management and shutdown procedures
* Convert outgoing images to JPEG before sending with Chatwoot
* Update baileys dependency to version 6.7.19
# 2.3.1 (2025-07-29)
### Feature
* Add BaileysMessageProcessor for improved message handling and integrate rxjs for asynchronous processing
* Enhance message processing with retry logic for error handling
### Fixed
* Update Baileys Version
* Update Dockerhub Repository and Delete Config Session Variable
* Fixed sending variables in typebot
* Add unreadMessages in the response
* Phone number as message ID for Evo AI
* Fix upload to s3 when media message
* Simplify edited message check in BaileysStartupService
* Avoid corrupting URLs with query strings
* Removed CONFIG_SESSION_PHONE_VERSION environment variable
# 2.3.0 (2025-06-17 09:19)
### Feature

View File

@@ -6,7 +6,7 @@ if [ "$DOCKER_ENV" != "true" ]; then
export_env_vars
fi
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then
export DATABASE_URL
echo "Deploying migrations for $DATABASE_PROVIDER"
echo "Database URL: $DATABASE_URL"

View File

@@ -6,7 +6,7 @@ if [ "$DOCKER_ENV" != "true" ]; then
export_env_vars
fi
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then
export DATABASE_URL
echo "Generating database for $DATABASE_PROVIDER"
echo "Database URL: $DATABASE_URL"
@@ -20,4 +20,4 @@ if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]
else
echo "Error: Database provider $DATABASE_PROVIDER invalid."
exit 1
fi
fi

View File

@@ -2,7 +2,7 @@ version: "3.7"
services:
evolution_v2:
image: atendai/evolution-api:v2.2.3
image: evoapicloud/evolution-api:v2.3.1
volumes:
- evolution_instances:/evolution/instances
networks:
@@ -94,7 +94,6 @@ services:
- WEBHOOK_EVENTS_ERRORS_WEBHOOK=
- CONFIG_SESSION_PHONE_CLIENT=Evolution API V2
- CONFIG_SESSION_PHONE_NAME=Chrome
- CONFIG_SESSION_PHONE_VERSION=2.3000.1023204200
- QRCODE_LIMIT=30
- OPENAI_ENABLED=true
- DIFY_ENABLED=true

View File

@@ -3,15 +3,17 @@ FROM node:20-alpine AS builder
RUN apk update && \
apk add --no-cache git ffmpeg wget curl bash openssl
LABEL version="2.3.0" description="Api to control whatsapp features through http requests."
LABEL version="2.3.1" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
LABEL contact="contato@evolution-api.com"
WORKDIR /evolution
COPY ./package.json ./tsconfig.json ./
COPY ./package*.json ./
COPY ./tsconfig.json ./
COPY ./tsup.config.ts ./
RUN npm install
RUN npm ci --silent
COPY ./src ./src
COPY ./public ./public
@@ -19,7 +21,6 @@ COPY ./prisma ./prisma
COPY ./manager ./manager
COPY ./.env.example ./.env
COPY ./runWithProvider.js ./
COPY ./tsup.config.ts ./
COPY ./Docker ./Docker
@@ -35,6 +36,7 @@ RUN apk update && \
apk add tzdata ffmpeg bash openssl
ENV TZ=America/Sao_Paulo
ENV DOCKER_ENV=true
WORKDIR /evolution
@@ -55,4 +57,4 @@ ENV DOCKER_ENV=true
EXPOSE 8080
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]

View File

@@ -2,7 +2,7 @@
<div align="center">
[![Docker Image (https://img.shields.io/badge/Docker-Image-blue)](https://hub.docker.com/r/evoapicloud/evolution-api)]
[![Docker Image](https://img.shields.io/badge/Docker-image-blue)](https://hub.docker.com/r/evoapicloud/evolution-api)
[![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp)
[![Discord Community](https://img.shields.io/badge/Discord-Community-blue)](https://evolution-api.com/discord)
[![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange)](https://evolution-api.com/postman)
@@ -117,4 +117,4 @@ Please contact contato@evolution-api.com to inquire about licensing matters.
Apart from the specific conditions mentioned above, all other rights and restrictions follow the Apache License 2.0. Detailed information about the Apache License 2.0 can be found at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
© 2024 Evolution API
© 2025 Evolution API

View File

@@ -1,3 +1,5 @@
version: "3.8"
services:
api:
container_name: evolution_api
@@ -5,56 +7,69 @@ services:
restart: always
depends_on:
- redis
- postgres
- evolution-postgres
ports:
- 8080:8080
- "127.0.0.1:8080:8080"
volumes:
- evolution_instances:/evolution/instances
networks:
- evolution-net
- dokploy-network
env_file:
- .env
expose:
- 8080
- "8080"
redis:
container_name: evolution_redis
image: redis:latest
networks:
- evolution-net
container_name: redis
restart: always
command: >
redis-server --port 6379 --appendonly yes
volumes:
- evolution_redis:/data
ports:
- 6379:6379
postgres:
container_name: postgres
image: postgres:15
networks:
- evolution-net
command: ["postgres", "-c", "max_connections=1000", "-c", "listen_addresses=*"]
evolution-net:
aliases:
- evolution-redis
dokploy-network:
aliases:
- evolution-redis
expose:
- "6379"
evolution-postgres:
container_name: evolution_postgres
image: postgres:15
restart: always
ports:
- 5432:5432
env_file:
- .env
command:
- postgres
- -c
- max_connections=1000
- -c
- listen_addresses=*
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=evolution
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_DB=${POSTGRES_DATABASE}
- POSTGRES_USER=${POSTGRES_USERNAME}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- evolution-net
- dokploy-network
expose:
- 5432
- "5432"
volumes:
evolution_instances:
evolution_redis:
postgres_data:
networks:
evolution-net:
name: evolution-net
driver: bridge
dokploy-network:
external: true

4267
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,15 @@
{
"name": "evolution-api",
"version": "2.3.0",
"version": "2.3.2",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/main.js",
"type": "commonjs",
"scripts": {
"build": "tsc --noEmit && tsup",
"start": "tsnd -r tsconfig-paths/register --files --transpile-only ./src/main.ts",
"start": "tsx ./src/main.ts",
"start:prod": "node dist/main",
"dev:server": "tsnd -r tsconfig-paths/register --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts",
"test": "tsnd -r tsconfig-paths/register --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts",
"dev:server": "tsx watch ./src/main.ts",
"test": "tsx watch ./test/all.test.ts",
"lint": "eslint --fix --ext .ts src",
"lint:check": "eslint --ext .ts src",
"db:generate": "node runWithProvider.js \"npx prisma generate --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
@@ -60,12 +60,13 @@
"amqplib": "^0.10.5",
"audio-decode": "^2.2.3",
"axios": "^1.7.9",
"baileys": "github:EvolutionAPI/Baileys",
"baileys": "github:WhiskeySockets/Baileys",
"class-validator": "^0.14.1",
"compression": "^1.7.5",
"cors": "^2.8.5",
"dayjs": "^1.11.13",
"dotenv": "^16.4.7",
"emoji-regex": "^10.4.0",
"eventemitter2": "^6.4.9",
"express": "^4.21.2",
"express-async-errors": "^3.1.1",
@@ -73,7 +74,7 @@
"form-data": "^4.0.1",
"https-proxy-agent": "^7.0.6",
"i18next": "^23.7.19",
"jimp": "^0.16.13",
"jimp": "^1.6.0",
"json-schema": "^0.4.0",
"jsonschema": "^1.4.1",
"jsonwebtoken": "^9.0.2",
@@ -95,9 +96,12 @@
"qrcode": "^1.5.4",
"qrcode-terminal": "^0.12.0",
"redis": "^4.7.0",
"sharp": "^0.32.6",
"rxjs": "^7.8.2",
"sharp": "^0.34.2",
"socket.io": "^4.8.1",
"socket.io-client": "^4.8.1",
"socks-proxy-agent": "^8.0.5",
"swagger-ui-express": "^5.0.1",
"tsup": "^8.3.5"
},
"devDependencies": {
@@ -120,8 +124,8 @@
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"prettier": "^3.4.2",
"ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.20.3",
"typescript": "^5.7.2"
}
}

View File

@@ -1,9 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Chat` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE `Setting`
ADD COLUMN IF NOT EXISTS `wavoipToken` VARCHAR(100);

View File

@@ -0,0 +1,17 @@
-- CreateTable
CREATE TABLE `Nats` (
`id` VARCHAR(191) NOT NULL,
`enabled` BOOLEAN NOT NULL DEFAULT false,
`events` JSON NOT NULL,
`createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL,
`instanceId` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `Nats_instanceId_key` ON `Nats`(`instanceId`);
-- AddForeignKey
ALTER TABLE `Nats` ADD CONSTRAINT `Nats_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,62 @@
-- CreateTable
CREATE TABLE `N8n` (
`id` VARCHAR(191) NOT NULL,
`enabled` BOOLEAN NOT NULL DEFAULT true,
`description` VARCHAR(255),
`webhookUrl` VARCHAR(255),
`basicAuthUser` VARCHAR(255),
`basicAuthPass` VARCHAR(255),
`expire` INTEGER DEFAULT 0,
`keywordFinish` VARCHAR(100),
`delayMessage` INTEGER,
`unknownMessage` VARCHAR(100),
`listeningFromMe` BOOLEAN DEFAULT false,
`stopBotFromMe` BOOLEAN DEFAULT false,
`keepOpen` BOOLEAN DEFAULT false,
`debounceTime` INTEGER,
`ignoreJids` JSON,
`splitMessages` BOOLEAN DEFAULT false,
`timePerChar` INTEGER DEFAULT 50,
`triggerType` ENUM('all', 'keyword', 'none') NULL,
`triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL,
`triggerValue` VARCHAR(191) NULL,
`createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL,
`instanceId` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `N8nSetting` (
`id` VARCHAR(191) NOT NULL,
`expire` INTEGER DEFAULT 0,
`keywordFinish` VARCHAR(100),
`delayMessage` INTEGER,
`unknownMessage` VARCHAR(100),
`listeningFromMe` BOOLEAN DEFAULT false,
`stopBotFromMe` BOOLEAN DEFAULT false,
`keepOpen` BOOLEAN DEFAULT false,
`debounceTime` INTEGER,
`ignoreJids` JSON,
`splitMessages` BOOLEAN DEFAULT false,
`timePerChar` INTEGER DEFAULT 50,
`createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL,
`n8nIdFallback` VARCHAR(100),
`instanceId` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `N8nSetting_instanceId_key` ON `N8nSetting`(`instanceId`);
-- AddForeignKey
ALTER TABLE `N8n` ADD CONSTRAINT `N8n_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `N8nSetting` ADD CONSTRAINT `N8nSetting_n8nIdFallback_fkey` FOREIGN KEY (`n8nIdFallback`) REFERENCES `N8n`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `N8nSetting` ADD CONSTRAINT `N8nSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,61 @@
-- CreateTable
CREATE TABLE `Evoai` (
`id` VARCHAR(191) NOT NULL,
`enabled` BOOLEAN NOT NULL DEFAULT true,
`description` VARCHAR(255),
`agentUrl` VARCHAR(255),
`apiKey` VARCHAR(255),
`expire` INTEGER DEFAULT 0,
`keywordFinish` VARCHAR(100),
`delayMessage` INTEGER,
`unknownMessage` VARCHAR(100),
`listeningFromMe` BOOLEAN DEFAULT false,
`stopBotFromMe` BOOLEAN DEFAULT false,
`keepOpen` BOOLEAN DEFAULT false,
`debounceTime` INTEGER,
`ignoreJids` JSON,
`splitMessages` BOOLEAN DEFAULT false,
`timePerChar` INTEGER DEFAULT 50,
`triggerType` ENUM('all', 'keyword', 'none') NULL,
`triggerOperator` ENUM('contains', 'equals', 'startsWith', 'endsWith', 'regex') NULL,
`triggerValue` VARCHAR(191) NULL,
`createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL,
`instanceId` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `EvoaiSetting` (
`id` VARCHAR(191) NOT NULL,
`expire` INTEGER DEFAULT 0,
`keywordFinish` VARCHAR(100),
`delayMessage` INTEGER,
`unknownMessage` VARCHAR(100),
`listeningFromMe` BOOLEAN DEFAULT false,
`stopBotFromMe` BOOLEAN DEFAULT false,
`keepOpen` BOOLEAN DEFAULT false,
`debounceTime` INTEGER,
`ignoreJids` JSON,
`splitMessages` BOOLEAN DEFAULT false,
`timePerChar` INTEGER DEFAULT 50,
`createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NOT NULL,
`evoaiIdFallback` VARCHAR(100),
`instanceId` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `EvoaiSetting_instanceId_key` ON `EvoaiSetting`(`instanceId`);
-- AddForeignKey
ALTER TABLE `Evoai` ADD CONSTRAINT `Evoai_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `EvoaiSetting` ADD CONSTRAINT `EvoaiSetting_evoaiIdFallback_fkey` FOREIGN KEY (`evoaiIdFallback`) REFERENCES `Evoai`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `EvoaiSetting` ADD CONSTRAINT `EvoaiSetting_instanceId_fkey` FOREIGN KEY (`instanceId`) REFERENCES `Instance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,2 @@
-- DropIndex
ALTER TABLE `Media` DROP INDEX `Media_fileName_key`;

View File

@@ -0,0 +1,7 @@
-- AlterTable
ALTER TABLE `Typebot` ADD COLUMN `splitMessages` BOOLEAN DEFAULT false,
ADD COLUMN `timePerChar` INTEGER DEFAULT 50;
-- AlterTable
ALTER TABLE `TypebotSetting` ADD COLUMN `splitMessages` BOOLEAN DEFAULT false,
ADD COLUMN `timePerChar` INTEGER DEFAULT 50;

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `IsOnWhatsapp` ADD COLUMN `lid` VARCHAR(100);

View File

@@ -647,22 +647,22 @@ model IsOnWhatsapp {
model N8n {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
enabled Boolean @default(true) @db.TinyInt(1)
description String? @db.VarChar(255)
webhookUrl String? @db.VarChar(255)
basicAuthUser String? @db.VarChar(255)
basicAuthPass String? @db.VarChar(255)
expire Int? @default(0) @db.Integer
expire Int? @default(0) @db.Int
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
delayMessage Int? @db.Int
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
listeningFromMe Boolean? @default(false)
stopBotFromMe Boolean? @default(false)
keepOpen Boolean? @default(false)
debounceTime Int? @db.Int
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
splitMessages Boolean? @default(false)
timePerChar Int? @default(50) @db.Int
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
@@ -675,17 +675,17 @@ model N8n {
model N8nSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
expire Int? @default(0) @db.Int
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
delayMessage Int? @db.Int
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
listeningFromMe Boolean? @default(false)
stopBotFromMe Boolean? @default(false)
keepOpen Boolean? @default(false)
debounceTime Int? @db.Int
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
splitMessages Boolean? @default(false)
timePerChar Int? @default(50) @db.Int
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback N8n? @relation(fields: [n8nIdFallback], references: [id])
@@ -696,21 +696,21 @@ model N8nSetting {
model Evoai {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
enabled Boolean @default(true) @db.TinyInt(1)
description String? @db.VarChar(255)
agentUrl String? @db.VarChar(255)
apiKey String? @db.VarChar(255)
expire Int? @default(0) @db.Integer
expire Int? @default(0) @db.Int
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
delayMessage Int? @db.Int
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
listeningFromMe Boolean? @default(false)
stopBotFromMe Boolean? @default(false)
keepOpen Boolean? @default(false)
debounceTime Int? @db.Int
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
splitMessages Boolean? @default(false)
timePerChar Int? @default(50) @db.Int
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
@@ -723,17 +723,17 @@ model Evoai {
model EvoaiSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
expire Int? @default(0) @db.Int
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
delayMessage Int? @db.Int
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
listeningFromMe Boolean? @default(false)
stopBotFromMe Boolean? @default(false)
keepOpen Boolean? @default(false)
debounceTime Int? @db.Int
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
splitMessages Boolean? @default(false)
timePerChar Int? @default(50) @db.Int
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback Evoai? @relation(fields: [evoaiIdFallback], references: [id])

View File

@@ -6,14 +6,4 @@ Warnings:
*/
-- AlterTable
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'Setting'
AND column_name = 'wavoipToken'
) THEN
ALTER TABLE "Setting" ADD COLUMN "wavoipToken" VARCHAR(100);
END IF;
END $$;
ALTER TABLE "Setting" ADD COLUMN IF NOT EXISTS "wavoipToken" VARCHAR(100);

View File

@@ -376,8 +376,8 @@ model TypebotSetting {
debounceTime Int? @db.Integer
typebotIdFallback String? @db.VarChar(100)
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id])
@@ -748,4 +748,4 @@ model EvoaiSetting {
evoaiIdFallback String? @db.VarChar(100)
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
}

View File

@@ -0,0 +1,752 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_BOUNCER_CONNECTION_URI")
directUrl = env("DATABASE_CONNECTION_URI")
}
enum InstanceConnectionStatus {
open
close
connecting
}
enum DeviceMessage {
ios
android
web
unknown
desktop
}
enum SessionStatus {
opened
closed
paused
}
enum TriggerType {
all
keyword
none
advanced
}
enum TriggerOperator {
contains
equals
startsWith
endsWith
regex
}
enum OpenaiBotType {
assistant
chatCompletion
}
enum DifyBotType {
chatBot
textGenerator
agent
workflow
}
model Instance {
id String @id @default(cuid())
name String @unique @db.VarChar(255)
connectionStatus InstanceConnectionStatus @default(open)
ownerJid String? @db.VarChar(100)
profileName String? @db.VarChar(100)
profilePicUrl String? @db.VarChar(500)
integration String? @db.VarChar(100)
number String? @db.VarChar(100)
businessId String? @db.VarChar(100)
token String? @db.VarChar(255)
clientName String? @db.VarChar(100)
disconnectionReasonCode Int? @db.Integer
disconnectionObject Json? @db.JsonB
disconnectionAt DateTime? @db.Timestamp
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime? @updatedAt @db.Timestamp
Chat Chat[]
Contact Contact[]
Message Message[]
Webhook Webhook?
Chatwoot Chatwoot?
Label Label[]
Proxy Proxy?
Setting Setting?
Rabbitmq Rabbitmq?
Nats Nats?
Sqs Sqs?
Websocket Websocket?
Typebot Typebot[]
Session Session?
MessageUpdate MessageUpdate[]
TypebotSetting TypebotSetting?
Media Media[]
OpenaiCreds OpenaiCreds[]
OpenaiBot OpenaiBot[]
OpenaiSetting OpenaiSetting?
Template Template[]
Dify Dify[]
DifySetting DifySetting?
IntegrationSession IntegrationSession[]
EvolutionBot EvolutionBot[]
EvolutionBotSetting EvolutionBotSetting?
Flowise Flowise[]
FlowiseSetting FlowiseSetting?
Pusher Pusher?
N8n N8n[]
N8nSetting N8nSetting[]
Evoai Evoai[]
EvoaiSetting EvoaiSetting?
}
model Session {
id String @id @default(cuid())
sessionId String @unique
creds String? @db.Text
createdAt DateTime @default(now()) @db.Timestamp
Instance Instance @relation(fields: [sessionId], references: [id], onDelete: Cascade)
}
model Chat {
id String @id @default(cuid())
remoteJid String @db.VarChar(100)
name String? @db.VarChar(100)
labels Json? @db.JsonB
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime? @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
unreadMessages Int @default(0)
@@index([instanceId])
@@index([remoteJid])
}
model Contact {
id String @id @default(cuid())
remoteJid String @db.VarChar(100)
pushName String? @db.VarChar(100)
profilePicUrl String? @db.VarChar(500)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime? @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
@@unique([remoteJid, instanceId])
@@index([remoteJid])
@@index([instanceId])
}
model Message {
id String @id @default(cuid())
key Json @db.JsonB
pushName String? @db.VarChar(100)
participant String? @db.VarChar(100)
messageType String @db.VarChar(100)
message Json @db.JsonB
contextInfo Json? @db.JsonB
source DeviceMessage
messageTimestamp Int @db.Integer
chatwootMessageId Int? @db.Integer
chatwootInboxId Int? @db.Integer
chatwootConversationId Int? @db.Integer
chatwootContactInboxSourceId String? @db.VarChar(100)
chatwootIsRead Boolean? @db.Boolean
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
MessageUpdate MessageUpdate[]
Media Media?
webhookUrl String? @db.VarChar(500)
status String? @db.VarChar(30)
sessionId String?
session IntegrationSession? @relation(fields: [sessionId], references: [id])
@@index([instanceId])
}
model MessageUpdate {
id String @id @default(cuid())
keyId String @db.VarChar(100)
remoteJid String @db.VarChar(100)
fromMe Boolean @db.Boolean
participant String? @db.VarChar(100)
pollUpdates Json? @db.JsonB
status String @db.VarChar(30)
Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade)
messageId String
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
@@index([instanceId])
@@index([messageId])
}
model Webhook {
id String @id @default(cuid())
url String @db.VarChar(500)
headers Json? @db.JsonB
enabled Boolean? @default(true) @db.Boolean
events Json? @db.JsonB
webhookByEvents Boolean? @default(false) @db.Boolean
webhookBase64 Boolean? @default(false) @db.Boolean
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
@@index([instanceId])
}
model Chatwoot {
id String @id @default(cuid())
enabled Boolean? @default(true) @db.Boolean
accountId String? @db.VarChar(100)
token String? @db.VarChar(100)
url String? @db.VarChar(500)
nameInbox String? @db.VarChar(100)
signMsg Boolean? @default(false) @db.Boolean
signDelimiter String? @db.VarChar(100)
number String? @db.VarChar(100)
reopenConversation Boolean? @default(false) @db.Boolean
conversationPending Boolean? @default(false) @db.Boolean
mergeBrazilContacts Boolean? @default(false) @db.Boolean
importContacts Boolean? @default(false) @db.Boolean
importMessages Boolean? @default(false) @db.Boolean
daysLimitImportMessages Int? @db.Integer
organization String? @db.VarChar(100)
logo String? @db.VarChar(500)
ignoreJids Json?
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Label {
id String @id @default(cuid())
labelId String? @db.VarChar(100)
name String @db.VarChar(100)
color String @db.VarChar(100)
predefinedId String? @db.VarChar(100)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
@@unique([labelId, instanceId])
}
model Proxy {
id String @id @default(cuid())
enabled Boolean @default(false) @db.Boolean
host String @db.VarChar(100)
port String @db.VarChar(100)
protocol String @db.VarChar(100)
username String @db.VarChar(100)
password String @db.VarChar(100)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Setting {
id String @id @default(cuid())
rejectCall Boolean @default(false) @db.Boolean
msgCall String? @db.VarChar(100)
groupsIgnore Boolean @default(false) @db.Boolean
alwaysOnline Boolean @default(false) @db.Boolean
readMessages Boolean @default(false) @db.Boolean
readStatus Boolean @default(false) @db.Boolean
syncFullHistory Boolean @default(false) @db.Boolean
wavoipToken String? @db.VarChar(100)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
@@index([instanceId])
}
model Rabbitmq {
id String @id @default(cuid())
enabled Boolean @default(false) @db.Boolean
events Json @db.JsonB
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Nats {
id String @id @default(cuid())
enabled Boolean @default(false) @db.Boolean
events Json @db.JsonB
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Sqs {
id String @id @default(cuid())
enabled Boolean @default(false) @db.Boolean
events Json @db.JsonB
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Websocket {
id String @id @default(cuid())
enabled Boolean @default(false) @db.Boolean
events Json @db.JsonB
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Pusher {
id String @id @default(cuid())
enabled Boolean @default(false) @db.Boolean
appId String @db.VarChar(100)
key String @db.VarChar(100)
secret String @db.VarChar(100)
cluster String @db.VarChar(100)
useTLS Boolean @default(false) @db.Boolean
events Json @db.JsonB
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Typebot {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
description String? @db.VarChar(255)
url String @db.VarChar(500)
typebot String @db.VarChar(100)
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime? @updatedAt @db.Timestamp
ignoreJids Json?
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
TypebotSetting TypebotSetting[]
}
model TypebotSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
typebotIdFallback String? @db.VarChar(100)
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id])
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Media {
id String @id @default(cuid())
fileName String @db.VarChar(500)
type String @db.VarChar(100)
mimetype String @db.VarChar(100)
createdAt DateTime? @default(now()) @db.Date
Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade)
messageId String @unique
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
}
model OpenaiCreds {
id String @id @default(cuid())
name String? @unique @db.VarChar(255)
apiKey String? @unique @db.VarChar(255)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
OpenaiAssistant OpenaiBot[]
OpenaiSetting OpenaiSetting?
}
model OpenaiBot {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
description String? @db.VarChar(255)
botType OpenaiBotType
assistantId String? @db.VarChar(255)
functionUrl String? @db.VarChar(500)
model String? @db.VarChar(100)
systemMessages Json? @db.JsonB
assistantMessages Json? @db.JsonB
userMessages Json? @db.JsonB
maxTokens Int? @db.Integer
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
ignoreJids Json?
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
OpenaiCreds OpenaiCreds @relation(fields: [openaiCredsId], references: [id], onDelete: Cascade)
openaiCredsId String
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
OpenaiSetting OpenaiSetting[]
}
model IntegrationSession {
id String @id @default(cuid())
sessionId String @db.VarChar(255)
remoteJid String @db.VarChar(100)
pushName String?
status SessionStatus
awaitUser Boolean @default(false) @db.Boolean
context Json?
type String? @db.VarChar(100)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Message Message[]
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
parameters Json? @db.JsonB
botId String?
}
model OpenaiSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
speechToText Boolean? @default(false) @db.Boolean
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
OpenaiCreds OpenaiCreds? @relation(fields: [openaiCredsId], references: [id])
openaiCredsId String @unique
Fallback OpenaiBot? @relation(fields: [openaiIdFallback], references: [id])
openaiIdFallback String? @db.VarChar(100)
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Template {
id String @id @default(cuid())
templateId String @unique @db.VarChar(255)
name String @unique @db.VarChar(255)
template Json @db.JsonB
webhookUrl String? @db.VarChar(500)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
}
model Dify {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
description String? @db.VarChar(255)
botType DifyBotType
apiUrl String? @db.VarChar(255)
apiKey String? @db.VarChar(255)
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
DifySetting DifySetting[]
}
model DifySetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback Dify? @relation(fields: [difyIdFallback], references: [id])
difyIdFallback String? @db.VarChar(100)
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model EvolutionBot {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
description String? @db.VarChar(255)
apiUrl String? @db.VarChar(255)
apiKey String? @db.VarChar(255)
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
EvolutionBotSetting EvolutionBotSetting[]
}
model EvolutionBotSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback EvolutionBot? @relation(fields: [botIdFallback], references: [id])
botIdFallback String? @db.VarChar(100)
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Flowise {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
description String? @db.VarChar(255)
apiUrl String? @db.VarChar(255)
apiKey String? @db.VarChar(255)
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
FlowiseSetting FlowiseSetting[]
}
model FlowiseSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback Flowise? @relation(fields: [flowiseIdFallback], references: [id])
flowiseIdFallback String? @db.VarChar(100)
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model IsOnWhatsapp {
id String @id @default(cuid())
remoteJid String @unique @db.VarChar(100)
jidOptions String
lid String? @db.VarChar(100)
createdAt DateTime @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
}
model N8n {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
description String? @db.VarChar(255)
webhookUrl String? @db.VarChar(255)
basicAuthUser String? @db.VarChar(255)
basicAuthPass String? @db.VarChar(255)
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
N8nSetting N8nSetting[]
}
model N8nSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback N8n? @relation(fields: [n8nIdFallback], references: [id])
n8nIdFallback String? @db.VarChar(100)
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}
model Evoai {
id String @id @default(cuid())
enabled Boolean @default(true) @db.Boolean
description String? @db.VarChar(255)
agentUrl String? @db.VarChar(255)
apiKey String? @db.VarChar(255)
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
triggerType TriggerType?
triggerOperator TriggerOperator?
triggerValue String?
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
EvoaiSetting EvoaiSetting[]
}
model EvoaiSetting {
id String @id @default(cuid())
expire Int? @default(0) @db.Integer
keywordFinish String? @db.VarChar(100)
delayMessage Int? @db.Integer
unknownMessage String? @db.VarChar(100)
listeningFromMe Boolean? @default(false) @db.Boolean
stopBotFromMe Boolean? @default(false) @db.Boolean
keepOpen Boolean? @default(false) @db.Boolean
debounceTime Int? @db.Integer
ignoreJids Json?
splitMessages Boolean? @default(false) @db.Boolean
timePerChar Int? @default(50) @db.Integer
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Fallback Evoai? @relation(fields: [evoaiIdFallback], references: [id])
evoaiIdFallback String? @db.VarChar(100)
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique
}

View File

@@ -11,11 +11,28 @@ if (!DATABASE_PROVIDER) {
console.warn(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`);
}
// Função para determinar qual pasta de migrations usar
// Função para determinar qual pasta de migrations usar
function getMigrationsFolder(provider) {
switch (provider) {
case 'psql_bouncer':
return 'postgresql-migrations'; // psql_bouncer usa as migrations do postgresql
default:
return `${provider}-migrations`;
}
}
const migrationsFolder = getMigrationsFolder(databaseProviderDefault);
let command = process.argv
.slice(2)
.join(' ')
.replace(/DATABASE_PROVIDER/g, databaseProviderDefault);
// Substituir referências à pasta de migrations pela pasta correta
const migrationsPattern = new RegExp(`${databaseProviderDefault}-migrations`, 'g');
command = command.replace(migrationsPattern, migrationsFolder);
if (command.includes('rmdir') && existsSync('prisma\\migrations')) {
try {
execSync('rmdir /S /Q prisma\\migrations', { stdio: 'inherit' });
@@ -32,4 +49,4 @@ try {
} catch (error) {
console.error(`Error executing command: ${command}`);
process.exit(1);
}
}

View File

@@ -70,6 +70,10 @@ export class ChatController {
return await this.waMonitor.waInstances[instanceName].fetchChats(query);
}
public async findChatByRemoteJid({ instanceName }: InstanceDto, remoteJid: string) {
return await this.waMonitor.waInstances[instanceName].findChatByRemoteJid(remoteJid);
}
public async sendPresence({ instanceName }: InstanceDto, data: SendPresenceDto) {
return await this.waMonitor.waInstances[instanceName].sendPresence(data);
}

View File

@@ -53,15 +53,21 @@ export class ProxyController {
httpsAgent: makeProxyAgent(proxy),
});
return response?.data !== serverIp?.data;
} catch (error) {
if (axios.isAxiosError(error) && error.response?.data) {
logger.error('testProxy error: ' + error.response.data);
} else if (axios.isAxiosError(error)) {
logger.error('testProxy error: ');
const result = response?.data !== serverIp?.data;
if (result) {
logger.info('testProxy: proxy connection successful');
} else {
logger.error('testProxy error: ');
logger.warn("testProxy: proxy connection doesn't change the origin IP");
}
return result;
} catch (error) {
if (axios.isAxiosError(error)) {
logger.error('testProxy error: axios error: ' + error.message);
} else {
logger.error('testProxy error: unexpected error: ' + error);
}
return false;
}
}

View File

@@ -17,13 +17,15 @@ import {
import { WAMonitoringService } from '@api/services/monitor.service';
import { BadRequestException } from '@exceptions';
import { isBase64, isURL } from 'class-validator';
import emojiRegex from 'emoji-regex';
const regex = emojiRegex();
function isEmoji(str: string) {
if (str === '') return true;
const emojiRegex =
/^[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F000}-\u{1F02F}\u{1F0A0}-\u{1F0FF}\u{1F100}-\u{1F64F}\u{1F680}-\u{1F6FF}]$/u;
return emojiRegex.test(str);
const match = str.match(regex);
return match?.length === 1 && match[0] === str;
}
export class SendMessageController {

View File

@@ -455,39 +455,46 @@ export class EvolutionStartupService extends ChannelStartupService {
if (base64 || file || audioFile) {
if (this.configService.get<S3>('S3').ENABLE) {
try {
const fileBuffer = audioFile?.buffer || file?.buffer;
const buffer = base64 ? Buffer.from(base64, 'base64') : fileBuffer;
// Verificação adicional para garantir que há conteúdo de mídia real
const hasRealMedia = this.hasValidMediaContent(messageRaw);
let mediaType: string;
let mimetype = audioFile?.mimetype || file.mimetype;
if (!hasRealMedia) {
this.logger.warn('Message detected as media but contains no valid media content');
} else {
const fileBuffer = audioFile?.buffer || file?.buffer;
const buffer = base64 ? Buffer.from(base64, 'base64') : fileBuffer;
if (messageRaw.messageType === 'documentMessage') {
mediaType = 'document';
mimetype = !mimetype ? 'application/pdf' : mimetype;
} else if (messageRaw.messageType === 'imageMessage') {
mediaType = 'image';
mimetype = !mimetype ? 'image/png' : mimetype;
} else if (messageRaw.messageType === 'audioMessage') {
mediaType = 'audio';
mimetype = !mimetype ? 'audio/mp4' : mimetype;
} else if (messageRaw.messageType === 'videoMessage') {
mediaType = 'video';
mimetype = !mimetype ? 'video/mp4' : mimetype;
let mediaType: string;
let mimetype = audioFile?.mimetype || file.mimetype;
if (messageRaw.messageType === 'documentMessage') {
mediaType = 'document';
mimetype = !mimetype ? 'application/pdf' : mimetype;
} else if (messageRaw.messageType === 'imageMessage') {
mediaType = 'image';
mimetype = !mimetype ? 'image/png' : mimetype;
} else if (messageRaw.messageType === 'audioMessage') {
mediaType = 'audio';
mimetype = !mimetype ? 'audio/mp4' : mimetype;
} else if (messageRaw.messageType === 'videoMessage') {
mediaType = 'video';
mimetype = !mimetype ? 'video/mp4' : mimetype;
}
const fileName = `${messageRaw.key.id}.${mimetype.split('/')[1]}`;
const size = buffer.byteLength;
const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, mediaType, fileName);
await s3Service.uploadFile(fullName, buffer, size, {
'Content-Type': mimetype,
});
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
}
const fileName = `${messageRaw.key.id}.${mimetype.split('/')[1]}`;
const size = buffer.byteLength;
const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, mediaType, fileName);
await s3Service.uploadFile(fullName, buffer, size, {
'Content-Type': mimetype,
});
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
} catch (error) {
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
}

View File

@@ -429,107 +429,114 @@ export class BusinessStartupService extends ChannelStartupService {
try {
const message: any = received;
const id = message.messages[0][message.messages[0].type].id;
let urlServer = this.configService.get<WaBusiness>('WA_BUSINESS').URL;
const version = this.configService.get<WaBusiness>('WA_BUSINESS').VERSION;
urlServer = `${urlServer}/${version}/${id}`;
const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${this.token}` };
const result = await axios.get(urlServer, { headers });
// Verificação adicional para garantir que há conteúdo de mídia real
const hasRealMedia = this.hasValidMediaContent(messageRaw);
const buffer = await axios.get(result.data.url, {
headers: { Authorization: `Bearer ${this.token}` }, // Use apenas o token de autorização para download
responseType: 'arraybuffer',
});
let mediaType;
if (message.messages[0].document) {
mediaType = 'document';
} else if (message.messages[0].image) {
mediaType = 'image';
} else if (message.messages[0].audio) {
mediaType = 'audio';
if (!hasRealMedia) {
this.logger.warn('Message detected as media but contains no valid media content');
} else {
mediaType = 'video';
}
const id = message.messages[0][message.messages[0].type].id;
let urlServer = this.configService.get<WaBusiness>('WA_BUSINESS').URL;
const version = this.configService.get<WaBusiness>('WA_BUSINESS').VERSION;
urlServer = `${urlServer}/${version}/${id}`;
const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${this.token}` };
const result = await axios.get(urlServer, { headers });
const mimetype = result.data?.mime_type || result.headers['content-type'];
const buffer = await axios.get(result.data.url, {
headers: { Authorization: `Bearer ${this.token}` }, // Use apenas o token de autorização para download
responseType: 'arraybuffer',
});
const contentDisposition = result.headers['content-disposition'];
let fileName = `${message.messages[0].id}.${mimetype.split('/')[1]}`;
if (contentDisposition) {
const match = contentDisposition.match(/filename="(.+?)"/);
if (match) {
fileName = match[1];
let mediaType;
if (message.messages[0].document) {
mediaType = 'document';
} else if (message.messages[0].image) {
mediaType = 'image';
} else if (message.messages[0].audio) {
mediaType = 'audio';
} else {
mediaType = 'video';
}
}
// Para áudio, garantir extensão correta baseada no mimetype
if (mediaType === 'audio') {
if (mimetype.includes('ogg')) {
fileName = `${message.messages[0].id}.ogg`;
} else if (mimetype.includes('mp3')) {
fileName = `${message.messages[0].id}.mp3`;
} else if (mimetype.includes('m4a')) {
fileName = `${message.messages[0].id}.m4a`;
const mimetype = result.data?.mime_type || result.headers['content-type'];
const contentDisposition = result.headers['content-disposition'];
let fileName = `${message.messages[0].id}.${mimetype.split('/')[1]}`;
if (contentDisposition) {
const match = contentDisposition.match(/filename="(.+?)"/);
if (match) {
fileName = match[1];
}
}
}
const size = result.headers['content-length'] || buffer.data.byteLength;
// Para áudio, garantir extensão correta baseada no mimetype
if (mediaType === 'audio') {
if (mimetype.includes('ogg')) {
fileName = `${message.messages[0].id}.ogg`;
} else if (mimetype.includes('mp3')) {
fileName = `${message.messages[0].id}.mp3`;
} else if (mimetype.includes('m4a')) {
fileName = `${message.messages[0].id}.m4a`;
}
}
const fullName = join(`${this.instance.id}`, key.remoteJid, mediaType, fileName);
const size = result.headers['content-length'] || buffer.data.byteLength;
await s3Service.uploadFile(fullName, buffer.data, size, {
'Content-Type': mimetype,
});
const fullName = join(`${this.instance.id}`, key.remoteJid, mediaType, fileName);
const createdMessage = await this.prismaRepository.message.create({
data: messageRaw,
});
await s3Service.uploadFile(fullName, buffer.data, size, {
'Content-Type': mimetype,
});
await this.prismaRepository.media.create({
data: {
messageId: createdMessage.id,
instanceId: this.instanceId,
type: mediaType,
fileName: fullName,
mimetype,
},
});
const createdMessage = await this.prismaRepository.message.create({
data: messageRaw,
});
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
messageRaw.message.base64 = buffer.data.toString('base64');
// Processar OpenAI speech-to-text para áudio após o mediaUrl estar disponível
if (this.configService.get<Openai>('OPENAI').ENABLED && mediaType === 'audio') {
const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({
where: {
await this.prismaRepository.media.create({
data: {
messageId: createdMessage.id,
instanceId: this.instanceId,
},
include: {
OpenaiCreds: true,
type: mediaType,
fileName: fullName,
mimetype,
},
});
if (
openAiDefaultSettings &&
openAiDefaultSettings.openaiCredsId &&
openAiDefaultSettings.speechToText
) {
try {
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(
openAiDefaultSettings.OpenaiCreds,
{
message: {
mediaUrl: messageRaw.message.mediaUrl,
...messageRaw,
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
messageRaw.message.base64 = buffer.data.toString('base64');
// Processar OpenAI speech-to-text para áudio após o mediaUrl estar disponível
if (this.configService.get<Openai>('OPENAI').ENABLED && mediaType === 'audio') {
const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({
where: {
instanceId: this.instanceId,
},
include: {
OpenaiCreds: true,
},
});
if (
openAiDefaultSettings &&
openAiDefaultSettings.openaiCredsId &&
openAiDefaultSettings.speechToText
) {
try {
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(
openAiDefaultSettings.OpenaiCreds,
{
message: {
mediaUrl: messageRaw.message.mediaUrl,
...messageRaw,
},
},
},
)}`;
} catch (speechError) {
this.logger.error(`Error processing speech-to-text: ${speechError}`);
)}`;
} catch (speechError) {
this.logger.error(`Error processing speech-to-text: ${speechError}`);
}
}
}
}

View File

@@ -0,0 +1,59 @@
import { Logger } from '@config/logger.config';
import { BaileysEventMap, MessageUpsertType, proto } from 'baileys';
import { catchError, concatMap, delay, EMPTY, from, retryWhen, Subject, Subscription, take, tap } from 'rxjs';
type MessageUpsertPayload = BaileysEventMap['messages.upsert'];
type MountProps = {
onMessageReceive: (payload: MessageUpsertPayload, settings: any) => Promise<void>;
};
export class BaileysMessageProcessor {
private processorLogs = new Logger('BaileysMessageProcessor');
private subscription?: Subscription;
protected messageSubject = new Subject<{
messages: proto.IWebMessageInfo[];
type: MessageUpsertType;
requestId?: string;
settings: any;
}>();
mount({ onMessageReceive }: MountProps) {
this.subscription = this.messageSubject
.pipe(
tap(({ messages }) => {
this.processorLogs.log(`Processing batch of ${messages.length} messages`);
}),
concatMap(({ messages, type, requestId, settings }) =>
from(onMessageReceive({ messages, type, requestId }, settings)).pipe(
retryWhen((errors) =>
errors.pipe(
tap((error) => this.processorLogs.warn(`Retrying message batch due to error: ${error.message}`)),
delay(1000), // 1 segundo de delay
take(3), // Máximo 3 tentativas
),
),
),
),
catchError((error) => {
this.processorLogs.error(`Error processing message batch: ${error}`);
return EMPTY;
}),
)
.subscribe({
error: (error) => {
this.processorLogs.error(`Message stream error: ${error}`);
},
});
}
processMessage(payload: MessageUpsertPayload, settings: any) {
const { messages, type, requestId } = payload;
this.messageSubject.next({ messages, type, requestId, settings });
}
onDestroy() {
this.subscription?.unsubscribe();
this.messageSubject.complete();
}
}

View File

@@ -99,6 +99,7 @@ import makeWASocket, {
Contact,
delay,
DisconnectReason,
downloadContentFromMessage,
downloadMediaMessage,
generateWAMessageFromContent,
getAggregateVotesInPollMessage,
@@ -122,7 +123,7 @@ import makeWASocket, {
WABrowserDescription,
WAMediaUpload,
WAMessage,
WAMessageUpdate,
WAMessageKey,
WAPresence,
WASocket,
} from 'baileys';
@@ -147,6 +148,7 @@ import sharp from 'sharp';
import { PassThrough, Readable } from 'stream';
import { v4 } from 'uuid';
import { BaileysMessageProcessor } from './baileysMessage.processor';
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';
const groupMetadataCache = new CacheService(new CacheEngine(configService, 'groups').getEngine());
@@ -212,6 +214,8 @@ async function getVideoDuration(input: Buffer | string | Readable): Promise<numb
}
export class BaileysStartupService extends ChannelStartupService {
private messageProcessor = new BaileysMessageProcessor();
constructor(
public readonly configService: ConfigService,
public readonly eventEmitter: EventEmitter2,
@@ -223,6 +227,9 @@ export class BaileysStartupService extends ChannelStartupService {
) {
super(configService, eventEmitter, prismaRepository, chatwootCache);
this.instance.qrcode = { count: 0 };
this.messageProcessor.mount({
onMessageReceive: this.messageHandle['messages.upsert'].bind(this), // Bind the method to the current context
});
this.authStateProvider = new AuthStateProvider(this.providerFiles);
}
@@ -242,6 +249,7 @@ export class BaileysStartupService extends ChannelStartupService {
}
public async logoutInstance() {
this.messageProcessor.onDestroy();
await this.client?.logout('Log out instance: ' + this.instanceName);
this.client?.ws?.close();
@@ -541,17 +549,18 @@ export class BaileysStartupService extends ChannelStartupService {
this.logger.info(`Browser: ${browser}`);
}
let version;
let log;
const baileysVersion = await fetchLatestWaWebVersion({});
const version = baileysVersion.version;
const log = `Baileys version: ${version.join('.')}`;
if (session.VERSION) {
version = session.VERSION.split('.');
log = `Baileys version env: ${version}`;
} else {
const baileysVersion = await fetchLatestWaWebVersion({});
version = baileysVersion.version;
log = `Baileys version: ${version}`;
}
// if (session.VERSION) {
// version = session.VERSION.split('.');
// log = `Baileys version env: ${version}`;
// } else {
// const baileysVersion = await fetchLatestWaWebVersion({});
// version = baileysVersion.version;
// log = `Baileys version: ${version}`;
// }
this.logger.info(log);
@@ -887,7 +896,7 @@ export class BaileysStartupService extends ChannelStartupService {
}: {
chats: Chat[];
contacts: Contact[];
messages: proto.IWebMessageInfo[];
messages: WAMessage[];
isLatest?: boolean;
progress?: number;
syncType?: proto.HistorySync.HistorySyncType;
@@ -973,6 +982,10 @@ export class BaileysStartupService extends ChannelStartupService {
continue;
}
if (m.key.remoteJid?.includes('@lid') && m.key.senderPn) {
m.key.remoteJid = m.key.senderPn;
}
if (Long.isLong(m?.messageTimestamp)) {
m.messageTimestamp = m.messageTimestamp?.toNumber();
}
@@ -1030,11 +1043,31 @@ export class BaileysStartupService extends ChannelStartupService {
},
'messages.upsert': async (
{ messages, type, requestId }: { messages: proto.IWebMessageInfo[]; type: MessageUpsertType; requestId?: string },
{ messages, type, requestId }: { messages: WAMessage[]; type: MessageUpsertType; requestId?: string },
settings: any,
) => {
try {
for (const received of messages) {
if (received.key.remoteJid?.includes('@lid') && received.key.senderPn) {
(received.key as { previousRemoteJid?: string | null }).previousRemoteJid = received.key.remoteJid;
received.key.remoteJid = received.key.senderPn;
}
if (
received?.messageStubParameters?.some?.((param) =>
[
'No matching sessions found for message',
'Bad MAC',
'failed to decrypt message',
'SessionError',
'Invalid PreKey ID',
'No session record',
'No session found to decrypt message',
].some((err) => param?.includes?.(err)),
)
) {
this.logger.warn(`Message ignored with messageStubParameters: ${JSON.stringify(received, null, 2)}`);
continue;
}
if (received.message?.conversation || received.message?.extendedTextMessage?.text) {
const text = received.message?.conversation || received.message?.extendedTextMessage?.text;
@@ -1055,7 +1088,7 @@ export class BaileysStartupService extends ChannelStartupService {
const editedMessage =
received?.message?.protocolMessage || received?.message?.editedMessage?.message?.protocolMessage;
if (received.message?.protocolMessage?.editedMessage && editedMessage) {
if (editedMessage) {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled)
this.chatwootService.eventWhatsapp(
'messages.edit',
@@ -1103,7 +1136,7 @@ export class BaileysStartupService extends ChannelStartupService {
if (
(type !== 'notify' && type !== 'append') ||
received.message?.protocolMessage ||
editedMessage ||
received.message?.pollUpdateMessage ||
!received?.message
) {
@@ -1226,33 +1259,41 @@ export class BaileysStartupService extends ChannelStartupService {
if (this.configService.get<S3>('S3').ENABLE) {
try {
const message: any = received;
const media = await this.getBase64FromMediaMessage({ message }, true);
const { buffer, mediaType, fileName, size } = media;
const mimetype = mimeTypes.lookup(fileName).toString();
const fullName = join(
`${this.instance.id}`,
received.key.remoteJid,
mediaType,
`${Date.now()}_${fileName}`,
);
await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype });
// Verificação adicional para garantir que há conteúdo de mídia real
const hasRealMedia = this.hasValidMediaContent(message);
await this.prismaRepository.media.create({
data: {
messageId: msg.id,
instanceId: this.instanceId,
type: mediaType,
fileName: fullName,
mimetype,
},
});
if (!hasRealMedia) {
this.logger.warn('Message detected as media but contains no valid media content');
} else {
const media = await this.getBase64FromMediaMessage({ message }, true);
const mediaUrl = await s3Service.getObjectUrl(fullName);
const { buffer, mediaType, fileName, size } = media;
const mimetype = mimeTypes.lookup(fileName).toString();
const fullName = join(
`${this.instance.id}`,
received.key.remoteJid,
mediaType,
`${Date.now()}_${fileName}`,
);
await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype });
messageRaw.message.mediaUrl = mediaUrl;
await this.prismaRepository.media.create({
data: {
messageId: msg.id,
instanceId: this.instanceId,
type: mediaType,
fileName: fullName,
mimetype,
},
});
await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw });
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw });
}
} catch (error) {
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
}
@@ -1356,7 +1397,7 @@ export class BaileysStartupService extends ChannelStartupService {
}
},
'messages.update': async (args: WAMessageUpdate[], settings: any) => {
'messages.update': async (args: { update: Partial<WAMessage>; key: WAMessageKey }[], settings: any) => {
this.logger.log(`Update messages ${JSON.stringify(args, undefined, 2)}`);
const readChatToUpdate: Record<string, true> = {}; // {remoteJid: true}
@@ -1366,6 +1407,10 @@ export class BaileysStartupService extends ChannelStartupService {
continue;
}
if (key.remoteJid?.includes('@lid') && key.senderPn) {
key.remoteJid = key.senderPn;
}
const updateKey = `${this.instance.id}_${key.id}_${update.status}`;
const cached = await this.baileysCache.get(updateKey);
@@ -1401,16 +1446,7 @@ export class BaileysStartupService extends ChannelStartupService {
}
}
const findMessage = await this.prismaRepository.message.findFirst({
where: { instanceId: this.instanceId, key: { path: ['id'], equals: key.id } },
});
if (!findMessage) {
continue;
}
const message: any = {
messageId: findMessage.id,
keyId: key.id,
remoteJid: key?.remoteJid,
fromMe: key.fromMe,
@@ -1420,6 +1456,16 @@ export class BaileysStartupService extends ChannelStartupService {
instanceId: this.instanceId,
};
let findMessage: any;
const configDatabaseData = this.configService.get<Database>('DATABASE').SAVE_DATA;
if (configDatabaseData.HISTORIC || configDatabaseData.NEW_MESSAGE) {
findMessage = await this.prismaRepository.message.findFirst({
where: { instanceId: this.instanceId, key: { path: ['id'], equals: key.id } },
});
if (findMessage) message.messageId = findMessage.id;
}
if (update.message === null && update.status === undefined) {
this.sendDataWebhook(Events.MESSAGES_DELETE, key);
@@ -1435,7 +1481,9 @@ export class BaileysStartupService extends ChannelStartupService {
}
continue;
} else if (update.status !== undefined && status[update.status] !== findMessage.status) {
}
if (findMessage && update.status !== undefined && status[update.status] !== findMessage.status) {
if (!key.fromMe && key.remoteJid) {
readChatToUpdate[key.remoteJid] = true;
@@ -1618,7 +1666,9 @@ export class BaileysStartupService extends ChannelStartupService {
if (events['messages.upsert']) {
const payload = events['messages.upsert'];
this.messageHandle['messages.upsert'](payload, settings);
this.messageProcessor.processMessage(payload, settings);
// this.messageHandle['messages.upsert'](payload, settings);
}
if (events['messages.update']) {
@@ -2121,31 +2171,39 @@ export class BaileysStartupService extends ChannelStartupService {
if (isMedia && this.configService.get<S3>('S3').ENABLE) {
try {
const message: any = messageRaw;
const media = await this.getBase64FromMediaMessage({ message }, true);
const { buffer, mediaType, fileName, size } = media;
// Verificação adicional para garantir que há conteúdo de mídia real
const hasRealMedia = this.hasValidMediaContent(message);
const mimetype = mimeTypes.lookup(fileName).toString();
if (!hasRealMedia) {
this.logger.warn('Message detected as media but contains no valid media content');
} else {
const media = await this.getBase64FromMediaMessage({ message }, true);
const fullName = join(
`${this.instance.id}`,
messageRaw.key.remoteJid,
`${messageRaw.key.id}`,
mediaType,
fileName,
);
const { buffer, mediaType, fileName, size } = media;
await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype });
const mimetype = mimeTypes.lookup(fileName).toString();
await this.prismaRepository.media.create({
data: { messageId: msg.id, instanceId: this.instanceId, type: mediaType, fileName: fullName, mimetype },
});
const fullName = join(
`${this.instance.id}`,
messageRaw.key.remoteJid,
`${messageRaw.key.id}`,
mediaType,
fileName,
);
const mediaUrl = await s3Service.getObjectUrl(fullName);
await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype });
messageRaw.message.mediaUrl = mediaUrl;
await this.prismaRepository.media.create({
data: { messageId: msg.id, instanceId: this.instanceId, type: mediaType, fileName: fullName, mimetype },
});
await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw });
const mediaUrl = await s3Service.getObjectUrl(fullName);
messageRaw.message.mediaUrl = mediaUrl;
await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw });
}
} catch (error) {
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
}
@@ -2390,9 +2448,43 @@ export class BaileysStartupService extends ChannelStartupService {
try {
const type = mediaMessage.mediatype === 'ptv' ? 'video' : mediaMessage.mediatype;
let mediaInput: any;
if (mediaMessage.mediatype === 'image') {
let imageBuffer: Buffer;
if (isURL(mediaMessage.media)) {
let config: any = { responseType: 'arraybuffer' };
if (this.localProxy?.enabled) {
config = {
...config,
httpsAgent: makeProxyAgent({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
};
}
const response = await axios.get(mediaMessage.media, config);
imageBuffer = Buffer.from(response.data, 'binary');
} else {
imageBuffer = Buffer.from(mediaMessage.media, 'base64');
}
mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
mediaMessage.fileName ??= 'image.jpg';
mediaMessage.mimetype = 'image/jpeg';
} else {
mediaInput = isURL(mediaMessage.media)
? { url: mediaMessage.media }
: Buffer.from(mediaMessage.media, 'base64');
}
const prepareMedia = await prepareWAMessageMedia(
{
[type]: isURL(mediaMessage.media) ? { url: mediaMessage.media } : Buffer.from(mediaMessage.media, 'base64'),
[type]: mediaInput,
} as any,
{ upload: this.client.waUploadToServer },
);
@@ -2406,7 +2498,7 @@ export class BaileysStartupService extends ChannelStartupService {
}
if (mediaMessage.mediatype === 'image' && !mediaMessage.fileName) {
mediaMessage.fileName = 'image.png';
mediaMessage.fileName = 'image.jpg';
}
if (mediaMessage.mediatype === 'video' && !mediaMessage.fileName) {
@@ -2504,7 +2596,9 @@ export class BaileysStartupService extends ChannelStartupService {
imageBuffer = Buffer.from(base64Data, 'base64');
} else {
const timestamp = new Date().getTime();
const url = `${image}?timestamp=${timestamp}`;
const parsedURL = new URL(image);
parsedURL.searchParams.set('timestamp', timestamp.toString());
const url = parsedURL.toString();
let config: any = { responseType: 'arraybuffer' };
@@ -2725,7 +2819,9 @@ export class BaileysStartupService extends ChannelStartupService {
if (isURL(audio)) {
const timestamp = new Date().getTime();
const url = `${audio}?timestamp=${timestamp}`;
const parsedURL = new URL(audio);
parsedURL.searchParams.set('timestamp', timestamp.toString());
const url = parsedURL.toString();
const config: any = { responseType: 'stream' };
@@ -3379,17 +3475,20 @@ export class BaileysStartupService extends ChannelStartupService {
where: { id: message.id },
data: { key: { ...existingKey, deleted: true }, status: 'DELETED' },
});
const messageUpdate: any = {
messageId: message.id,
keyId: messageId,
remoteJid: response.key.remoteJid,
fromMe: response.key.fromMe,
participant: response.key?.remoteJid,
status: 'DELETED',
instanceId: this.instanceId,
};
await this.prismaRepository.messageUpdate.create({ data: messageUpdate });
if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE) {
const messageUpdate: any = {
messageId: message.id,
keyId: messageId,
remoteJid: response.key.remoteJid,
fromMe: response.key.fromMe,
participant: response.key?.remoteJid,
status: 'DELETED',
instanceId: this.instanceId,
};
await this.prismaRepository.messageUpdate.create({ data: messageUpdate });
}
} else {
if (!message) return response;
await this.prismaRepository.message.deleteMany({ where: { id: message.id } });
}
this.sendDataWebhook(Events.MESSAGES_DELETE, {
@@ -3413,6 +3512,18 @@ export class BaileysStartupService extends ChannelStartupService {
}
}
public async mapMediaType(mediaType) {
const map = {
imageMessage: 'image',
videoMessage: 'video',
documentMessage: 'document',
stickerMessage: 'sticker',
audioMessage: 'audio',
ptvMessage: 'video',
};
return map[mediaType] || null;
}
public async getBase64FromMediaMessage(data: getBase64FromMediaMessageDto, getBuffer = false) {
try {
const m = data?.message;
@@ -3437,28 +3548,76 @@ export class BaileysStartupService extends ChannelStartupService {
let mediaMessage: any;
let mediaType: string;
for (const type of TypeMediaMessage) {
mediaMessage = msg.message[type];
if (mediaMessage) {
mediaType = type;
break;
}
}
if (msg.message?.templateMessage) {
const template =
msg.message.templateMessage.hydratedTemplate || msg.message.templateMessage.hydratedFourRowTemplate;
if (!mediaMessage) {
throw 'The message is not of the media type';
for (const type of TypeMediaMessage) {
if (template[type]) {
mediaMessage = template[type];
mediaType = type;
msg.message = { [type]: { ...template[type], url: template[type].staticUrl } };
break;
}
}
if (!mediaMessage) {
throw 'Template message does not contain a supported media type';
}
} else {
for (const type of TypeMediaMessage) {
mediaMessage = msg.message[type];
if (mediaMessage) {
mediaType = type;
break;
}
}
if (!mediaMessage) {
throw 'The message is not of the media type';
}
}
if (typeof mediaMessage['mediaKey'] === 'object') {
msg.message = JSON.parse(JSON.stringify(msg.message));
}
const buffer = await downloadMediaMessage(
{ key: msg?.key, message: msg?.message },
'buffer',
{},
{ logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage },
);
let buffer: Buffer;
try {
buffer = await downloadMediaMessage(
{ key: msg?.key, message: msg?.message },
'buffer',
{},
{ logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage },
);
} catch (err) {
this.logger.error('Download Media failed, trying to retry in 5 seconds...');
await new Promise((resolve) => setTimeout(resolve, 5000));
const mediaType = Object.keys(msg.message).find((key) => key.endsWith('Message'));
if (!mediaType) throw new Error('Could not determine mediaType for fallback');
try {
const media = await downloadContentFromMessage(
{
mediaKey: msg.message?.[mediaType]?.mediaKey,
directPath: msg.message?.[mediaType]?.directPath,
url: `https://mmg.whatsapp.net${msg?.message?.[mediaType]?.directPath}`,
},
await this.mapMediaType(mediaType),
{},
);
const chunks = [];
for await (const chunk of media) {
chunks.push(chunk);
}
buffer = Buffer.concat(chunks);
this.logger.info('Download Media with downloadContentFromMessage was successful!');
} catch (fallbackErr) {
this.logger.error('Download Media with downloadContentFromMessage also failed!');
throw fallbackErr;
}
}
const typeMessage = getContentType(msg.message);
const ext = mimeTypes.extension(mediaMessage?.['mimetype']);
@@ -3591,7 +3750,9 @@ export class BaileysStartupService extends ChannelStartupService {
let pic: WAMediaUpload;
if (isURL(picture)) {
const timestamp = new Date().getTime();
const url = `${picture}?timestamp=${timestamp}`;
const parsedURL = new URL(picture);
parsedURL.searchParams.set('timestamp', timestamp.toString());
const url = parsedURL.toString();
let config: any = { responseType: 'arraybuffer' };
@@ -3659,6 +3820,10 @@ export class BaileysStartupService extends ChannelStartupService {
private async formatUpdateMessage(data: UpdateMessageDto) {
try {
if (!this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
return data;
}
const msg: any = await this.getMessage(data.key, true);
if (msg?.messageType === 'conversation' || msg?.messageType === 'extendedTextMessage') {
@@ -3692,13 +3857,15 @@ export class BaileysStartupService extends ChannelStartupService {
try {
const oldMessage: any = await this.getMessage(data.key, true);
if (!oldMessage) throw new NotFoundException('Message not found');
if (oldMessage?.key?.remoteJid !== jid) {
throw new BadRequestException('RemoteJid does not match');
}
if (oldMessage?.messageTimestamp > Date.now() + 900000) {
// 15 minutes in milliseconds
throw new BadRequestException('Message is older than 15 minutes');
if (this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
if (!oldMessage) throw new NotFoundException('Message not found');
if (oldMessage?.key?.remoteJid !== jid) {
throw new BadRequestException('RemoteJid does not match');
}
if (oldMessage?.messageTimestamp > Date.now() + 900000) {
// 15 minutes in milliseconds
throw new BadRequestException('Message is older than 15 minutes');
}
}
const messageSent = await this.client.sendMessage(jid, { ...(options as any), edit: data.key });
@@ -3716,7 +3883,7 @@ export class BaileysStartupService extends ChannelStartupService {
);
const messageId = messageSent.message?.protocolMessage?.key?.id;
if (messageId) {
if (messageId && this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
let message = await this.prismaRepository.message.findFirst({
where: { key: { path: ['id'], equals: messageId } },
});
@@ -3728,6 +3895,7 @@ export class BaileysStartupService extends ChannelStartupService {
if ((message.key.valueOf() as any)?.deleted) {
new BadRequestException('You cannot edit deleted messages');
}
if (oldMessage.messageType === 'conversation' || oldMessage.messageType === 'extendedTextMessage') {
oldMessage.message.conversation = data.text;
} else {
@@ -3741,16 +3909,19 @@ export class BaileysStartupService extends ChannelStartupService {
messageTimestamp: Math.floor(Date.now() / 1000), // Convert to int32 by dividing by 1000 to get seconds
},
});
const messageUpdate: any = {
messageId: message.id,
keyId: messageId,
remoteJid: messageSent.key.remoteJid,
fromMe: messageSent.key.fromMe,
participant: messageSent.key?.remoteJid,
status: 'EDITED',
instanceId: this.instanceId,
};
await this.prismaRepository.messageUpdate.create({ data: messageUpdate });
if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE) {
const messageUpdate: any = {
messageId: message.id,
keyId: messageId,
remoteJid: messageSent.key.remoteJid,
fromMe: messageSent.key.fromMe,
participant: messageSent.key?.remoteJid,
status: 'EDITED',
instanceId: this.instanceId,
};
await this.prismaRepository.messageUpdate.create({ data: messageUpdate });
}
}
}
}
@@ -3873,7 +4044,9 @@ export class BaileysStartupService extends ChannelStartupService {
let pic: WAMediaUpload;
if (isURL(picture.image)) {
const timestamp = new Date().getTime();
const url = `${picture.image}?timestamp=${timestamp}`;
const parsedURL = new URL(picture.image);
parsedURL.searchParams.set('timestamp', timestamp.toString());
const url = parsedURL.toString();
let config: any = { responseType: 'arraybuffer' };

View File

@@ -26,7 +26,7 @@ import axios from 'axios';
import { proto } from 'baileys';
import dayjs from 'dayjs';
import FormData from 'form-data';
import Jimp from 'jimp';
import { Jimp, JimpMime } from 'jimp';
import Long from 'long';
import mimeTypes from 'mime-types';
import path from 'path';
@@ -457,6 +457,24 @@ export class ChatwootService {
}
}
private async mergeContacts(baseId: number, mergeId: number) {
try {
const contact = await chatwootRequest(this.getClientCwConfig(), {
method: 'POST',
url: `/api/v1/accounts/${this.provider.accountId}/actions/contact_merge`,
body: {
base_contact_id: baseId,
mergee_contact_id: mergeId,
},
});
return contact;
} catch {
this.logger.error('Error merging contacts');
return null;
}
}
private async mergeBrazilianContacts(contacts: any[]) {
try {
const contact = await chatwootRequest(this.getClientCwConfig(), {
@@ -549,24 +567,41 @@ export class ChatwootService {
}
public async createConversation(instance: InstanceDto, body: any) {
const isLid = body.key.remoteJid.includes('@lid') && body.key.senderPn;
const remoteJid = isLid ? body.key.senderPn : body.key.remoteJid;
if (!body?.key) {
this.logger.warn(
`body.key is null or undefined in createConversation. Full body object: ${JSON.stringify(body)}`,
);
return null;
}
const isLid = body.key.previousRemoteJid?.includes('@lid') && body.key.senderPn;
const remoteJid = body.key.remoteJid;
const cacheKey = `${instance.instanceName}:createConversation-${remoteJid}`;
const lockKey = `${instance.instanceName}:lock:createConversation-${remoteJid}`;
const maxWaitTime = 5000; // 5 secounds
try {
// Processa atualização de contatos já criados @lid
if (body.key.remoteJid.includes('@lid') && body.key.senderPn && body.key.senderPn !== body.key.remoteJid) {
if (isLid && body.key.senderPn !== body.key.previousRemoteJid) {
const contact = await this.findContact(instance, body.key.remoteJid.split('@')[0]);
if (contact && contact.identifier !== body.key.senderPn) {
this.logger.verbose(
`Identifier needs update: (contact.identifier: ${contact.identifier}, body.key.remoteJid: ${body.key.remoteJid}, body.key.senderPn: ${body.key.senderPn})`,
`Identifier needs update: (contact.identifier: ${contact.identifier}, body.key.remoteJid: ${body.key.remoteJid}, body.key.senderPn: ${body.key.senderPn}`,
);
await this.updateContact(instance, contact.id, {
const updateContact = await this.updateContact(instance, contact.id, {
identifier: body.key.senderPn,
phone_number: `+${body.key.senderPn.split('@')[0]}`,
});
if (updateContact === null) {
const baseContact = await this.findContact(instance, body.key.senderPn.split('@')[0]);
if (baseContact) {
await this.mergeContacts(baseContact.id, contact.id);
this.logger.verbose(
`Merge contacts: (${baseContact.id}) ${baseContact.phone_number} and (${contact.id}) ${contact.phone_number}`,
);
}
}
}
}
this.logger.verbose(`--- Start createConversation ---`);
@@ -646,7 +681,7 @@ export class ChatwootService {
instance,
body.key.participant.split('@')[0],
filterInbox.id,
isGroup,
false,
body.pushName,
picture_url.profilePictureUrl || null,
body.key.participant,
@@ -685,7 +720,6 @@ export class ChatwootService {
}
}
} else {
const jid = isLid && body?.key?.senderPn ? body.key.senderPn : body.key.remoteJid;
contact = await this.createContact(
instance,
chatId,
@@ -693,7 +727,7 @@ export class ChatwootService {
isGroup,
nameContact,
picture_url.profilePictureUrl || null,
jid,
remoteJid,
);
}
@@ -1866,6 +1900,12 @@ export class ChatwootService {
public async eventWhatsapp(event: string, instance: InstanceDto, body: any) {
try {
// Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE)
if (body?.type && body.type !== 'message' && body.type !== 'conversation') {
this.logger.verbose(`Ignoring non-message event type: ${body.type}`);
return;
}
const waInstance = this.waMonitor.waInstances[instance.instanceName];
if (!waInstance) {
@@ -1911,6 +1951,11 @@ export class ChatwootService {
}
if (event === 'messages.upsert' || event === 'send.message') {
if (!body?.key) {
this.logger.warn(`body.key is null or undefined. Full body object: ${JSON.stringify(body)}`);
return;
}
if (body.key.remoteJid === 'status@broadcast') {
return;
}
@@ -2101,9 +2146,11 @@ export class ChatwootService {
const fileData = Buffer.from(imgBuffer.data, 'binary');
const img = await Jimp.read(fileData);
await img.cover(320, 180);
const processedBuffer = await img.getBufferAsync(Jimp.MIME_PNG);
await img.cover({
w: 320,
h: 180,
});
const processedBuffer = await img.getBuffer(JimpMime.png);
const fileStream = new Readable();
fileStream._read = () => {}; // _read is required but you can noop it
@@ -2231,10 +2278,23 @@ export class ChatwootService {
}
if (event === 'messages.edit' || event === 'send.message.update') {
// Ignore events that are not messages (like EPHEMERAL_SYNC_RESPONSE)
if (body?.type && body.type !== 'message') {
this.logger.verbose(`Ignoring non-message event type: ${body.type}`);
return;
}
if (!body?.key?.id) {
this.logger.warn(
`body.key.id is null or undefined in messages.edit. Full body object: ${JSON.stringify(body)}`,
);
return;
}
const editedText = `${
body?.editedMessage?.conversation || body?.editedMessage?.extendedTextMessage?.text
}\n\n_\`${i18next.t('cw.message.edited')}.\`_`;
const message = await this.getMessageByKeyId(instance, body?.key?.id);
const message = await this.getMessageByKeyId(instance, body.key.id);
const key = message.key as {
id: string;
fromMe: boolean;

View File

@@ -70,7 +70,7 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
}
const callId = `req-${uuidv4().substring(0, 8)}`;
const messageId = msg?.key?.id || uuidv4();
const messageId = remoteJid.split('@')[0] || uuidv4(); // Use phone number as messageId
// Prepare message parts
const parts = [

View File

@@ -49,6 +49,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
sessionId: session.sessionId,
remoteJid: remoteJid,
pushName: pushName,
keyId: msg?.key?.id,
fromMe: msg?.key?.fromMe,
instanceName: instance.instanceName,
serverUrl: this.configService.get<HttpServer>('SERVER').URL,

View File

@@ -119,7 +119,7 @@ export class TypebotController extends BaseChatbotController<TypebotModel, Typeb
const instanceData = await this.prismaRepository.instance.findFirst({
where: {
id: instance.instanceId,
name: instance.instanceName,
},
});
@@ -290,7 +290,7 @@ export class TypebotController extends BaseChatbotController<TypebotModel, Typeb
request.data.clientSideActions,
);
this.waMonitor.waInstances[instance.instanceId].sendDataWebhook(Events.TYPEBOT_START, {
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
remoteJid: remoteJid,
url: url,
typebot: typebot,

View File

@@ -186,7 +186,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
messages,
input,
clientSideActions,
this.applyFormatting,
this.applyFormatting.bind(this),
this.prismaRepository,
).catch((err) => {
console.error('Erro ao processar mensagens:', err);

View File

@@ -8,7 +8,12 @@ import { EmitData, EventController, EventControllerInterface } from '../event.co
export class RabbitmqController extends EventController implements EventControllerInterface {
public amqpChannel: amqp.Channel | null = null;
private amqpConnection: amqp.Connection | null = null;
private readonly logger = new Logger('RabbitmqController');
private reconnectAttempts = 0;
private maxReconnectAttempts = 10;
private reconnectDelay = 5000; // 5 seconds
private isReconnecting = false;
constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) {
super(prismaRepository, waMonitor, configService.get<Rabbitmq>('RABBITMQ')?.ENABLED, 'rabbitmq');
@@ -19,7 +24,11 @@ export class RabbitmqController extends EventController implements EventControll
return;
}
await new Promise<void>((resolve, reject) => {
await this.connect();
}
private async connect(): Promise<void> {
return new Promise<void>((resolve, reject) => {
const uri = configService.get<Rabbitmq>('RABBITMQ').URI;
const frameMax = configService.get<Rabbitmq>('RABBITMQ').FRAME_MAX;
const rabbitmqExchangeName = configService.get<Rabbitmq>('RABBITMQ').EXCHANGE_NAME;
@@ -33,22 +42,61 @@ export class RabbitmqController extends EventController implements EventControll
password: url.password || 'guest',
vhost: url.pathname.slice(1) || '/',
frameMax: frameMax,
heartbeat: 30, // Add heartbeat of 30 seconds
};
amqp.connect(connectionOptions, (error, connection) => {
amqp.connect(connectionOptions, (error: Error, connection: amqp.Connection) => {
if (error) {
this.logger.error({
local: 'RabbitmqController.connect',
message: 'Failed to connect to RabbitMQ',
error: error.message || error,
});
reject(error);
return;
}
connection.createChannel((channelError, channel) => {
if (channelError) {
reject(channelError);
// Connection event handlers
connection.on('error', (err: Error) => {
this.logger.error({
local: 'RabbitmqController.connectionError',
message: 'RabbitMQ connection error',
error: err.message || err,
});
this.handleConnectionLoss();
});
connection.on('close', () => {
this.logger.warn('RabbitMQ connection closed');
this.handleConnectionLoss();
});
connection.createChannel((channelError: Error, channel: amqp.Channel) => {
if (channelError) {
this.logger.error({
local: 'RabbitmqController.createChannel',
message: 'Failed to create RabbitMQ channel',
error: channelError.message || channelError,
});
reject(channelError);
return;
}
// Channel event handlers
channel.on('error', (err: Error) => {
this.logger.error({
local: 'RabbitmqController.channelError',
message: 'RabbitMQ channel error',
error: err.message || err,
});
this.handleConnectionLoss();
});
channel.on('close', () => {
this.logger.warn('RabbitMQ channel closed');
this.handleConnectionLoss();
});
const exchangeName = rabbitmqExchangeName;
channel.assertExchange(exchangeName, 'topic', {
@@ -56,16 +104,80 @@ export class RabbitmqController extends EventController implements EventControll
autoDelete: false,
});
this.amqpConnection = connection;
this.amqpChannel = channel;
this.reconnectAttempts = 0; // Reset reconnect attempts on successful connection
this.isReconnecting = false;
this.logger.info('AMQP initialized');
this.logger.info('AMQP initialized successfully');
resolve();
});
});
}).then(() => {
if (configService.get<Rabbitmq>('RABBITMQ')?.GLOBAL_ENABLED) this.initGlobalQueues();
});
})
.then(() => {
if (configService.get<Rabbitmq>('RABBITMQ')?.GLOBAL_ENABLED) {
this.initGlobalQueues();
}
})
.catch((error) => {
this.logger.error({
local: 'RabbitmqController.init',
message: 'Failed to initialize AMQP',
error: error.message || error,
});
this.scheduleReconnect();
throw error;
});
}
private handleConnectionLoss(): void {
if (this.isReconnecting) {
return; // Already attempting to reconnect
}
this.cleanup();
this.scheduleReconnect();
}
private scheduleReconnect(): void {
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
this.logger.error(
`Maximum reconnect attempts (${this.maxReconnectAttempts}) reached. Stopping reconnection attempts.`,
);
return;
}
if (this.isReconnecting) {
return; // Already scheduled
}
this.isReconnecting = true;
this.reconnectAttempts++;
const delay = this.reconnectDelay * Math.pow(2, Math.min(this.reconnectAttempts - 1, 5)); // Exponential backoff with max delay
this.logger.info(
`Scheduling RabbitMQ reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`,
);
setTimeout(async () => {
try {
this.logger.info(
`Attempting to reconnect to RabbitMQ (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`,
);
await this.connect();
this.logger.info('Successfully reconnected to RabbitMQ');
} catch (error) {
this.logger.error({
local: 'RabbitmqController.scheduleReconnect',
message: `Reconnection attempt ${this.reconnectAttempts} failed`,
error: error.message || error,
});
this.isReconnecting = false;
this.scheduleReconnect();
}
}, delay);
}
private set channel(channel: amqp.Channel) {
@@ -76,6 +188,17 @@ export class RabbitmqController extends EventController implements EventControll
return this.amqpChannel;
}
private async ensureConnection(): Promise<boolean> {
if (!this.amqpChannel) {
this.logger.warn('AMQP channel is not available, attempting to reconnect...');
if (!this.isReconnecting) {
this.scheduleReconnect();
}
return false;
}
return true;
}
public async emit({
instanceName,
origin,
@@ -95,6 +218,11 @@ export class RabbitmqController extends EventController implements EventControll
return;
}
if (!(await this.ensureConnection())) {
this.logger.warn(`Failed to emit event ${event} for instance ${instanceName}: No AMQP connection`);
return;
}
const instanceRabbitmq = await this.get(instanceName);
const rabbitmqLocal = instanceRabbitmq?.events;
const rabbitmqGlobal = configService.get<Rabbitmq>('RABBITMQ').GLOBAL_ENABLED;
@@ -154,7 +282,15 @@ export class RabbitmqController extends EventController implements EventControll
break;
} catch (error) {
this.logger.error({
local: 'RabbitmqController.emit',
message: `Error publishing local RabbitMQ message (attempt ${retry + 1}/3)`,
error: error.message || error,
});
retry++;
if (retry >= 3) {
this.handleConnectionLoss();
}
}
}
}
@@ -199,7 +335,15 @@ export class RabbitmqController extends EventController implements EventControll
break;
} catch (error) {
this.logger.error({
local: 'RabbitmqController.emit',
message: `Error publishing global RabbitMQ message (attempt ${retry + 1}/3)`,
error: error.message || error,
});
retry++;
if (retry >= 3) {
this.handleConnectionLoss();
}
}
}
}
@@ -208,41 +352,78 @@ export class RabbitmqController extends EventController implements EventControll
private async initGlobalQueues(): Promise<void> {
this.logger.info('Initializing global queues');
if (!(await this.ensureConnection())) {
this.logger.error('Cannot initialize global queues: No AMQP connection');
return;
}
const rabbitmqExchangeName = configService.get<Rabbitmq>('RABBITMQ').EXCHANGE_NAME;
const events = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
const prefixKey = configService.get<Rabbitmq>('RABBITMQ').PREFIX_KEY;
if (!events) {
this.logger.warn('No events to initialize on AMQP');
return;
}
const eventKeys = Object.keys(events);
eventKeys.forEach((event) => {
if (events[event] === false) return;
for (const event of eventKeys) {
if (events[event] === false) continue;
const queueName =
prefixKey !== ''
? `${prefixKey}.${event.replace(/_/g, '.').toLowerCase()}`
: `${event.replace(/_/g, '.').toLowerCase()}`;
const exchangeName = rabbitmqExchangeName;
try {
const queueName =
prefixKey !== ''
? `${prefixKey}.${event.replace(/_/g, '.').toLowerCase()}`
: `${event.replace(/_/g, '.').toLowerCase()}`;
const exchangeName = rabbitmqExchangeName;
this.amqpChannel.assertExchange(exchangeName, 'topic', {
durable: true,
autoDelete: false,
await this.amqpChannel.assertExchange(exchangeName, 'topic', {
durable: true,
autoDelete: false,
});
await this.amqpChannel.assertQueue(queueName, {
durable: true,
autoDelete: false,
arguments: {
'x-queue-type': 'quorum',
},
});
await this.amqpChannel.bindQueue(queueName, exchangeName, event);
this.logger.info(`Global queue initialized: ${queueName}`);
} catch (error) {
this.logger.error({
local: 'RabbitmqController.initGlobalQueues',
message: `Failed to initialize global queue for event ${event}`,
error: error.message || error,
});
this.handleConnectionLoss();
break;
}
}
}
public async cleanup(): Promise<void> {
try {
if (this.amqpChannel) {
await this.amqpChannel.close();
this.amqpChannel = null;
}
if (this.amqpConnection) {
await this.amqpConnection.close();
this.amqpConnection = null;
}
} catch (error) {
this.logger.warn({
local: 'RabbitmqController.cleanup',
message: 'Error during cleanup',
error: error.message || error,
});
this.amqpChannel.assertQueue(queueName, {
durable: true,
autoDelete: false,
arguments: {
'x-queue-type': 'quorum',
},
});
this.amqpChannel.bindQueue(queueName, exchangeName, event);
});
this.amqpChannel = null;
this.amqpConnection = null;
}
}
}

View File

@@ -30,8 +30,12 @@ export class WebsocketController extends EventController implements EventControl
const url = new URL(req.url || '', 'http://localhost');
const params = new URLSearchParams(url.search);
const { remoteAddress } = req.socket;
const isLocalhost =
remoteAddress === '127.0.0.1' || remoteAddress === '::1' || remoteAddress === '::ffff:127.0.0.1';
// Permite conexões internas do Socket.IO (EIO=4 é o Engine.IO v4)
if (params.has('EIO')) {
if (params.has('EIO') && isLocalhost) {
return callback(null, true);
}

View File

@@ -191,6 +191,16 @@ export class ChatRouter extends RouterBroker {
return res.status(HttpStatus.OK).json(response);
})
.get(this.routerPath('findChatByRemoteJid'), ...guards, async (req, res) => {
const instance = req.params as unknown as InstanceDto;
const { remoteJid } = req.query as unknown as { remoteJid: string };
if (!remoteJid) {
return res.status(HttpStatus.BAD_REQUEST).json({ error: 'remoteJid is a required query parameter' });
}
const response = await chatController.findChatByRemoteJid(instance, remoteJid);
return res.status(HttpStatus.OK).json(response);
})
// Profile routes
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
const response = await this.dataValidate<ProfilePictureDto>({

View File

@@ -69,8 +69,7 @@ router
clientName: process.env.DATABASE_CONNECTION_CLIENT_NAME,
manager: !serverConfig.DISABLE_MANAGER ? `${req.protocol}://${req.get('host')}/manager` : undefined,
documentation: `https://doc.evolution-api.com`,
whatsappWebVersion:
process.env.CONFIG_SESSION_PHONE_VERSION || (await fetchLatestWaWebVersion({})).version.join('.'),
whatsappWebVersion: (await fetchLatestWaWebVersion({})).version.join('.'),
});
})
.post('/verify-creds', authGuard['apikey'], async (req, res) => {

View File

@@ -696,6 +696,16 @@ export class ChannelStartupService {
});
}
public async findChatByRemoteJid(remoteJid: string) {
if (!remoteJid) return null;
return await this.prismaRepository.chat.findFirst({
where: {
instanceId: this.instanceId,
remoteJid: remoteJid,
},
});
}
public async fetchChats(query: any) {
const remoteJid = query?.where?.remoteJid
? query?.where?.remoteJid.includes('@')
@@ -738,22 +748,23 @@ export class ChannelStartupService {
"Chat"."name" as "pushName",
"Chat"."createdAt" as "windowStart",
"Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
"Chat"."unreadMessages" as "unreadMessages",
CASE WHEN "Chat"."createdAt" + INTERVAL '24 hours' > NOW() THEN true ELSE false END as "windowActive",
"Message"."id" AS lastMessageId,
"Message"."key" AS lastMessage_key,
"Message"."id" AS "lastMessageId",
"Message"."key" AS "lastMessage_key",
CASE
WHEN "Message"."key"->>'fromMe' = 'true' THEN 'Você'
ELSE "Message"."pushName"
END AS lastMessagePushName,
"Message"."participant" AS lastMessageParticipant,
"Message"."messageType" AS lastMessageMessageType,
"Message"."message" AS lastMessageMessage,
"Message"."contextInfo" AS lastMessageContextInfo,
"Message"."source" AS lastMessageSource,
"Message"."messageTimestamp" AS lastMessageMessageTimestamp,
"Message"."instanceId" AS lastMessageInstanceId,
"Message"."sessionId" AS lastMessageSessionId,
"Message"."status" AS lastMessageStatus
END AS "lastMessagePushName",
"Message"."participant" AS "lastMessageParticipant",
"Message"."messageType" AS "lastMessageMessageType",
"Message"."message" AS "lastMessageMessage",
"Message"."contextInfo" AS "lastMessageContextInfo",
"Message"."source" AS "lastMessageSource",
"Message"."messageTimestamp" AS "lastMessageMessageTimestamp",
"Message"."instanceId" AS "lastMessageInstanceId",
"Message"."sessionId" AS "lastMessageSessionId",
"Message"."status" AS "lastMessageStatus"
FROM "Message"
LEFT JOIN "Contact" ON "Contact"."remoteJid" = "Message"."key"->>'remoteJid' AND "Contact"."instanceId" = "Message"."instanceId"
LEFT JOIN "Chat" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid' AND "Chat"."instanceId" = "Message"."instanceId"
@@ -770,47 +781,65 @@ export class ChannelStartupService {
if (results && isArray(results) && results.length > 0) {
const mappedResults = results.map((contact) => {
const lastMessage = contact.lastmessageid
const lastMessage = contact.lastMessageId
? {
id: contact.lastmessageid,
key: contact.lastmessage_key,
pushName: contact.lastmessagepushname,
participant: contact.lastmessageparticipant,
messageType: contact.lastmessagemessagetype,
message: contact.lastmessagemessage,
contextInfo: contact.lastmessagecontextinfo,
source: contact.lastmessagesource,
messageTimestamp: contact.lastmessagemessagetimestamp,
instanceId: contact.lastmessageinstanceid,
sessionId: contact.lastmessagesessionid,
status: contact.lastmessagestatus,
id: contact.lastMessageId,
key: contact.lastMessage_key,
pushName: contact.lastMessagePushName,
participant: contact.lastMessageParticipant,
messageType: contact.lastMessageMessageType,
message: contact.lastMessageMessage,
contextInfo: contact.lastMessageContextInfo,
source: contact.lastMessageSource,
messageTimestamp: contact.lastMessageMessageTimestamp,
instanceId: contact.lastMessageInstanceId,
sessionId: contact.lastMessageSessionId,
status: contact.lastMessageStatus,
}
: undefined;
return {
id: contact.contactid || null,
remoteJid: contact.remotejid,
pushName: contact.pushname,
profilePicUrl: contact.profilepicurl,
updatedAt: contact.updatedat,
windowStart: contact.windowstart,
windowExpires: contact.windowexpires,
windowActive: contact.windowactive,
id: contact.contactId || null,
remoteJid: contact.remoteJid,
pushName: contact.pushName,
profilePicUrl: contact.profilePicUrl,
updatedAt: contact.updatedAt,
windowStart: contact.windowStart,
windowExpires: contact.windowExpires,
windowActive: contact.windowActive,
lastMessage: lastMessage ? this.cleanMessageData(lastMessage) : undefined,
unreadCount: 0,
isSaved: !!contact.contactid,
unreadCount: contact.unreadMessages,
isSaved: !!contact.contactId,
};
});
if (query?.take && query?.skip) {
const skip = query.skip || 0;
const take = query.take || 20;
return mappedResults.slice(skip, skip + take);
}
return mappedResults;
}
return [];
}
public hasValidMediaContent(message: any): boolean {
if (!message?.message) return false;
const msg = message.message;
// Se só tem messageContextInfo, não é mídia válida
if (Object.keys(msg).length === 1 && 'messageContextInfo' in msg) {
return false;
}
// Verifica se tem pelo menos um tipo de mídia válido
const mediaTypes = [
'imageMessage',
'videoMessage',
'stickerMessage',
'documentMessage',
'documentWithCaptionMessage',
'ptvMessage',
'audioMessage',
];
return mediaTypes.some((type) => msg[type] && Object.keys(msg[type]).length > 0);
}
}

View File

@@ -249,7 +249,7 @@ export type Webhook = {
};
};
export type Pusher = { ENABLED: boolean; GLOBAL?: GlobalPusher; EVENTS: EventsPusher };
export type ConfigSessionPhone = { CLIENT: string; NAME: string; VERSION: string };
export type ConfigSessionPhone = { CLIENT: string; NAME: string };
export type QrCode = { LIMIT: number; COLOR: string };
export type Typebot = { ENABLED: boolean; API_VERSION: string; SEND_MEDIA_BASE64: boolean };
export type Chatwoot = {
@@ -590,7 +590,6 @@ export class ConfigService {
CONFIG_SESSION_PHONE: {
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API',
NAME: process.env?.CONFIG_SESSION_PHONE_NAME || 'Chrome',
VERSION: process.env?.CONFIG_SESSION_PHONE_VERSION || null,
},
QRCODE: {
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,

19
src/railway.json Normal file
View File

@@ -0,0 +1,19 @@
{
"$schema": "https://railway.com/railway.schema.json",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "Dockerfile"
},
"deploy": {
"runtime": "V2",
"numReplicas": 1,
"sleepApplication": false,
"multiRegionConfig": {
"us-east4-eqdc4a": {
"numReplicas": 1
}
},
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}

View File

@@ -1,4 +1,5 @@
import { HttpsProxyAgent } from 'https-proxy-agent';
import { SocksProxyAgent } from 'socks-proxy-agent';
type Proxy = {
host: string;
@@ -8,9 +9,28 @@ type Proxy = {
username?: string;
};
export function makeProxyAgent(proxy: Proxy | string) {
function selectProxyAgent(proxyUrl: string): HttpsProxyAgent<string> | SocksProxyAgent {
const url = new URL(proxyUrl);
// NOTE: The following constants are not used in the function but are defined for clarity.
// When a proxy URL is used to build the URL object, the protocol returned by procotol's property contains a `:` at
// the end so, we add the protocol constants without the `:` to avoid confusion.
const PROXY_HTTP_PROTOCOL = 'http:';
const PROXY_SOCKS_PROTOCOL = 'socks:';
switch (url.protocol) {
case PROXY_HTTP_PROTOCOL:
return new HttpsProxyAgent(url);
case PROXY_SOCKS_PROTOCOL:
return new SocksProxyAgent(url);
default:
throw new Error(`Unsupported proxy protocol: ${url.protocol}`);
}
}
export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string> | SocksProxyAgent {
if (typeof proxy === 'string') {
return new HttpsProxyAgent(proxy);
return selectProxyAgent(proxy);
}
const { host, password, port, protocol, username } = proxy;
@@ -19,5 +39,6 @@ export function makeProxyAgent(proxy: Proxy | string) {
if (username && password) {
proxyUrl = `${protocol}://${username}:${password}@${host}:${port}`;
}
return new HttpsProxyAgent(proxyUrl);
return selectProxyAgent(proxyUrl);
}