Skip to content

Conversation

@oriondesign2015
Copy link
Contributor

@oriondesign2015 oriondesign2015 commented May 22, 2025

Esta PR corrige problemas de sintaxe no arquivo chatwoot-import-helper.ts, especificamente:

  • Ajusta a estrutura do bloco if/else no método getExistingSourceIds, evitando erro de compilação do TypeScript.
  • Garante que o bloco catch esteja corretamente posicionado dentro do método, retornando null em caso de erro.
  • Mantém a lógica original do método, apenas corrigindo a sintaxe para permitir a compilação e execução correta do projeto.
    Essas correções eliminam o erro de build relacionado ao TypeScript e melhoram a robustez do código ao tratar exceções de forma adequada.

Summary by Sourcery

Refactor and extend core chatbot and event infrastructure, add new integrations, enhance media processing and message handling, and resolve critical build and runtime bugs

New Features:

  • Introduce NATS support in the event system alongside RabbitMQ, SQS, WebSocket and Pusher
  • Add EvoAI and N8n chatbot integrations and expose catalog/collection endpoints
  • Extend Webhook controller with configurable timeouts, exponential‐backoff retries, and JWT authentication
  • Support message location, sticker and enhanced media types in BusinessStartupService

Bug Fixes:

  • Fix chatwoot-import-helper logic to correctly query existing source IDs by conversation
  • Prevent duplicate audio messages and improper conversation reopen in Chatwoot
  • Retain animation in GIF/WebP stickers and enforce libopus 48 kHz mono audio conversion
  • Eliminate deadlock and duplicate delivery in Baileys message processing and caching
  • Correct SEND_MESSAGE_UPDATE event handling across RabbitMQ, Pusher and Webhook schemas

Enhancements:

  • Refactor OpenAI, Typebot, Flowise, EvolutionBot and Dify to share BaseChatbotService and BaseChatbotController logic
  • Unify message sending, session lifecycle and speech-to-text flows across chatbot services
  • Add S3_SKIP_POLICY environment variable to opt out of automatic bucket policy
  • Improve Websocket authentication to validate API keys and support Engine.IO clients

Documentation:

  • Update CHANGELOG to document new features, fixes and security improvements

joaosouz4dev and others added 30 commits December 27, 2024 10:40
- Update Docker image repository to evoapicloud/evolution-api
- Modify contact email to contato@evolution-api.com
- Update Docker Compose, Dockerfile, and workflow files
- Add Docker image badge to README
- Include additional content creator in README
- Implement message deduplication cache in Baileys service
…leys service

- Refactor edited message detection logic
- Prevent duplicate message processing for edited messages
- Optimize message key caching mechanism
…{baseUrl}}/chat/fetchCatalogs' and '{{baseUrl}}/chat/fetchCollections'
Refactor edit and delete message functionality in BaileyStartupService
Feat: Adicionei suporte para obter o Catálogos de Produtos e as Coleções de Produtos para a versão 2.2.3
- Added NATS package to dependencies
- Created Prisma schema models for NATS configuration
- Implemented NATS controller, router, and event management
- Updated instance controller and event manager to support NATS
- Added NATS configuration options in environment configuration
- Included NATS events in instance validation schema
…gos de produtos e Coleções evitando alterações desnecessárias em arquivos do repositório
Adicionado suporte para obter Catálogos e Coleções no WhatsApp Business
feat: notconvertsticket for animated stickers
Fix instance creation on v2.2.3
feat: add message location support whatsapp meta
Fix audio send duplicate from chatwoot.
fix: chatwoot csat creating new conversation in another language
Corrige problema na API relacionado à migration. Fixes #1234
DavidsonGomes and others added 28 commits May 21, 2025 13:54
- Enhanced the logic for converting media messages to base64 by adding a retry mechanism for downloading media if the initial buffer is not available.
- This change ensures that media messages are reliably converted to base64 format, improving the robustness of media handling in the WhatsApp integration service.
- Updated error logging to capture issues during the media conversion process.
Refatoração da funcionalidade de chatbots (em andamento)
- Adjusted spacing in destructuring assignments for `remoteJid` in multiple locations to enhance code readability and maintain consistency with coding standards.
- Removed unnecessary blank lines to streamline the code structure.

This commit focuses on improving the overall style of the `whatsapp.baileys.service.ts` file without altering any functionality.
- Changed the type of `keywordFinish` from an array to a string in multiple DTOs and controller interfaces to simplify data handling.
- Updated the `BaseChatbotService` to include logic for updating session status to 'opened' and managing user responses more effectively.
- Refactored the media message handling in the `BaseChatbotService` to streamline the process and improve readability.
- Enhanced error logging across various services to ensure better traceability during operations.

