Skip to content

Conversation

@DhanashreePetare
Copy link

@DhanashreePetare DhanashreePetare commented Dec 24, 2025

Summary

Adds descending date sorting to the admin “View Conversation” list so recent interactions appear first.
Improves analysis workflow by presenting newest chats at the top while preserving pagination.

Changes

Admin backend: updates the chat-list query in AdminController.java.
No frontend changes required; existing pagination and rendering continue to work.

Implementation

In AdminController.actionChatList():
Uses descending(true) on the CouchDB/Cloudant view request.
Reverses the key range for the user’s chats: startKey([userId, \ufff0]) → endKey([userId]) so the view returns rows in reverse chronological order for that user.
Keeps limit and skip to support page-wise loading.
Assumes the underlying “chats/getChatList” view emits composite keys [userId, timestamp], where timestamp collates correctly for descending order (typically millisecond epoch as number/string of fixed length).

Summary by CodeRabbit

  • New Features

    • Smart reply suggestions now appear when the bot cannot understand a user's message.
  • Style

    • Updated smart reply button styling with improved spacing, shadows, and hover interactions.
  • Chores

    • Refined fallback messages for clarity.
    • Chat history now displays in reverse chronological order.

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 24, 2025

📝 Walkthrough

Walkthrough

This PR introduces fallback handling for text messages with guided DBpedia-focused suggestions, updates the admin chat list query to sort results by timestamp in descending order, refines smart-reply UI styling with flex layout and visual feedback, and revises fallback messaging content.

Changes

