-
Notifications
You must be signed in to change notification settings - Fork 53
Feature/admin date sorting(#10) #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feature/admin date sorting(#10) #62
Conversation
📝 WalkthroughWalkthroughThis 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
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
ResponseTypeimport 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
extractKeywordmethod 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
📒 Files selected for processing (4)
app/src/less/modules/smart-reply.lesssrc/main/java/chatbot/lib/handlers/TextHandler.javasrc/main/java/chatbot/platforms/web/controllers/AdminController.javasrc/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
fallbackTriggeredflag correctly tracks when the FALLBACK_SCENARIO is reached, enabling the guided fallback suggestions flow.
80-90: LGTM! Fallback scenario handling is correct.Setting
fallbackTriggered = truewhen 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:
- When
fallbackTriggeredis true (understanding failed)- 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
ResponseGeneratorAPI 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
ChatModelclass stores timestamp as along(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.
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
Style
Chores
✏️ Tip: You can customize this high-level summary in your review settings.