This commit focuses on improving the structure and consistency of chatbot integrations while ensuring that session management is robust and user-friendly.
- Added new environment variables for SSL configuration, including `SSL_CONF_PRIVKEY` and `SSL_CONF_FULLCHAIN`, to support secure connections.
- Introduced additional webhook configuration options in the `.env.example` file, such as `WEBHOOK_REQUEST_TIMEOUT_MS`, `WEBHOOK_RETRY_MAX_ATTEMPTS`, and related retry settings to improve webhook resilience and error handling.
- Updated the `bootstrap` function in `main.ts` to handle SSL certificate loading failures gracefully, falling back to HTTP if necessary.
- Enhanced error handling and logging in the `BusinessStartupService` to ensure better traceability and robustness when processing messages.

This commit focuses on improving the security and reliability of webhook interactions while ensuring that the application can handle SSL configurations effectively.
- Updated various chatbot services (Typebot, Dify, EvolutionBot, Flowise, N8n) to include the OpenAI service for audio transcription capabilities.
- Modified constructors to accept OpenaiService as a dependency, enhancing the ability to transcribe audio messages directly within each service.
- Refactored the handling of `keywordFinish` in multiple controllers and services, changing its type from an array to a string for consistency and simplifying logic.
- Removed redundant audio transcription logic from the base service, centralizing it within the OpenAI service to improve maintainability and reduce code duplication.

This commit focuses on enhancing the chatbot services by integrating OpenAI's transcription capabilities, improving code structure, and ensuring consistent handling of session keywords.
- Integrated OpenAI service into the EvoaiService to streamline audio message transcription.
- Updated the constructor to initialize OpenaiService, allowing for direct transcription of audio messages.
- Refactored audio message handling to utilize the OpenAI service for improved reliability and maintainability.
- Adjusted the processing logic to handle transcription results more effectively, ensuring fallback content is provided when transcription fails.

This commit focuses on enhancing the EvoaiService's capabilities by leveraging OpenAI for audio transcription, improving overall service functionality and code structure.
Corrige o problema de formatação nas mensagens do N8n onde quebras de linha extras estavam sendo adicionadas antes e depois das mídias (imagens, vídeos, etc). Agora o texto é enviado mantendo apenas as quebras de linha intencionais.
Corrige o problema onde o Evolution Bot não processava mensagens subsequentes após a primeira resposta. A correção permite que o bot continue respondendo a todas as mensagens enquanto a sessão estiver ativa, melhorando a continuidade da conversa.
Corrige o problema onde o Evolution Bot reativava automaticamente por qualquer mensagem do usuario quando a sessão estava pausada. Agora, quando uma sessão está pausada, o bot ignora completamente as mensagens recebidas até que a sessão seja explicitamente reativada.
Corrige o problema onde o N8N reativava automaticamente a sessão após receber uma mensagem quando estava pausado. Agora, quando uma sessão está pausada, o bot ignora completamente as mensagens recebidas até que a sessão seja explicitamente reativada através do endpoint de mudança de status.
fix: melhora consistência e formatação dos chatbots (N8N e Evolution Bot)
chore: possibilita o envio de medias do tipo [svg, tiff] vindas do Chatwoot
Corrige o envio da apiKey no payload do Evolution Bot para usar a apiKey específica da instância ao invés da apiKey global do sistema.
Corrige o envio da apiKey no payload do N8N para usar a apiKey específica da instância ao invés da apiKey global do sistema.
fix: Corrige envio da apiKey da instância nos payloads do Evolution Bot e N8N
Corrige o envio da apiKey no payload do Flowise para usar a apiKey específica da instância ao invés da apiKey global do sistema.
Corrige o envio da apiKey no payload do Dify para usar a apiKey específica da instância ao invés da apiKey global do sistema.
fix: Corrige envio da apiKey da instância nos payloads do Flowise e do Dify
…t-helper.ts

Esta PR corrige problemas de sintaxe no arquivo chatwoot-import-helper.ts, especificamente:
- Ajusta a estrutura do bloco if/else no método getExistingSourceIds, evitando erro de compilação do TypeScript.
- Garante que o bloco catch esteja corretamente posicionado dentro do método, retornando null em caso de erro.
- Mantém a lógica original do método, apenas corrigindo a sintaxe para permitir a compilação e execução correta do projeto.
Essas correções eliminam o erro de build relacionado ao TypeScript e melhoram a robustez do código ao tratar exceções de forma adequada.
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 22, 2025

