Skip to content

AdjButtonsLogic#123

Merged
clairton merged 3 commits intoclairton:mainfrom
rodrigo-gmengue:buttons
Dec 29, 2025
Merged

AdjButtonsLogic#123
clairton merged 3 commits intoclairton:mainfrom
rodrigo-gmengue:buttons

Conversation

@rodrigo-gmengue
Copy link
Collaborator

@rodrigo-gmengue rodrigo-gmengue commented Dec 29, 2025

Adjustments to button logic and improved compatibility.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected initialization logic for the native flow buttons configuration.
    • Fixed interactive message handling to prevent mixed/fall-through message types.
  • Improvements

    • Improved support for interactive messages with header media and clearer message flows.
    • Refined fallback behavior for buttons/list messages and standardized row/button resolution.
    • Updated default button label text.
  • Documentation

    • Added configuration option description for native flow buttons in README.

✏️ Tip: You can customize this high-level summary in your review settings.

Refactor interactive message handling to improve structure and clarity. Added support for native flow buttons and enhanced button mapping logic.
@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

Refactors interactive message construction: strict 'false' check for UNOAPI_NATIVE_FLOW_BUTTONS and a clear sequential transformer flow handling header media, list messages, native-flow buttons, and fallbacks (with MIME detection made tolerant).

Changes

Cohort / File(s) Summary
Configuration
src/defaults.ts
Changed UNOAPI_NATIVE_FLOW_BUTTONS init to a strict string comparison (=== 'false'), altering when native flow is considered enabled.
Message Processing
src/services/transformer.ts
Reworked interactive message handling into explicit paths: header media attachment (image/video/document/audio with tolerant MIME detection), list message construction (title/text/footer/buttonText default "Selecionar", rowId resolution), nativeFlowMessage construction when UNOAPI_NATIVE_FLOW_BUTTONS enabled (headers + mapped button types), and fallback reply/buttons path when disabled. Removed legacy mixed branches and added explicit breakpoints; changed default label from "Selecione" to "Selecionar".
Documentation
README.md
Added description for UNOAPI_NATIVE_FLOW_BUTTONS in CONFIG OPTIONS and notes about nativeFlowButtons behavior.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Transformer
  participant MIME as MIME Detector
  participant Baileys as Baileys/WaLib

  Client->>Transformer: send interactive message payload
  alt header.type exists and != text
    Transformer->>MIME: try detect mime & filename
    MIME-->>Transformer: mime (or silent fail)
    Transformer->>Baileys: attach top-level media + interactive meta
  end
  alt action.sections non-empty
    Transformer->>Baileys: build and return listMessage (title/text/footer/buttonText/sections)
  else UNOAPI_NATIVE_FLOW_BUTTONS == 'false'
    Transformer->>Baileys: build nativeFlowMessage (header/body/footer) + native buttons
  else
    Transformer->>Baileys: build reply/buttons fallback (cta_url/cta_call/cta_copy/quick_reply)
  end
  Baileys-->>Client: structured interactiveMessage (and nativeFlowMessage when present)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through code with nimble paws,

Lists and headers, tidy laws,
Buttons sorted, flows set free,
MIME whispers handled gently,
A little rabbit's polishing spree. 🥕✨

Pre-merge checks

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'AdjButtonsLogic' is vague and uses abbreviated, non-descriptive terminology that does not clearly convey what the changeset accomplishes. Use a more descriptive title such as 'Add native flow buttons support with configurable initialization' or 'Refactor button logic to support native flow messages' to clarify the main change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33c122c and ae4d761.

📒 Files selected for processing (1)
  • README.md
✅ Files skipped from review due to trivial changes (1)
  • README.md

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/services/transformer.ts (1)

255-260: Consider logging MIME detection failures at debug level.

The empty catch block silently swallows errors from MIME type detection. While the intent is to not fail message construction, adding debug-level logging would help troubleshoot issues when media messages don't include the expected MIME type.