Cohort / File(s) Summary
Fallback Handling Logic
src/main/java/chatbot/lib/handlers/TextHandler.java
Added fallback scenario detection and response augmentation: new private field fallbackTriggered tracks fallback occurrences; new method appendFallbackSuggestions() constructs DBpedia-focused smart replies; new method extractKeyword() filters stop words to identify primary keywords; updated control flow in handleTextMessage() to trigger augmentation when appropriate. New imports for TemplateType, Constants, and ResponseType.
Admin Query Changes
src/main/java/chatbot/platforms/web/controllers/AdminController.java
Modified actionChatList() query: inverted startKey/endKey bounds (userId with "\ufff0" boundaries reversed) and added descending(true) to sort results by timestamp in descending order. All other pagination parameters retained.
Smart-Reply Styling
app/src/less/modules/smart-reply.less
Refactored container from fixed height with overflow to flex layout with gap and wrap; reduced padding and border-radius; applied text color and box-shadow; merged interaction pseudo-classes (:hover, :active, :focus) with enhanced shadow and removed text-decoration.
Fallback Messaging
src/main/resources/rivescript/scenario-text.rive
Updated fallbacktext from longer apology to directive "I couldn't understand that yet. Try one of these suggestions or rephrase with who/what/where." Updated noresultstext with normalized ASCII formatting and dash-prefixed line.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TextHandler
    participant RiveScript as RiveScript<br/>(scenario-text)
    participant ResponseGenerator
    participant DBpedia as Suggestions<br/>(DBpedia)

    User->>TextHandler: Send message
    TextHandler->>RiveScript: Process message
    RiveScript-->>TextHandler: No response / Fallback triggered
    alt Fallback Path
        TextHandler->>TextHandler: Mark fallbackTriggered
        TextHandler->>TextHandler: extractKeyword(message)
        TextHandler->>ResponseGenerator: appendFallbackSuggestions()
        ResponseGenerator->>DBpedia: Build suggestions
        DBpedia-->>ResponseGenerator: Suggestion set
        ResponseGenerator-->>TextHandler: Response with smart replies
    end
    TextHandler-->>User: Response + suggestions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Feature/admin date sorting(#10)' is partially related to the changeset. While date sorting for the admin chat list is the primary objective, the title is vague and uses a generic 'Feature/' prefix. Additionally, the changeset includes unrelated fallback mechanism changes, smart-reply styling updates, and scenario text revisions that are not captured in the title, indicating it covers only part of the main work.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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: 0

🧹 Nitpick comments (2)
src/main/java/chatbot/lib/handlers/TextHandler.java (2)

5-5: Note: ResponseType import appears unused.

The ResponseType import was added but doesn't appear to be used in the visible code. If it's not needed, consider removing it to keep imports clean.

Also applies to: 9-9, 12-12


129-148: Consider removing unused extractKeyword method.

The extractKeyword method is well-implemented with stop-word filtering and longest-token selection, but it's never called in the current code. This represents dead code that adds maintenance burden.

Options to consider

Option 1: Remove if not planned for near-term use

-    private String extractKeyword(String text) {
-        if(text == null || text.trim().length() == 0) {
-            return null;
-        }
-        String cleaned = text.replaceAll("[^A-Za-z0-9 ]", " ").toLowerCase();
-        String[] tokens = cleaned.split(" +");
-        String[] stop = new String[]{"what","who","where","why","how","is","are","the","a","an","of","in","on","for","with","to","tell","me","about","please"};
-        java.util.Set<String> stopSet = new java.util.HashSet<>();
-        for(String s : stop) stopSet.add(s);
-
-        String best = null;
-        for(String t : tokens) {
-            if(t.length() < 3) continue;
-            if(stopSet.contains(t)) continue;
-            if(best == null || t.length() > best.length()) {
-                best = t;
-            }
-        }
-        return best;
-    }

Option 2: Add a TODO comment if planned for future use

+    // TODO: Use this method to extract keywords for contextual fallback suggestions
     private String extractKeyword(String text) {
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4627979 and ea1ff12.

📒 Files selected for processing (4)
  • app/src/less/modules/smart-reply.less
  • src/main/java/chatbot/lib/handlers/TextHandler.java
  • src/main/java/chatbot/platforms/web/controllers/AdminController.java
  • src/main/resources/rivescript/scenario-text.rive
🧰 Additional context used
🧬 Code graph analysis (2)
src/main/java/chatbot/lib/handlers/TextHandler.java (4)
src/main/java/chatbot/lib/request/Request.java (1)
  • Request (12-75)
src/main/java/chatbot/lib/response/ResponseData.java (1)
  • ResponseData (13-276)
src/main/java/chatbot/lib/response/ResponseGenerator.java (1)
  • ResponseGenerator (17-116)
src/main/java/chatbot/lib/Utility.java (1)
  • Utility (15-107)
src/main/java/chatbot/platforms/web/controllers/AdminController.java (1)
src/main/java/codeanticode/eliza/Key.java (1)
  • Key (7-76)
🔇 Additional comments (7)
app/src/less/modules/smart-reply.less (1)

1-27: LGTM! Smart reply styling improvements enhance user interaction.

The CSS updates improve the smart reply component with better flex layout, visual hierarchy, and interaction feedback. The addition of transitions, box shadows, and merged interaction states (hover/active/focus) creates a more polished user experience.

src/main/resources/rivescript/scenario-text.rive (1)

43-48: LGTM! Fallback messaging is clearer and more actionable.

The updated fallback text is more concise and provides clearer guidance ("Try one of these suggestions or rephrase with who/what/where"), aligning well with the new fallback suggestion flow in TextHandler.java.

src/main/java/chatbot/lib/handlers/TextHandler.java (4)

31-31: LGTM! Fallback tracking flag is well-placed.

The fallbackTriggered flag correctly tracks when the FALLBACK_SCENARIO is reached, enabling the guided fallback suggestions flow.


80-90: LGTM! Fallback scenario handling is correct.

Setting fallbackTriggered = true when entering FALLBACK_SCENARIO appropriately marks when user input wasn't understood, triggering the guided suggestions later in the flow.


98-101: LGTM! Fallback suggestion trigger logic is appropriate.

The condition correctly adds fallback suggestions in two scenarios:

  1. When fallbackTriggered is true (understanding failed)
  2. When no responses were generated (empty response list)

This ensures users receive helpful guidance in both explicit fallback cases and when handlers return empty results.


110-127: LGTM! Fallback suggestions provide helpful guidance.

The method effectively enriches the response with:

  • A clear fallback prompt from RiveScript
  • Six fixed DBpedia-focused smart reply suggestions

The implementation correctly uses the ResponseGenerator API to add text and smart reply responses.

src/main/java/chatbot/platforms/web/controllers/AdminController.java (1)

65-74: Confirm the CouchDB "chats/getChatList" view emits composite keys in the expected order.

The timestamp collation concern in the original review is mitigated: the ChatModel class stores timestamp as a long (numeric epoch), which is correctly collatable in CouchDB. The descending sort logic appears sound for this format.

However, the CouchDB view definition is external to this repository (likely managed directly in Cloudant). Verify that the "getChatList" view emits composite keys as [userId, timestamp] in the correct order to match the query's key range expectations:

  • startKey(Key.complex(userId, "\ufff0"))
  • endKey(Key.complex(userId))
  • descending(true)

This pattern assumes the view emits timestamps where higher values sort later, which is correct for numeric epochs but should be confirmed in the actual design document.

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.

1 participant