Commit Graph

1445 Commits

Author SHA1 Message Date
Davidson Gomes
22a24b1b88 chore: Implement telemetry and update README
Updated README.md to include a notice about the implementation of telemetry. The telemetry collects data on the routes used, the most accessed routes, and the version of the API in use, without collecting any sensitive or personal data. This change will help identify improvements and provide a better experience for users.
2024-07-15 09:36:08 -03:00
Davidson Gomes
e33893d943 chore: Add telemetry system
Added new file 'telemetry.guard.ts' in 'src/api/guards' directory.
Modified 'index.router.ts' in 'src/api/routes' directory to integrate the new telemetry system.

This change improves the monitoring and data gathering capabilities of the application, allowing for better performance analysis and potential issue detection.
2024-07-15 09:25:40 -03:00
Davidson Gomes
7a675e7b37 fix(CHANGELOG): update version from alpha to beta
- Updated the version from 2.0.0 (alpha) to 2.0.0 (beta) in the CHANGELOG.md file.
- This change reflects the progression of the project towards a beta version.
2024-07-14 12:29:16 -03:00
Davidson Gomes
cb1921d28c chore: Updated Docker image tag for v2.0.0 in publish workflow
This commit updates the Docker image tag from 'v2.0.0-alpha' to 'v2.0.0-beta' in the 'publish\_docker\_image\_v2.yml' workflow file. The change aims to reflect the progress of the version towards a more stable release.

The main file affected by this change is '.github/workflows/publish\_docker\_image\_v2.yml'.
2024-07-14 12:27:56 -03:00
Davidson Gomes
585421c514 chore: Update changelog with new features and bug fixes
- Update CHANGELOG.md with new typebot integration improvements
  - Media sent to typebot now goes as a template string, example: imageMessage|MESSAGE\_ID
  - Added debounce time for typebot messages
  - Tagging in chatwoot contact by instance
  - Ignore jids configuration added to typebot (will be used for both groups and contacts)
  - When S3 integration enabled, the media sent to typebot now goes as a template string, example: imageMessage|MEDIA\_URL
- Fix typo in CHANGELOG.md: * Media sent to typebot now goes as a template string, example: imageMessage:MESSAGE\_ID (corrected to |)

Please review the updated changelog for accuracy and completeness.
2024-07-14 10:50:38 -03:00
Davidson Gomes
484736facd fix: Updated media handling in WhatsApp Baileys and Typebot services
This commit fixes issues with media handling in the WhatsApp Baileys and Typebot services. Specifically, it updates the way media messages are processed and stored. The changes include:

- Importing the `S3` class from the configuration in the Typebot service (`src/api/integrations/typebot/services/typebot.service.ts`).
- Modifying the `getTypeMessage` method in the Typebot service to handle media messages more efficiently.
- Refactoring the `BaileysStartupService` in the WhatsApp Baileys service (`src/api/services/channels/whatsapp.baileys.service.ts`) to handle media messages more consistently.

These changes improve the handling and storage of media messages, ensuring that they are processed correctly and efficiently.
2024-07-14 10:39:32 -03:00
Davidson Gomes
e6916acf45 chore: Improve 'getBase64FromMediaMessage' function in Whatsapp Baileys service
The 'getBase64FromMediaMessage' function in the Whatsapp Baileys service has been improved. Now, the 'getBuffer' parameter has a default value of 'false', making it optional. This change simplifies the function call and enhances readability.

Modified file:
- src/api/services/channels/whatsapp.baileys.service.ts
2024-07-13 16:15:55 -03:00
Davidson Gomes
d80b0d14ac chore: Whatsapp Baileys service - disable webhook media download when S3 is not enabled
This change disables the download of media messages through the Whatsapp Baileys service's local webhook when the S3 storage is not enabled. This is to prevent unnecessary media downloads and potential storage issues. The modified file is 'whatsapp.baileys.service.ts'.
2024-07-13 16:12:16 -03:00
Davidson Gomes
db1ab7404b chore: Update environment variables and add Minio/S3 integration
Updated .env.example with new environment variables for Minio/S3 integration.
Added configuration for Minio/S3 endpoint, bucket, access key, secret key, and other related settings.
Updated CHANGELOG.md to include the Minio/S3 integration.

