Skip to content

[CM-1345] Prechat lead support for Regex - iOS SDK#505

Merged
kandpal025 merged 1 commit intodevfrom
CM-1345
Jul 2, 2025
Merged

[CM-1345] Prechat lead support for Regex - iOS SDK#505
kandpal025 merged 1 commit intodevfrom
CM-1345

Conversation

@KommunicateDeveloper
Copy link
Contributor

@KommunicateDeveloper KommunicateDeveloper commented Jun 23, 2025

Summary

  • Added a Regex for name, email, password.
  • Also Localized the error labels for easy customization.

Example Code

preChatVC.preChatConfiguration.optionsToShow = [.email, .name, .phoneNumber, .password] // Configure options to be visible in pre-chat
preChatVC.preChatConfiguration.mandatoryOptions = [.email, .name, .phoneNumber, .password] // Configure mandatory options
preChatVC.preChatConfiguration.passwordRegexPattern = "^(?=.*[A-Z])(?=.*\\d)(?=.*[^a-zA-Z\\d]).{8,}$"
preChatVC.preChatConfiguration.nameRegexPattern = "^[A-Z][a-z]{0,13}$"
preChatVC.preChatConfiguration.emailRegexPattern = "^[A-Za-z0-9._%+-]+@(gmail\\.com|hotmail\\.com)$"
preChatVC.preChatConfiguration.phoneNumberRegexPattern = "^[0-9]{10}$"

Localizable Keys

/* Invalid Email error message for custom regex */
PreChatViewEmailRegexFailedError = "Please enter valid email address";
/* Invalid Name error message for custom regex */
PreChatViewNameRegexFailedError = "Please enter valid name";
/* Invalid Password error message for custom regex */
PreChatViewPasswordRegexFailedError = "Please enter valid password";

Testing Branches

KM_ChatUI_Branch : dev
KM_Core_Branch: dev

Summary by CodeRabbit

  • New Features
    • Added support for custom regular expression validation for name, email, and password fields in the pre-chat form.
    • Introduced specific error messages for invalid name, email, and password inputs when custom validation fails.
  • Improvements
    • Enhanced pre-chat form validation logic for more precise feedback on input errors.
    • Updated label in the pre-chat user form to allow unlimited lines and dynamic height adjustment for better display of error messages.

@coderabbitai
Copy link

coderabbitai bot commented Jun 23, 2025

Walkthrough

The update introduces new optional regex-based validation for name, email, and password fields in the pre-chat form, with corresponding error messages and UI adjustments. It adds localized strings for new error cases, updates validation logic to handle custom regex patterns, and modifies a label in the user form view to better accommodate dynamic content.

Changes

File(s) Change Summary
Example/Kommunicate/Base.lproj/Localizable.strings
Sources/Resources/Assets/Localizable.strings
Added new localized strings for custom regex validation errors for email, name, and password fields.
Sources/Kommunicate/Classes/KMPreChatFormViewController.swift Added optional regex pattern properties to configuration; revised validation logic; new error cases for custom regex failures.
Sources/Resources/Assets/KMPreChatUserFormView.xib Updated label to support unlimited lines, word wrapping, enabled interaction, and removed fixed height.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PreChatFormViewController
    participant PreChatConfiguration

    User->>PreChatFormViewController: Submit pre-chat form
    PreChatFormViewController->>PreChatConfiguration: Access regex patterns (name, email, password)
    PreChatFormViewController->>PreChatFormViewController: Validate fields
    alt Field is empty
        PreChatFormViewController-->>User: Show required field error
    else Field not empty
        alt Custom regex provided
            PreChatFormViewController->>PreChatFormViewController: Validate with custom regex
            alt Regex fails
                PreChatFormViewController-->>User: Show custom regex error message
            else Regex passes
                PreChatFormViewController->>PreChatFormViewController: Continue validation
            end
        else No custom regex
            PreChatFormViewController->>PreChatFormViewController: Use default validation
        end
    end
    PreChatFormViewController-->>User: Show success or next step
Loading

