Skip to content

Conversation

@letfontenelle
Copy link

@letfontenelle letfontenelle commented Oct 15, 2025

πŸ“‹ Description

πŸ”— Related Issue

Closes #(issue_number)

πŸ§ͺ Type of Change

  • πŸ› 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 to not work as expected)
  • πŸ“š Documentation update
  • πŸ”§ Refactoring (no functional changes)
  • ⚑ Performance improvement
  • 🧹 Code cleanup
  • πŸ”’ Security fix

πŸ§ͺ Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced
  • Tested with different connection types (if applicable)

πŸ“Έ Screenshots (if applicable)

βœ… Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have manually tested my changes thoroughly
  • I have verified the changes work with different scenarios
  • Any dependent changes have been merged and published

πŸ“ Additional Notes

Summary by Sourcery

Refactor middleware and service logic in main and WhatsApp Baileys integration, remove unused parameters, and revert version to 2.3.2

Enhancements:

  • Extract CORS options into a separate object and apply urlencoded, json, and compression middleware individually
  • Simplify lid extraction logic in BaileysStartupService by removing redundant branch
  • Remove the unused force parameter from assertSessions in both service and event handler

Chores:

  • Downgrade project version from 2.3.4 to 2.3.2

…ecessary parameters

- Refactored CORS middleware setup in main.ts for improved readability and maintainability.
- Removed the 'force' parameter from assertSessions method in Baileys service for consistency.
- Updated related calls in useVoiceCallsBaileys to align with the new method signature.
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 15, 2025

Reviewer's Guide

Refactored CORS middleware setup, streamlined LID extraction and session assertion logic in the WhatsApp integration, and downgraded the package version.

Sequence diagram for updated CORS middleware setup in bootstrap

sequenceDiagram
participant App
participant ConfigService
participant CorsMiddleware
App->>ConfigService: get('CORS')
App->>CorsMiddleware: cors(corsOptions)
CorsMiddleware->>ConfigService: get('CORS')
CorsMiddleware-->>App: Allow/deny request origin
Loading

Class diagram for BaileysStartupService session assertion method change

classDiagram
class BaileysStartupService {
  +baileysAssertSessions(jids: string[]): Promise<any>
}
BaileysStartupService --> Client : uses
class Client {
  +assertSessions(jids: string[]): Promise<any>
}
Loading

Class diagram for streamlined LID extraction in BaileysStartupService

classDiagram
class BaileysStartupService {
  +extractLid(numberJid: string): string | undefined
}
BaileysStartupService : - lid extraction logic simplified
Loading

File-Level Changes

Change Details Files
Extracted CORS configuration into a dedicated options object and updated middleware usage
  • Defined corsOptions constant with origin, methods, and credentials
  • Replaced inline cors call with app.use(cors(corsOptions))
  • Separated urlencoded, json, and compression middleware into individual app.use calls
  • Added type assertion for compression()
src/main.ts
Simplified LID extraction logic in WhatsApp Baileys service
  • Removed conditional type check on numberVerified.lid
  • Inlined '@lid' split operation into a single expression
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Removed force parameter from session assertion methods
  • Updated baileysAssertSessions signature to drop 'force' argument
  • Adjusted client.assertSessions call accordingly
  • Updated socket event handler in useVoiceCallsBaileys to omit force parameter
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
src/api/integrations/channel/whatsapp/voiceCalls/useVoiceCallsBaileys.ts
Downgraded project version
  • Changed version from 2.3.4 to 2.3.2
package.json

Possibly linked issues

  • #Regression Issue: The PR downgrades the project version to 2.3.2, directly resolving the regressions reported in versions 2.3.3 and 2.3.4.

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

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 there - I've reviewed your changes - here's some feedback:

  • Consider retrieving the CORS config once outside the origin callback to avoid hitting configService.get on every request and improve performance.
  • The cast compression() as any bypasses type safetyβ€”import or declare the correct middleware type instead of using any.
  • You’ve removed the force parameter from baileysAssertSessions and its callersβ€”double-check that this preserves the intended session assertion behavior and update related interfaces or logic if needed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider retrieving the CORS config once outside the origin callback to avoid hitting `configService.get` on every request and improve performance.
- The cast `compression() as any` bypasses type safetyβ€”import or declare the correct middleware type instead of using `any`.
- You’ve removed the `force` parameter from `baileysAssertSessions` and its callersβ€”double-check that this preserves the intended session assertion behavior and update related interfaces or logic if needed.

## Individual Comments

### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:3370` </location>
<code_context>
-              : numberJid.includes('@lid')
-                ? numberJid.split('@')[1]
-                : undefined;
+          const lid = numberJid.includes('@lid') ? numberJid.split('@')[1] : undefined;
           return new OnWhatsAppDto(
             numberJid,
</code_context>

<issue_to_address>
**question:** The new lid extraction logic may not handle all edge cases.

The new logic may miss cases where numberVerified.lid is set but numberJid lacks '@lid'. Please review if this could impact functionality.
</issue_to_address>

### Comment 2
<location> `src/api/integrations/channel/whatsapp/voiceCalls/useVoiceCallsBaileys.ts:74` </location>
<code_context>
   socket.on('assertSessions', async (jids, force, callback) => {
     try {
-      const response = await baileys_sock.assertSessions(jids, force);
+      const response = await baileys_sock.assertSessions(jids);

       callback(response);
</code_context>

<issue_to_address>
**question (bug_risk):** The removal of the 'force' argument may affect voice call session assertions.

Verify that removing the 'force' parameter does not break any session assertion scenarios.
</issue_to_address>

### Comment 3
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:4560-4562` </location>
<code_context>
    const response = await this.client.assertSessions(jids);

    return response;

</code_context>

<issue_to_address>
**suggestion (code-quality):** Inline variable that is immediately returned ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/TypeScript/Default-Rules/inline-immediately-returned-variable))

```suggestion
    return await this.client.assertSessions(jids);

```

<br/><details><summary>Explanation</summary>Something that we often see in people's code is assigning to a result variable
and then immediately returning it.

Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.

Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.
</details>
</issue_to_address>

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.

: numberJid.includes('@lid')
? numberJid.split('@')[1]
: undefined;
const lid = numberJid.includes('@lid') ? numberJid.split('@')[1] : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

question: The new lid extraction logic may not handle all edge cases.

The new logic may miss cases where numberVerified.lid is set but numberJid lacks '@lid'. Please review if this could impact functionality.

socket.on('assertSessions', async (jids, force, callback) => {
try {
const response = await baileys_sock.assertSessions(jids, force);
const response = await baileys_sock.assertSessions(jids);
Copy link
Contributor

Choose a reason for hiding this comment

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

question (bug_risk): The removal of the 'force' argument may affect voice call session assertions.

Verify that removing the 'force' parameter does not break any session assertion scenarios.

Comment on lines +4560 to 4562
const response = await this.client.assertSessions(jids);

return response;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
const response = await this.client.assertSessions(jids);
return response;
return await this.client.assertSessions(jids);


ExplanationSomething that we often see in people's code is assigning to a result variable
and then immediately returning it.

Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.

Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.

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