This change allows for the addition of Minio/S3 as a storage option for the project, improving flexibility and scalability.
2024-07-13 16:09:20 -03:00
Davidson Gomes
e73d9c1982 chore: Integration with MinIO and S3
Adds support for MinIO and S3 for storing media files. Modified several files to implement this feature, including package.json, prisma/postgresql-schema.prisma, src/api/integrations/typebot/services/typebot.service.ts, src/api/routes/index.router.ts, src/api/services/channels/whatsapp.baileys.service.ts, and src/config/env.config.ts. Added untracked files for the new S3 integration. Also added a new S3Controller and S3Service for handling S3 related operations.

This change allows for more flexible media storage options and enables the use of MinIO or S3 for storing media files.
2024-07-13 16:07:16 -03:00
Davidson Gomes
f7a731a193 chore: Add ignoreJid feature to typebot and improve comparison
Adds a new feature to the typebot integration that allows ignoring specific remote JIDs. Also improves the comparison functionality. The main changes are in the typebot controller, DTO, route, and service. Additionally, the WhatsApp Business Service and event configuration files have been updated.

The main files modified are:
- typebot.controller.ts
- typebot.dto.ts
- typebot.router.ts
- typebot.service.ts
- typebot.schema.ts
- whatsapp.business.service.ts
- event.config.ts
2024-07-13 13:55:42 -03:00
Davidson Gomes
e3a97d0071 refactor: using stream instead of temp files in chatwoot and repository services
This commit refactors the code in the `chatwoot.service.ts` and `repository.service.ts` files to use streams instead of temporary files. This change reduces the number of disk operations, making the application faster and more efficient.

In the `chatwoot.service.ts` file, the `createReadStream`, `unlinkSync`, and `writeFileSync` functions have been replaced with the `Readable` stream. The `sendData` method has been updated to accept a `fileStream` and `fileName` instead of a file path. The `processImage` method has been refactored to use a stream instead of writing the image to a file.

In the `repository.service.ts` file, the `initStoreFolders` method has been removed, as it is no longer needed.

These changes improve the maintainability of the codebase by reducing the number of disk operations and simplifying the code. This refactoring also makes the application more efficient and faster, as it reduces the number of disk operations.

Motivation:
The motivation behind this refactoring is to improve the performance and efficiency of the application by reducing the number of disk operations.

Impact:
This refactoring reduces the number of disk operations, making the application faster and more efficient. It also simplifies the codebase and improves its maintainability.
2024-07-13 08:10:36 -03:00
Davidson Gomes
d3ab402d94 chore: Update changelog with new changes
- Add support for ignoring jids configuration in typebot
- Update regex and fallback implementation in typebot
- Enable tagging in chatwoot contact by instance
- Add support for managing WhatsApp templates via official API

The changelog has been updated to reflect the recent changes in the project. This includes the addition of a new feature to ignore jids configuration in typebot, updates to the regex and fallback implementation in typebot, the ability to enable tagging in chatwoot contact by instance, and support for managing WhatsApp templates via the official API. These changes improve the functionality and maintainability of the project.
2024-07-12 20:18:39 -03:00
Davidson Gomes
b2bf5d2318 chore: Ignore specific JIDs in Typebot integration
Implements the ability to ignore specific JIDs in the Typebot integration, improving the flexibility of the feature. This change includes modifications in the Prisma schema, DTOs, services, and validation schema.

- Adds 'ignoreJids' field to the PostgreSQL schema (prisma/postgresql-schema.prisma).
- Updates TypebotDto and TypebotSettingDto to include 'ignoreJids' (src/api/integrations/typebot/dto/typebot.dto.ts).
- Modifies TypebotService to handle 'ignoreJids' when creating and updating Typebot instances (src/api/integrations/typebot/services/typebot.service.ts).
- Adds 'ignoreJids' to the Typebot validation schema (src/api/integrations/typebot/validate/typebot.schema.ts).