Poem

A regex hop, a bunny bound,
New patterns in the fields are found.
Labels stretch and errors sing,
"Please try again!" the prompts now ring.
With every form, we leap ahead—
More flexible, just as we said!
🐇✨

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.

@KommunicateDeveloper
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jun 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🔭 Outside diff range comments (1)
Sources/Kommunicate/Classes/KMPreChatFormViewController.swift (1)

307-390: Consider simplifying the complex validation logic.

The validation method has become quite complex with nested conditions and multiple validation paths. Consider refactoring to improve readability and maintainability:

  1. Extract individual field validation into separate methods
  2. Consider using a more functional approach with validation result accumulation
  3. The interaction between allowEmailOrPhoneNumber and individual field validation could be clearer

Example refactor approach:

private func validateEmail(_ text: String?) -> TextFieldValidationError? {
    guard let text = text, !text.isEmpty else {
        return .emptyEmailAddress
    }
    
    guard text.isValidEmail else {
        return .invalidEmailAddress  
    }
    
    if let pattern = preChatConfiguration.emailRegexPattern,
       !text.matchesWithPattern(pattern) {
        return .invalidCustomEmailRegex
    }
    
    return nil
}
♻️ Duplicate comments (1)
Example/Kommunicate/Base.lproj/Localizable.strings (1)

33-38: Consistent localization keys added.

The localization keys are consistent with the main resource file, which is good for maintaining uniformity across the codebase. However, the same concern applies here regarding the generic nature of the error messages - they don't provide specific guidance about the expected input format for custom regex patterns.

🧹 Nitpick comments (1)
Sources/Resources/Assets/Localizable.strings (1)

29-34: Consider more descriptive validation error messages.

The new regex validation error messages are quite generic and don't provide users with specific guidance about the expected input format. Since these are for custom regex patterns that developers will configure, consider making the messages more informative or allowing developers to provide custom error messages.

For example, instead of "Please enter valid email address", consider something like "Email format does not match the required pattern" or allow developers to specify custom error messages alongside their regex patterns.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6f688 and 41c53bd.

📒 Files selected for processing (4)
  • Example/Kommunicate/Base.lproj/Localizable.strings (1 hunks)
  • Sources/Kommunicate/Classes/KMPreChatFormViewController.swift (4 hunks)
  • Sources/Resources/Assets/KMPreChatUserFormView.xib (1 hunks)
  • Sources/Resources/Assets/Localizable.strings (1 hunks)
🔇 Additional comments (5)
Sources/Resources/Assets/KMPreChatUserFormView.xib (1)

226-226: LGTM - UI improvements for better error message display.

The label modifications appropriately support the new regex validation feature:

  • Enabling user interaction allows for potential future enhancements (e.g., tappable error messages)
  • Word wrap and unlimited lines enable better display of longer validation error messages
  • Dynamic height adjustment ensures proper content display

These changes align well with the enhanced validation functionality.

Sources/Kommunicate/Classes/KMPreChatFormViewController.swift (4)

39-52: Well-documented regex pattern properties.

The new regex pattern properties are well-documented and appropriately optional. The documentation clearly explains the fallback behavior when patterns are nil.


79-81: Properly integrated new validation error cases.

The new error cases are well-integrated into the existing error handling system and follow the established pattern for localization.

Also applies to: 106-111


359-371: Phone number validation allows empty values - verify intended behavior.

The phone number validation now allows empty values to pass through (line 360: continue // optional empty allowed), but then validates against regex if the value is present. This differs from other mandatory fields that use guard statements to enforce non-empty values.

Verify this is the intended behavior - should phone numbers be allowed to be empty even when marked as mandatory?


363-365: ```shell
#!/bin/bash

Show implementation of isValidPhoneNumber in String+Extension.swift

rg -n "var isValidPhoneNumber" -A 20 Sources/Kommunicate/Classes/String+Extension.swift


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@kandpal025 kandpal025 merged commit 07b82c7 into dev Jul 2, 2025
2 of 3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2025
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.

3 participants