Reviewer's Guide

This PR refactors getExistingSourceIds in chatwoot-import-helper.ts by updating its signature to accept an optional conversationId, conditionally adding a WHERE filter when conversationId is provided, and replacing the process exit in the catch block with a safe return of an empty set.

Sequence Diagram for OpenAI Audio Transcription

sequenceDiagram
    actor User
    participant OS as OpenaiService
    participant OAI as OpenAI API

    User->>OS: process(audio message, ...)
    OS->>OS: speechToText(msgOrBuffer, ...)
    OS->>OS: getAudioBufferFromMsg(msg, ...)
    activate OS
    OS-->>OS: audioBuffer
    deactivate OS
    OS->>OS: processAudioTranscription(audioBuffer)
    activate OS
    OS->>OAI: Transcribe audio (POST /v1/audio/transcriptions)
    OAI-->>OS: transcription text
    OS-->>OS: transcription
    deactivate OS
    OS-->>OS: transcription
    OS-->>User: (Sends message with transcribed text or uses it in bot logic)
Loading

Sequence Diagram for Typebot Audio Message Handling

sequenceDiagram
    actor User
    participant TC as TypebotController
    participant TS as TypebotService
    participant BCS as BaseChatbotService
    participant OS as OpenaiService
    participant TAPI as Typebot API
    participant WA as WhatsApp API

    User->>TC: emit(audio message, ...)
    TC->>TS: processTypebot(...)
    TS->>BCS: process(bot, audio content, ...)
    BCS->>TS: sendMessageToBot(audio content, ...)
    activate TS
    TS->>TS: isAudioMessage(content)
    alt Audio Message
        TS->>OS: speechToText(msg)
        OS-->>TS: transcription
        TS->>TAPI: continueChat/sendMessage (with transcription)
    else Not Audio Message
        TS->>TAPI: continueChat/sendMessage (original content)
    end
    TAPI-->>TS: Bot Response (messages, input, actions)
    deactivate TS
    TS->>TS: sendWAMessage(..., response.messages, ...)
    activate TS
    TS->>WA: Send Formatted Messages (text, media, buttons, list)
    deactivate TS
    WA-->>User: Bot Messages
Loading

Entity Relationship Diagram for EventDto NATS Integration

erDiagram
    EventDto {
        object webhook
        object sqs
        object rabbitmq
        object nats
        object pusher
        object websocket
    }
    EventDto ||--o{ nats : contains
    nats {
        boolean enabled "Optional"
        string events "Optional, Array of strings"
    }
Loading

Class Diagram for TypebotService Refactoring

classDiagram
    class BaseChatbotService {
        +process(...)
    }
    class OpenaiService {
        +speechToText(...)
    }
    class TypebotService {
        +TypebotService(waMonitor, configService, prismaRepository, openaiService: OpenaiService)
        +sendWAMessage(instance, session, settings, remoteJid, messages, input, clientSideActions)
        +processTypebot(instance, remoteJid, msg, session, bot, ...)
        #getBotType(): string
        #sendMessageToBot(instance, session, settings, bot, remoteJid, pushName, content, msg?)
        -openaiService: OpenaiService
        -initTypebotSession(instance, session, bot, remoteJid, pushName, prefilledVariables?)
        -processTypebotMessages(instance, session, settings, remoteJid, messages, input, clientSideActions)
        -parseListFormat(text: string)
        -parseButtonFormat(text: string)
    }
    BaseChatbotService <|-- TypebotService
    TypebotService o-- OpenaiService : uses for audio transcription
Loading

Class Diagram for WebhookController Enhancements

classDiagram
    class EventController
    class WebhookController {
        +set(instanceName, data)
        +sendData(instanceName, event, webhookData)
        #retryWebhookRequest(httpService, webhookData, origin, baseURL, serverUrl, maxRetries?, delaySeconds?)
        -generateJwtToken(authToken: string): string
    }
    EventController <|-- WebhookController
Loading

File-Level Changes

Change Details Files
Extended getExistingSourceIds signature with optional conversationId
  • Add conversationId parameter
  • Update return type to include optional param
src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts
Conditional SQL query based on conversationId
  • Introduce query variable assignment
  • Branch query to include conversation_id filter when provided
  • Fallback to original query otherwise
src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts
Adjust database call parameters
  • Pass formattedSourceIds and conversationId to pgClient.query
  • Wrap parameters in array matching query signature
src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts
Improve error handling in catch block
  • Replace process.exit with returning new Set()
  • Log error without terminating process
src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.