Skip to content

chore: possibilita o envio de medias do tipo [svg, tiff] vindas do Chatwoot #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025

Conversation

KokeroO
Copy link
Contributor

@KokeroO KokeroO commented May 22, 2025

Descrição

Este PR adiciona a possiblidade de envio de arquivos do tipo SVG e TIFF da mesma forma que faz com do tipo GIF vindas do Chatwoot.
Atualmente o WhatsApp WEB somente aceita imagens do tipo JPG, PNG e WEBP de forma nativa, GIF e SVG o core processa as imagens em JPEG e PNG respectivamente.

Como o Chatwoot não entende que isso é um problema no canal de API deles, visto que o envio do arquivo é feito puro. Então sim, se entende ser um problema da API. Devemos tratar esses attachs na API Evolution.

Proposta

Enviar os tipos SVG e TIFF da mesma forma que atualmente é feito com as imagens do tipo GIF.

Solução

Adicionei uma constante com um array de extensões de mimetype: image e que deverão ser enviadas como tipo document. O array permite a fácil inclusão de outros tipos de imagens que poderão ser identificadas futuramente.

const documentExtensions = ['.gif', '.svg', '.tiff'];
if (type === 'image' && parsedMedia && documentExtensions.includes(parsedMedia?.ext)) {
  type = 'document';
}

Futuro

Futuramente poderíamos implementar um processador de imagens. Convertendo nos formatos aceitáveis pelo WhatsApp.

Copy link
Contributor

sourcery-ai bot commented May 22, 2025

Reviewer's Guide

This PR generalizes the media handling logic by introducing a documentExtensions array (['.gif', '.svg', '.tiff']) and updating the condition to send matching images as documents, thereby enabling SVG and TIFF support in the Chatwoot integration.

Sequence Diagram for Handling Special Image Attachments from Chatwoot

sequenceDiagram
    participant C as Chatwoot
    participant API as "ChatwootService (API)"
    participant WA as WhatsApp

    C->>+API: Send message with image (e.g., .svg, .tiff, .gif)
    API->>API: Received type: 'image', attachment_extension: ext
    alt ext is in documentExtensions ['.gif', '.svg', '.tiff']
        API->>API: Modify type: 'image' -> 'document'
        API->>+WA: Send message (type='document', media)
    else Other image types (e.g., .jpg, .png)
        API->>+WA: Send message (type='image', media)
    end
    WA-->>-API: Delivery Status
    API-->>-C: Message Status
Loading

File-Level Changes

Change Details Files
Extract and define a reusable list of media extensions for document mapping
  • Added a documentExtensions constant array containing ['.gif', '.svg', '.tiff']
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
Replace hardcoded GIF check with array-based condition to include SVG and TIFF
  • Updated the if (type === 'image' && parsedMedia?.ext === '.gif') to use documentExtensions.includes(parsedMedia.ext)
src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

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

@KokeroO
Copy link
Contributor Author

KokeroO commented May 22, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @KokeroO - I've reviewed your changes - here's some feedback:

  • Consider hoisting the documentExtensions array out of the function (or module) scope to avoid recreating it on every call and centralize configuration.
  • You might also want to include the common .tif extension alongside .tiff to cover both naming variants.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@KokeroO
Copy link
Contributor Author

KokeroO commented May 22, 2025

@sourcery-ai resolve

@DavidsonGomes DavidsonGomes merged commit 6f47a54 into EvolutionAPI:develop May 22, 2025
1 check passed
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.

2 participants