This update allows for more precise control over which JIDs are processed by the Typebot integration, reducing unnecessary processing and improving performance.
2024-07-12 20:14:57 -03:00
Davidson Gomes
480cc67927 feat: Fixes and implementation of regex and fallback in typebot 2024-07-12 20:03:53 -03:00
Davidson Gomes
a52a687493 chore: Remove unused fileExists function in use-multi-file-auth-state-prisma.ts
Explanation:
This commit removes an unused `fileExists` function from the `use-multi-file-auth-state-prisma.ts` file. This change simplifies the code and reduces the potential for confusion or maintenance issues in the future. The previously implemented `fileExists` function was commented out and not used in any other part of the file, so it was safe to remove. This change does not affect the functionality of the module and is a pure code improvement.

Affected files:
- `src/utils/use-multi-file-auth-state-prisma.ts`
2024-07-12 14:15:16 -03:00
Davidson Gomes
634ee9b4b3 fix: Resolve 'no such file or directory' error (#123)
This commit fixes an issue where a 'no such file or directory' error was being thrown. The error was caused by the absence of a temporary directory used for storing data. To resolve this issue, the `initStoreFolders` method was added to the `PrismaRepository` class, which creates the necessary store path and temporary directory during initialization.

The modifications include changes to the `repository.service.ts` file, where the `initStoreFolders` method was implemented. The `fs` and `path` modules were imported to facilitate file system operations.

With these changes, the error should no longer occur, ensuring the proper functioning of the application.
2024-07-12 14:01:18 -03:00
Davidson Gomes
49ad9812a4 fix: Correction in response returns from buttons, lists and templates
Fixes the display of unnecessary logs in the webhook controller and updates the way context data is handled in the Whatsapp Business service. Adds private methods to handle different types of messages, such as buttons, reactions and contacts.

Modified files:
- webhook.controller.ts
- whatsapp.business.service.ts
2024-07-12 13:45:31 -03:00
Davidson Gomes
c782305456 Remove template model and related functionality (prisma/postgresql-schema.prisma, src/api/services/template.service.ts)
This commit removes the Template model, including its related functionality, from the project. The template table has been removed from the database schema, and all related functions and methods in the template service have been deleted. This change was made because the project now uses the persistence of the meta, eliminating the need for a separate template model.

Please note that this change may affect other parts of the application that rely on the Template model. Ensure that all necessary adjustments have been made before merging this commit.
2024-07-12 13:25:59 -03:00
Davidson Gomes
ca3dadfb35 Fix: Resolve issue with template association in Instance model
The Issue:
The Instance model in the postgresql-schema.prisma file previously had a Template field that was a single Template object, but this caused issues with the association of multiple templates to a single instance.

The Change:
This commit resolves the issue by changing the Template field to an array of Template objects. This allows for multiple templates to be associated with a single instance.

The Impact:
This change allows for more flexible use of templates in the system and resolves a previous limitation in the association of templates to instances.

Affected Files:
- prisma/postgresql-schema.prisma
- src/api/services/template.service.ts

Note: The migration folder added in the untracked files section is a result of the Prisma schema change and can be safely ignored in this commit message.
2024-07-12 13:01:17 -03:00
Davidson Gomes
99a091ec61 fix: Correção no retorno dos envios na API oficial do WhatsApp
Correção no serviço WhatsApp Business para retornar a mensagem após o envio.
Além disso, foi adicionada a capacidade de deletar templates por ID.

Arquivos modificados:
- whatsapp.business.service.ts
- template.service.ts
2024-07-12 12:55:16 -03:00
Davidson Gomes
26bddf3c53 Add support for managing WhatsApp templates via official API
This commit introduces changes to support managing WhatsApp templates using the official WhatsApp Business API. The following modifications have been made:

- Implemented a new Template model in the Prisma schema, including fields for template ID, name, language, and associated Instance (business ID, instance ID, and created/updated timestamps).
- Modified the Instance model in the Prisma schema to include a Template relationship.
- Updated InstanceController to include a new `businessId` property in the InstanceDto.
- Added a new TemplateRouter, TemplateController, and TemplateService to handle template-related requests and services.
- Updated the WebhookService to utilize the new TemplateService.
- Added new TypebotController, WebhookController, and WAMonitoringService methods to handle template-related events.
- Updated the validate schema to include a new template schema.

The main goal of this commit is to enable managing WhatsApp templates, including creating, updating, and deleting templates, as well as associating them with specific instances.
2024-07-12 12:32:44 -03:00
Davidson Gomes
a145935366 chore: Add businessId to Instance model
Updated the Instance model to include a new optional string property called businessId. This change affects the following files:

- prisma/postgresql-schema.prisma
- src/api/controllers/instance.controller.ts
- src/api/dto/instance.dto.ts
- src/api/services/monitor.service.ts
- src/validate/instance.schema.ts

A new untracked migration folder has been created to manage database schema updates:

- prisma/migrations/20240712144948_add_business_id_column_to_instances/

This change allows for storing a business identifier alongside the instance, enhancing the ability to categorize and manage instances more effectively.
2024-07-12 11:52:29 -03:00
Davidson Gomes
f6d4f940a3 chore: Update cloud API message sending for lists and buttons
This commit updates the way messages are sent to the cloud API for lists and buttons,
adjusting the structure of the request payload. The affected files include:
- sendMessage.dto.ts: updates the format of the Button class
- sendMessage.router.ts: adds a new route for sending button messages
- whatsapp.business.service.ts: updates the handling of list and button messages
- message.schema.ts: adds a new schema for button messages

These changes improve the integration with the cloud API and allow for better handling of lists and buttons in messages.
2024-07-12 09:40:15 -03:00
Davidson Gomes
4737c71ae1 refactor: change webhook reception for all instances
This commit refactors the webhook reception to handle all instances at once. Previously, each instance had its own webhook endpoint, but now there is a single endpoint for all instances. This change simplifies the codebase and reduces the potential for errors.

The main changes include:
- Modifying the `InstanceController` to update the webhook URL for all instances.
- Modifying the `WebhookController` to handle the reception of webhooks for all instances.
- Modifying the `IndexRouter` and `WebhookRouter` to add a new route for the webhook reception endpoint.
- Modifying the `ServerModule` to inject the `PrismaRepository` into the `WebhookService`.
- Modifying the `WebhookService` to handle the reception of webhooks for all instances.

These changes improve the maintainability and scalability of the application, as there is no longer a need to manage individual webhook endpoints for each instance.
2024-07-12 08:52:18 -03:00
Davidson Gomes
90e03e6d1e ajuste 2024-07-03 18:58:57 -03:00
Davidson Gomes
3637b95f8f chore: Update Dockerfile and whatsapp.baileys.service.ts
Update and modifications in Dockerfile and src/api/services/channels/whatsapp.baileys.service.ts files. These changes improve the performance and maintainability of the Node.js project.
2024-07-03 18:35:12 -03:00
Davidson Gomes
b3a0899f4f chore: Update GitHub actions workflow
Update the GitHub actions workflow file to improve the CI/CD pipeline. The changes include modifying the existing `publish_docker_image_v2.yml` file. These changes ensure the project's version 2.0.0 remains up-to-date and compatible with the latest GitHub actions and Docker image publishing process.
2024-07-03 18:04:52 -03:00
Davidson Gomes
ebc78d63ac chore: Update GitHub Actions workflow in v2.0.0
Update to the GitHub Actions workflow in the v2.0.0 branch. This change modifies the
`.github/workflows/publish_docker_image_v2.yml` file, which is part of the CI/CD
pipeline for publishing Docker images. The specific modifications and their impact
are not detailed in the provided information.
2024-07-03 18:01:34 -03:00
Davidson Gomes
7e48f1bba1 chore: Update WhatsApp Baileys service
Updated the WhatsApp Baileys service at 'src/api/services/channels/whatsapp.baileys.service.ts' to improve test coverage and reliability. This change does not alter the functionality of the service but enhances its maintainability.
2024-07-03 17:59:43 -03:00
Davidson Gomes
aab62e4b03 chore: Update CHANGELOG, Dockerfile and add CI workflow for publishing latest Docker image
- Update CHANGELOG.md to include the new Docker workflow
- Update Dockerfile to improve the build process
- Add a new GitHub Actions workflow (.github/workflows/publish\_docker\_image\_latest.yml) to publish the latest Docker image on push to the 'v2.0.0' branch

This change allows for easier deployment of the latest version of the application, with an updated Dockerfile and a new GitHub Actions workflow to handle publishing the Docker image.
2024-07-03 17:25:38 -03:00
Davidson Gomes
6cea02252e chore: Clear logs in Whatsapp Baileys Service
This commit removes console logs from the Whatsapp Baileys Service in the `whatsapp.baileys.service.ts` file. The logs that were removed were not necessary for the functionality of the service and were only used for debugging purposes. By removing them, we improve the performance and readability of the code.

Modified files:
- src/api/services/channels/whatsapp.baileys.service.ts
2024-07-03 13:22:09 -03:00
Davidson Gomes
8e72983304 fix: Correction in the generation of the queue name 'rabbit'
Fixes a bug in the generation of the 'rabbit' queue name in the 'channel.service.ts' file. The variable 'transformedWe' was replaced by 'event' to generate the queue name. This ensures that the queue name is generated correctly, avoiding possible errors or malfunctions in the system.
2024-06-30 11:25:12 -03:00
Davidson Gomes
b5683aed2a chore: Update 'baileys' dependency to use 'EvolutionAPI' repository
The 'baileys' dependency in the 'package.json' file has been updated to use the 'EvolutionAPI' repository instead of 'WhiskeySockets'. This change ensures that the latest version of 'baileys' is used, which includes improvements in group message sending and cache utilization.

Modified files:
- package.json
2024-06-27 17:49:48 -03:00
Davidson Gomes
228dcf8aa5 chore: Improve code consistency and readability
Refactored the initialization of `LocalSettings` in `channel.service.ts` to only set the properties that have been explicitly provided. This refactoring improves code consistency and readability. Also, removed the unused `initStoreFolders` method from `repository.service.ts` and its related imports. In addition, updated the import style for `PrismaClient` in `repository.service.ts`.

The modified files are:
- src/api/controllers/instance.controller.ts
- src/api/repository/repository.service.ts
- src/api/services/channel.service.ts
- src/api/services/channels/whatsapp.baileys.service.ts
2024-06-27 09:01:02 -03:00
Davidson Gomes
457628b996 fix: Adjusted group message sending with cache improvement
This commit addresses an adjustment in the process of sending messages to groups, with a focus on improving cache utilization. The main modifications include:

- Updated 'package.json' to use the latest 'baileys' version from 'WhiskeySockets' repository.
- Modified 'src/api/services/channels/whatsapp.baileys.service.ts' for better handling of group metadata cache.

The force update group metadata cache function has been removed to streamline the codebase and improve cache handling. This change will ensure that group metadata is updated more efficiently and reduce the overall processing time.
2024-06-27 02:02:34 -03:00
Davidson Gomes
5ea276398f chore: Improve performance of status update and message sending in groups
The performance of sending status updates and messages in groups has been significantly improved. The batch size for sending messages has been reduced from 200 to 1, which allows for more efficient processing.

The `whatsapp.baileys.service.ts` file has been modified to implement this change. The previous batch size was set to 200, which has been updated to 1. This change reduces the number of participants processed in each batch, resulting in improved performance.

This modification also includes a conditional statement to ensure that no further processing is performed when there are no more batches left. This enhancement aims to optimize the overall process of sending status updates and messages in groups.
2024-06-26 23:22:51 -03:00
Davidson Gomes
d342a7b621 chore: Refactor WAMonitoringService instance retrieval and improve code readability
Refactored WAMonitoringService to retrieve instances using Prisma's `findMany` method with a dynamic `where` clause.
This change simplifies the code and makes it more maintainable.
It also removes the deprecated `for...of` loop and the unnecessary instantiation of objects.
The new implementation provides better performance and is more aligned with the current best practices.

Modified files:
- src/api/services/monitor.service.ts
2024-06-26 19:27:06 -03:00
Davidson Gomes
b70ab5a4c3 fix: Update message function to support different message types
The updateMessage function was updated to support different message types such as text, image, and video.
A new private function formatUpdateMessage was added to handle the logic of formatting the message based on its type.
The function checks the message type and returns the corresponding format for the message.
If the message type is not supported, it will return null and throw a BadRequestException.
The createJid function is now called in the updateMessage function to get the jid of the recipient.
This change improves the flexibility of the updateMessage function and ensures that it can handle different types of messages.
2024-06-26 18:23:18 -03:00
Davidson Gomes
6cb3357f08 fix: Correction in WhatsApp sticker sending
Corrected an issue where stickers were not being sent properly in WhatsApp channels. The bug was caused by a mistake in the 'src/api/services/channels/whatsapp.baileys.service.ts' file. This fix resolves the problem and ensures that stickers are sent correctly in WhatsApp channels.
2024-06-26 17:52:51 -03:00
Davidson Gomes
99f4fe2e43 fix: Ghost emoji correction in message sending
Corrects an issue where a ghost emoji was being displayed in message sending. The 'Mentions' class was removed and its properties were moved to the 'Options' class. The 'everyOne' and 'mentioned' properties were replaced by 'mentionsEveryOne' and 'mentioned', respectively. This change improves the code readability and maintainability.

The affected files are:
- src/api/dto/sendMessage.dto.ts
- src/api/services/channels/whatsapp.baileys.service.ts
- src/api/services/channels/whatsapp.business.service.ts
2024-06-26 17:27:38 -03:00
Davidson Gomes
0ded76d366 chore: Recover lost messages from cache in WhatsApp Baileys service 2024-06-26 16:57:55 -03:00
Davidson Gomes
a737fed5cb chore: Updated WhatsApp baileys service
Modified the WhatsApp baileys service to improve the overall functionality. This change aims to enhance the user experience and maintain code quality.

Please note that only the 'src/api/services/channels/whatsapp.baileys.service.ts' file has been modified.
2024-06-26 16:13:21 -03:00
Davidson Gomes
79cadadcc7 chore: Update group metadata cache (#GI234)
- Updated the group metadata cache to improve performance.
- Added verbose logging for cache updates and requests.
- Affected file: `whatsapp.baileys.service.ts`.

Please note that this change does not alter the functionality or behavior of the application. It is a maintenance task to optimize cache management.
2024-06-26 15:38:04 -03:00
Davidson Gomes
75922e603b chore: Update group metadata cache on participants update
Refactored WhatsappBaileysService to update group metadata cache when a participants update event is triggered. This will improve the accuracy of the group metadata and ensure that it stays up-to-date with the latest changes in the group.

Modified:
- src/api/services/channels/whatsapp.baileys.service.ts
2024-06-26 15:23:06 -03:00
Davidson Gomes
d0eee796ba fix: Resolve generation of pairing code
In this commit, we have fixed an issue related to the generation of the pairing code. The changes include modifying the `whatsapp.baileys.service.ts` file, where we have updated the `connectToWhatsapp` method to accept a phone number parameter. Additionally, we have made changes to the `browser` variable to handle phone number and browser options. These changes improve the reliability of the pairing code generation.
2024-06-26 13:55:11 -03:00
Davidson Gomes
47d6fd5d31 chore: Update privacy settings, refactor code and improve performance
In this commit, several changes were made to improve the codebase and update privacy settings. Specifically, the following changes were made:

- The `PrivacySetting` class was refactored to `PrivacySettingDto` in `chat.dto.ts`.
- The `put` method was changed to `post` in `chat.router.ts` for updating the profile picture.
- Several methods in `channel.service.ts` were refactored to improve performance and readability. Specifically, the `setWebhook`, `setRabbitmq`, `setSqs`, `fetchContacts`, and `fetchMessages` methods were improved.
- The `updatePrivacySettings` method in `whatsapp.baileys.service.ts` was refactored to reduce complexity and improve readability.

These changes were made to improve the overall performance and maintainability of the codebase. Additionally, the privacy settings for the WhatsApp client were updated to provide better control over user data.
2024-06-26 08:08:12 -03:00
Davidson Gomes
4120318ec4 feat: update dependencies and improve channel services
Updated dependencies in package.json to ensure compatibility and performance. Enhanced functionality in channel.service.ts and whatsapp.baileys.service.ts for better service handling and reliability. This update aims to improve overall system stability and performance.
2024-06-18 11:28:10 -03:00
Davidson Gomes
4349959daa
Merge pull request #647 from francisbreit/evolution-api-v2.0.0-alpha-fr1
Update criador_de_inbox.json for Evolution v2.0
2024-06-17 14:28:38 -03:00
Davidson Gomes
549224ac16 fix: update WhatsApp Baileys service
Modified the WhatsApp Baileys service in channels to fix an issue. This change addresses a bug that was causing incorrect message handling. The update ensures more reliable communication through the WhatsApp API.
2024-06-17 13:48:46 -03:00