Skip to content

Conversation

@priyanshu6238
Copy link
Collaborator

@priyanshu6238 priyanshu6238 commented Dec 29, 2025

Summary

This PR enhances the Webhook Router Form by allowing users to manually input a custom function name when the predefined options from the backend do not meet their needs. This provides greater flexibility for developers using the webhook router in FUNCTION mode.

Changes

  1. Conditional Field Switching: Replaced the standard search dropdown with a conditional block. If a user selects the Custom option, the dropdown is swapped for a TextInputElement.
Screenshot 2025-12-29 at 3 14 10 PM

2-Where you can edit the label name and body.

  1. Added a custom wrapper around the text input containing a "light arrow" chevron icon (▾). Clicking this icon resets the state, allowing users to return to the preset search list.
Screenshot 2025-12-29 at 3 18 08 PM

@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

Adds a custom-webhook option and UI to WebhookRouterForm: CSS for the custom input and toggle; component logic to detect/fallback to a custom function, update URL/body accordingly, and conditionally render either a select or the custom input with toggle.

Changes

Cohort / File(s) Summary
Webhook Custom Function Styling
src/components/flow/routers/webhook/WebhookRouterForm.module.scss
Adds .custom_function_wrapper with full-width layout and nested .toggle_icon absolutely positioned to the right, vertically centered, with pointer cursor, color/hover styles and z-index.
Webhook Custom Function Logic
src/components/flow/routers/webhook/WebhookRouterForm.tsx
On mount, if METHOD is FUNCTION and URL's function name isn't in webhook options, select a custom_webhook fallback and set URL/body appropriately; introduces isCustom handling in function-change logic; conditionally renders a custom input + toggle for custom_webhook or the existing select for named functions; ensures body is '{}' for custom and URL reflects selection consistently.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant WebhookForm as WebhookRouterForm
  participant API as Backend / webhookOptions

  User->>WebhookForm: Open form (METHOD = FUNCTION, URL present)
  WebhookForm->>API: fetchWebhookOptions()
  API-->>WebhookForm: webhookOptions (list)
  alt URL function in options
    WebhookForm->>WebhookForm: set selected named function, set URL to function name, keep/restore body
  else URL function not in options
    WebhookForm->>WebhookForm: set selected = custom_webhook, set URL to '' or custom name, set body = '{}'
  end

  User->>WebhookForm: change function selection
  alt selects named function
    WebhookForm->>WebhookForm: set URL = selected name, restore backend/default body
  else selects custom_webhook
    WebhookForm->>WebhookForm: render custom input + toggle, set URL = '', set body = '{}'
  end

  User->>WebhookForm: toggle/reset custom
  WebhookForm->>WebhookForm: clear URL or switch back to select UI
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • shijithkjayan
  • akanshaaa19
  • madclaws

Poem

🐇 I hopped into the form today,

a custom hook to light the way.
Toggle bright and body neat,
URL set, the flow's complete.
Hooray — the webhook's new heartbeat! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately summarizes the main change: adding a custom webhook option to the Webhook Router Form, matching the core feature described in the PR objectives.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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

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

@priyanshu6238 priyanshu6238 changed the title feat: add custom webhook feat: Add custom webhook option Dec 29, 2025
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/components/flow/routers/webhook/WebhookRouterForm.tsx (1)

95-110: Redundant null check on line 106.

Since selectedOption is always assigned a value (either from find() or from the fallback object creation on lines 97-101), the || null is unreachable.

🔎 Suggested simplification
       this.setState({
         webhookOptions,
-        webhookFunction: { value: selectedOption || null },
+        webhookFunction: { value: selectedOption },
         url: {
           value: selectedOption.value === 'custom' ? this.state.url.value : selectedOption.name
         }
       });
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a7f1a7 and b2b1f61.

📒 Files selected for processing (2)
  • src/components/flow/routers/webhook/WebhookRouterForm.module.scss
  • src/components/flow/routers/webhook/WebhookRouterForm.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/flow/routers/webhook/WebhookRouterForm.tsx (2)
src/components/form/textinput/TextInputElement.tsx (1)
  • TextInputElement (35-94)
src/temba/TembaSelectElement.tsx (1)
  • TembaSelectElement (13-26)
🔇 Additional comments (3)
src/components/flow/routers/webhook/WebhookRouterForm.module.scss (1)

