8000 fix: baileys send message with jid by CayoPOliveira · Pull Request #32 · fazer-ai/chatwoot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: baileys send message with jid #32

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 5 commits into from
Apr 29, 2025

Conversation

CayoPOliveira
Copy link
Collaborator
@CayoPOliveira CayoPOliveira commented Apr 27, 2025

…hanges

Pull Request Template

Description

Please include a summary of the change and issue(s) fixed. Also, mention relevant motivation, context, and any dependencies that this change requires.
Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

This change is Reviewable

Summary by CodeRabbit

  • Refactor

    • Streamlined WhatsApp message sending by unifying attachment and text handling into a single process.
    • Enhanced unsupported message detection, preventing their sending and clearly marking them.
    • Updated message sending to use a new recipient format for improved delivery.
  • Tests

    • Updated tests to align with the unified message sending approach and improved unsupported message handling.
    • Modified test cases to use the new WhatsApp recipient format.

Copy link
coderabbitai bot commented Apr 27, 2025

Walkthrough

This update refactors the message sending logic in the WhatsappBaileysService by consolidating separate methods for sending text and attachment messages into a unified approach. The new implementation prepares the message content based on whether it contains text or attachments and sends it through a single request method. Unsupported messages are now flagged by updating their content attributes and status instead of returning early without content. Corresponding tests have been updated to reflect these changes, including the handling of unsupported messages and the use of WhatsApp JID formatting in API requests.

Changes

File(s) Change Summary
app/services/whatsapp/providers/whatsapp_baileys_service.rb Refactored message sending logic to use a unified method for both text and attachments, removed send_attachment_message and send_text_message, added new methods for preparing attachment content, sending the message request, and formatting the contact JID. Unsupported messages are now flagged by setting content attributes and status to failed. The API request field recipient was replaced by jid formatted as <phone_number>@s.whatsapp.net.
spec/services/whatsapp/providers/whatsapp_baileys_service_spec.rb Updated tests to match the new unified message sending logic, added tests for unsupported messages setting content and status, removed old unsupported message tests, and updated HTTP request stubs to use the jid field with WhatsApp JID formatting consistently across all scenarios, including error cases.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WhatsappBaileysService
    participant HTTParty

    User->>WhatsappBaileysService: send_message(phone_number, message)
    alt message has attachments
        WhatsappBaileysService->>WhatsappBaileysService: attachment_message_content(message)
        WhatsappBaileysService->>WhatsappBaileysService: contact_jid(phone_number)
        WhatsappBaileysService->>HTTParty: send_message_request(jid, attachment_content)
    else message has text
        WhatsappBaileysService->>WhatsappBaileysService: contact_jid(phone_number)
        WhatsappBaileysService->>HTTParty: send_message_request(jid, text_content)
    else unsupported message
        WhatsappBaileysService->>WhatsappBaileysService: set content_attributes['is_unsupported'] = true
        WhatsappBaileysService->>WhatsappBaileysService: update status to failed
        WhatsappBaileysService-->>User: return nil
    end
    HTTParty-->>WhatsappBaileysService: response
    WhatsappBaileysService-->>User: message_id or error
Loading

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • gabrieljablonski

Poem

In the warren of code, a new path we send,
Messages unified, old branches now end.
Attachments or text, all hop in one flow,
Unsupported ones flagged, so everyone knows.
With JIDs in our paws and requests sent with cheer,
This bunny says, "Great work—let's ship it this year!" 🐇✨

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)
app/services/whatsapp/providers/whatsapp_baileys_service.rb

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

spec/services/whatsapp/providers/whatsapp_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 d982fb5 and 5f17f91.

📒 Files selected for processing (2)
  • app/services/whatsapp/providers/whatsapp_baileys_service.rb (3 hunks)
  • spec/services/whatsapp/providers/whatsapp_baileys_service_spec.rb (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • spec/services/whatsapp/providers/whatsapp_baileys_service_spec.rb
  • app/services/whatsapp/providers/whatsapp_baileys_service.rb
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
@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.

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

@CayoPOliveira CayoPOliveira merged commit 8dc893d into fazer-ai/main Apr 29, 2025
2 checks passed
@CayoPOliveira CayoPOliveira deleted the fix/baileys-api-send-message-jid branch April 29, 2025 23:52
@coderabbitai coderabbitai bot mentioned this pull request May 8, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved for merge enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0