🔎 Proposed improvement
           try {
             const tmpPayload: any = { type: mediaType }
             tmpPayload[mediaType] = { link }
             const mimetype = getMimetype(tmpPayload)
             if (mimetype) response.mimetype = mimetype
-          } catch {}
+          } catch (e) {
+            logger.debug('Failed to detect mimetype for header media: %s', e)
+          }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b9584d and 33c122c.

📒 Files selected for processing (2)
  • src/defaults.ts
  • src/services/transformer.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/services/transformer.ts (1)
src/defaults.ts (1)
  • UNOAPI_NATIVE_FLOW_BUTTONS (29-30)
🔇 Additional comments (3)
src/services/transformer.ts (3)

269-288: LGTM!

The list message handling is well-structured with proper fallbacks for row IDs (row.id || row.rowId) and an explicit break to prevent fall-through.


295-364: Native flow button mapping logic is sound, but depends on the inverted flag.

The button type mapping and nativeFlowMessage construction look correct. The .filter(Boolean) at line 346 properly removes any undefined entries.

Note: This code path will only be entered when useNativeFlow is true, which due to the bug in src/defaults.ts (lines 29-30), occurs when the environment variable UNOAPI_NATIVE_FLOW_BUTTONS is set to 'false'.


372-410: LGTM!

The fallback button handling for non-native flow is well-structured, maintaining backward compatibility with the buttonId/buttonText/type format.

Comment on lines 29 to +30
export const UNOAPI_NATIVE_FLOW_BUTTONS: boolean =
process.env.UNOAPI_NATIVE_FLOW_BUTTONS === _undefined ? false : process.env.UNOAPI_NATIVE_FLOW_BUTTONS == 'false'
process.env.UNOAPI_NATIVE_FLOW_BUTTONS === 'false'
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Inverted logic: setting env var to 'false' enables native flow buttons.

The expression === 'false' makes the constant true when the environment variable is set to the string 'false', which is semantically inverted. Users setting UNOAPI_NATIVE_FLOW_BUTTONS=true will unexpectedly disable native flow, while UNOAPI_NATIVE_FLOW_BUTTONS=false will enable it.

Expected behavior based on the variable name:

  • UNOAPI_NATIVE_FLOW_BUTTONS=true → enable native flow
  • UNOAPI_NATIVE_FLOW_BUTTONS=false → disable native flow
🔎 Proposed fix
 export const UNOAPI_NATIVE_FLOW_BUTTONS: boolean =
-  process.env.UNOAPI_NATIVE_FLOW_BUTTONS === 'false'
+  process.env.UNOAPI_NATIVE_FLOW_BUTTONS !== 'false'

Alternatively, to match the pattern used elsewhere in this file and default to false when undefined:

 export const UNOAPI_NATIVE_FLOW_BUTTONS: boolean =
-  process.env.UNOAPI_NATIVE_FLOW_BUTTONS === 'false'
+  process.env.UNOAPI_NATIVE_FLOW_BUTTONS == _undefined ? false : process.env.UNOAPI_NATIVE_FLOW_BUTTONS == 'true'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const UNOAPI_NATIVE_FLOW_BUTTONS: boolean =
process.env.UNOAPI_NATIVE_FLOW_BUTTONS === _undefined ? false : process.env.UNOAPI_NATIVE_FLOW_BUTTONS == 'false'
process.env.UNOAPI_NATIVE_FLOW_BUTTONS === 'false'
export const UNOAPI_NATIVE_FLOW_BUTTONS: boolean =
process.env.UNOAPI_NATIVE_FLOW_BUTTONS !== 'false'
🤖 Prompt for AI Agents
In src/defaults.ts around lines 29-30, the boolean assignment is inverted:
UNOAPI_NATIVE_FLOW_BUTTONS is set to true when
process.env.UNOAPI_NATIVE_FLOW_BUTTONS === 'false'. Change the logic to evaluate
the env var as truthy for 'true' (or follow the file pattern) so that
UNOAPI_NATIVE_FLOW_BUTTONS is true when the env var equals 'true' (and defaults
to false when undefined); update the expression accordingly and ensure it parses
the string value consistently with other defaults in this file.

Added configuration for UNOAPI native flow buttons support.
@clairton clairton merged commit de36327 into clairton:main Dec 29, 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