10000 fix: handle extended text message type of incoming message upsert by CayoPOliveira · Pull Request #9 · fazer-ai/chatwoot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: handle extended text message type of incoming message upsert #9

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

Conversation

CayoPOliveira
Copy link
Collaborator
@CayoPOliveira CayoPOliveira commented Mar 30, 2025

This change is Reviewable

Summary by CodeRabbit

  • New Features
    • Enhanced message handling to now recognize text within extended message fields, ensuring improved reliability when traditional text content is missing.
  • Tests
    • Streamlined and reorganized tests to clearly distinguish and validate both standard and extended text message scenarios.
    • Updated expected outcomes for hotkey enablement based on configuration changes in the UI settings.

@Copilot Copilot AI review requested due to automatic review settings March 30, 2025 21:15
Copy link
coderabbitai bot commented Mar 30, 2025

Walkthrough

The changes update the message handling logic in the WhatsApp incoming message service. The service now checks for text in both the conversation key and the nested extendedTextMessage key. The text message creation method has been modified accordingly to use the new fallback lookup. Test cases have been reorganized into context blocks to separately verify messages with conversation and extendedTextMessage keys, enhancing clarity without altering the underlying assertions. Additionally, test outcomes for the isEditorHotKeyEnabled function have been adjusted based on the configuration state.

Changes

File(s) Change Summary
app/.../incoming_message_baileys_service.rb Updated message_type to check for text in both conversation and extendedTextMessage fields. Modified create_text_message to use the fallback.
spec/.../incoming_message_baileys_service_spec.rb Added context blocks in tests to separate validations for messages with conversation and extendedTextMessage keys.
app/.../useUISettings.spec.js Changed expected outcomes for isEditorHotKeyEnabled based on editor_message_key configuration: undefined now yields true for 'enter' and false for 'cmd_enter'.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant S as IncomingMessageBaileysService

    C->>S: Send raw message payload
    S->>S: Execute message_type()
    alt Message contains 'conversation' or 'extendedTextMessage' text
        S->>S: Recognize as text message
        S->>S: Call create_text_message() to extract content
        S->>C: Return created text message
    else
        S->>C: Process as non-text message
    end
Loading

Poem

I hopped through code with a joyful glow,
Checking texts where hidden words grow.
conversation or extendedTextMessage in play,
My clever tweaks now light the way.
With a twitch of my nose, I'm off to explore—
CodeRabbit leaps with changes galore! 🐰✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 RuboCop (1.73)
spec/services/whatsapp/incoming_message_baileys_service_spec.rb

Error: RSpec/FactoryBot/* has been extracted to the rubocop-factory_bot gem.
(obsolete configuration found in .rubocop.yml, please update it)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82ea7ed and d29b49c.

📒 Files selected for processing (1)
  • spec/services/whatsapp/incoming_message_baileys_service_spec.rb (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • spec/services/whatsapp/incoming_message_baileys_service_spec.rb
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the handling of extended text messages by updating the service logic and adding corresponding tests.

  • Added a new test context to verify that extendedTextMessage payloads are processed correctly.
  • Updated the message type detection to include extendedTextMessage and refactored message content extraction accordingly.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
spec/services/whatsapp/incoming_message_baileys_service_spec.rb Added new test contexts for messages having a conversation key and extendedTextMessage with text.
app/services/whatsapp/incoming_message_baileys_service.rb Modified message_type and create_text_message methods to correctly handle extended text messages.

Copy link
Member
@gabrieljablonski gabrieljablonski left a comment

Choose a reason for hiding this comment

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

-(review needed) +(approved for merge) +(questions/changes requested)

Reviewed 2 of 2 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @CayoPOliveira)


spec/services/whatsapp/incoming_message_baileys_service_spec.rb line 273 at r2 (raw file):

              pushName: 'John Doe'
            }
          end

Avoid this syntax (string as hash key). Rubocop won't complain (it's valid in some contexts), but we should avoid it.

Suggestion:

          let(:raw_message) do
            {
              key: { id: 'msg_123', remoteJid: '5511912345678@s.whatsapp.net', fromMe: false },
              message: { extendedTextMessage: { text: 'Hello from Baileys' } },
              pushName: 'John Doe'
            }
          end

@gabrieljablonski gabrieljablonski force-pushed the fazer-ai/main branch 4 times, most recently from 3fa895f to a70b858 Compare April 1, 2025 13:21
Copy link
Collaborator Author
@CayoPOliveira CayoPOliveira left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 19 files reviewed, 1 unresolved discussion (waiting on @gabrieljablonski)


spec/services/whatsapp/incoming_message_baileys_service_spec.rb line 273 at r2 (raw file):

Previously, gabrieljablonski (Gabriel Jablonski) wrote…

Avoid this syntax (string as hash key). Rubocop won't complain (it's valid in some contexts), but we should avoid it.

Done.

Copy link
Collaborator Author
@CayoPOliveira CayoPOliveira left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 17 files at r3.
Reviewable status: 3 of 19 files reviewed, 1 unresolved discussion (waiting on @gabrieljablonski)

Copy link
Collaborator Author
@CayoPOliveira CayoPOliveira left a comment

Choose a reason for hiding this comment

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

-(questions/changes requested) +(review needed)

Reviewable status: 3 of 19 files reviewed, 1 unresolved discussion (waiting on @gabrieljablonski)

Copy link
Member
@gabrieljablonski gabrieljablonski left a comment

Choose a reason for hiding this comment

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

Address pending comment and good to merge. No re-review needed.

-(review needed) +question +(approved for merge)

Reviewed 1 of 17 files at r3, 16 of 16 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @CayoPOliveira)


spec/services/whatsapp/incoming_message_baileys_service_spec.rb line 273 at r2 (raw file):

Previously, CayoPOliveira (Cayo P. R. Oliveira) wrote…

Done.

Still not fixed.

Copy link
Member
@gabrieljablonski gabrieljablonski left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @CayoPOliveira)

@CayoPOliveira CayoPOliveira merged commit 1a656ff into fazer-ai/main Apr 2, 2025
3 of 4 checks passed
@CayoPOliveira CayoPOliveira deleted the fix/handle-types-of-incoming-message-upsert branch April 2, 2025 17:29
gabrieljablonski added a commit that referenced this pull request Apr 4, 2025
* feat: support extended text messages in WhatsApp incoming message service

* fix: correct isEditorHotKeyEnabled's spec

* ci: add baileys-api service to docker-compose configuration

* feat!: update validate_provider_config? endpoint

* feat: add Resend email delivery method and configuration (#11)

* feat: add Resend email delivery method and configuration

* chore: simplify ResendProvider initialization by removing settings parameter

* test: update ResendProvider initialization in tests by removing unnecessary settings parameter

* chore: improvements

* chore: add support for external frontend URL in environment configuration

* chore: ensure trailing slash

* ci: updated docker compose

* feat: update Resend email delivery method to use headers for sender and recipient

* feat: update email templates to use user's name instead of email

* fix: simplify extended text message structure in Baileys service spec

---------

Co-authored-by: gabrieljablonski <contact@gabrieljablonski.com>
Co-authored-by: Gabriel Jablonski <gabriel@fazer.ai>
@coderabbitai coderabbitai bot mentioned this pull request May 1, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0