Conversation
Refactor interactive message handling to improve structure and clarity. Added support for native flow buttons and enhanced button mapping logic.
📝 WalkthroughWalkthroughRefactors 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
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)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
Pre-merge checks❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/defaults.tssrc/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
useNativeFlowis true, which due to the bug insrc/defaults.ts(lines 29-30), occurs when the environment variableUNOAPI_NATIVE_FLOW_BUTTONSis set to'false'.
372-410: LGTM!The fallback button handling for non-native flow is well-structured, maintaining backward compatibility with the
buttonId/buttonText/typeformat.
| 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' |
There was a problem hiding this comment.
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 flowUNOAPI_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.
| 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.
Adjustments to button logic and improved compatibility.
Summary by CodeRabbit
Bug Fixes
Improvements
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.