101-127: LGTM!

The styling for the custom function wrapper and toggle icon is well-structured. The absolute positioning with vertical centering, hover state, and user-select: none are appropriate for an interactive toggle element.

src/components/flow/routers/webhook/WebhookRouterForm.tsx (2)

142-146: Potential validation inconsistency when clearing function selection.

When selected is null (line 145), body is set to an empty string. However, in handleUpdate (lines 238-243), an empty body only bypasses JSON validation for FUNCTION method, but if the user then saves, the empty body may cause issues downstream.

Consider whether clearing the function should also set body to '{}' to maintain valid JSON, or verify that empty body is acceptable throughout the flow.


85-91: Verify: How do users select the "Custom" option initially?

The Custom option is only created in componentDidMount when loading an existing node with a non-matching function name (lines 96-101). However, the webhookOptions array built from the backend (lines 85-91) doesn't include a Custom option.

This means users cannot switch to custom mode from a fresh state—they can only end up in custom mode by loading a previously saved custom function. Is this intentional, or should a Custom option be appended to webhookOptions so users can select it?

Also applies to: 439-472

@priyanshu6238 priyanshu6238 self-assigned this Dec 29, 2025
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: 0

♻️ Duplicate comments (1)
src/components/flow/routers/webhook/WebhookRouterForm.tsx (1)

441-475: Conditional rendering logic is correct.

The implementation properly switches between custom input and function selection based on the webhookFunction value. The loading state and placeholder text provide good user feedback.

Note: The accessibility issue with the toggle icon (lines 451-456) lacking keyboard support has already been flagged in previous reviews.

🧹 Nitpick comments (3)
src/components/flow/routers/webhook/WebhookRouterForm.tsx (3)

122-153: Logic looks good with proper null safety.

The function correctly handles custom vs named webhooks with appropriate URL and body updates. The use of optional chaining (selected?.value) provides good defensive programming.

One minor observation: At line 106 in componentDidMount, the expression selectedOption || null is redundant since selectedOption is always defined (either from find or the custom fallback object on lines 97-101). You can simplify to:

-        webhookFunction: { value: selectedOption || null },
+        webhookFunction: { value: selectedOption },

85-91: Consider defining a proper type for webhook options.

The webhook options are currently mapped to objects with specific properties but lack a defined type. While using any (line 95) works, defining an interface would improve type safety and code maintainability.

🔎 Suggested enhancement

Add an interface at the top of the file:

interface WebhookOption {
  name: string;
  value: string;
  id: string;
  label: string;
  body?: string;
}

Then update the state type and usage:

export interface WebhookRouterFormState extends FormState {
  headers: HeaderEntry[];
  method: MethodEntry;
  url: StringEntry;
  body: StringEntry;
  resultName: StringEntry;
  webhookFunction: FormEntry;
-  webhookOptions: any[];
+  webhookOptions: WebhookOption[];
  isLoading: boolean;
}

And at line 95:

-        let selectedOption = webhookOptions.find((opt: any) => opt.name === functionName);
+        let selectedOption = webhookOptions.find((opt) => opt.name === functionName);

93-111: Consider adding a permanent "Custom" option to webhookOptions for better UX discoverability.

The current implementation requires users to click the toggle icon (▾) to switch into custom webhook mode. While functional, a "Custom" option in the dropdown would be more discoverable. If TembaSelect's allowCreate prop is already enabled, this change is unnecessary; otherwise, consider adding a permanent custom option as shown in the suggested enhancement.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2b1f61 and a80b20b.

📒 Files selected for processing (1)
  • src/components/flow/routers/webhook/WebhookRouterForm.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/flow/routers/webhook/WebhookRouterForm.tsx (2)
src/components/form/textinput/TextInputElement.tsx (1)
  • TextInputElement (35-94)
src/temba/TembaSelectElement.tsx (1)
  • TembaSelectElement (13-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Coverage
  • GitHub Check: Tests (16.x)

@priyanshu6238 priyanshu6238 changed the title feat: Add custom webhook option Add custom webhook option Dec 30, 2025
@priyanshu6238 priyanshu6238 marked this pull request as draft January 2, 2026 12:01
@priyanshu6238
Copy link
Collaborator Author

Closing this — will create new pr , that provides a direct way to add a custom webhook directly from the dropdown. when the option is not present.

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